Practically I receive the MQTT topics from the MySensors Gateway.
Then in Node-Red I have make a function that translate the MySensors MQTT topics in a personalized MQTT topics,
in order to have clear names of the sensors value.
In Node-Red you make a flow like this:
[image: 1617521270781-d6af473c-7ae1-4977-834e-04fcf8f98b26-image.png]
Then in the function node you make something like this... but personalized:
// add timestamp to every sensor reads
var dt = new Date();
var hh = dt.getHours();
var mm = dt.getMinutes();
var ss = dt.getSeconds();
var yy = dt.getFullYear();
var mo = dt.getMonth() + 1; // want 1 more
var dd = dt.getDate();
//var daynum = date.getDay();
timeST = (dd < 10 ? "0" : "") + dd + "-" + (mo < 10 ? "0" : "") + mo + "-" + yy +
" " + (hh < 10 ? "0" : "") + hh + ":" + (mm < 10 ? "0" : "") + mm + ":" + (ss < 10 ? "0" : "") + ss;
/* sensors ID
id SensGaraj: 11
id SensCame1:
id SensCame2:
id SensCame3:
id SensCucin:
id SensSerra: 12
id SensFuori:
id SensSalon:
type Temp : 51
type Hum : 52
type Press : 53
type BatVol: 54
type BatLev: 255
*/
ret = 0; // send the return or not
// sensor id (topic:MySensors-out/xx/)
var parts = msg.topic.split("/");
id = parts[1];
type = parts[2];
val = msg.payload;
if (id == 11 ){sname = "SensGaraj";ret = 1;}
if (id == 12 ){sname = "SensSerra";ret = 1;}
// if etc...
if (ret == 1){
if (type == 51 ){stype = "Temp"; }
if (type == 52 ){stype = "Hum";}
if (type == 53 ){stype = "Press";}
if (type == 54 ){stype = "BattVol";}
if (type == 255){stype = "BattLev";}
msg = {}; //initialize msg object
msg.measurement = "sensors"; // tabella/file > influxdb
msg.topic = "MySensors/" + sname + "/" + stype;
msg.payload = {value: val, timeST: timeST}
node.status({fill:"green",shape:"ring",text:sname});
return msg;
}
//////////////////////////////////////////////////////////////
If you need more help just let me know :-)
Denis