Extract sensor values in Node-red
-
Hi All
I am having a go with Node-red. I have several temp sensors which I know are working as they are on home assistant. I know I am getting the values into Node-red using the debug.
This is an example of the info coming in.
msg.payload : string[15]
"2;0;1;0;0;19.1↵"
29/10/2017, 09:51:23node: 4764cb04.8ff4a4
msg.payload : string[15]
"2;1;1;0;0;16.9↵"
29/10/2017, 09:51:23node: 4764cb04.8ff4a4
msg.payload : string[16]
"67;0;1;0;0;63.0↵"
29/10/2017, 09:51:23node: 4764cb04.8ff4a4
msg.payload : string[18]
"0;255;3;0;2;2.1.1↵"
29/10/2017, 09:51:26node: 4764cb04.8ff4a4
msg.payload : string[16]
"67;0;1;0;0;62.5↵"
29/10/2017, 09:51:33node: 4764cb04.8ff4a4
msg.payload : string[18]
"0;255;3;0;2;2.1.1↵"
29/10/2017, 09:51:41node: 4764cb04.8ff4a4
msg.payload : string[15]
"2;0;1;0;0;19.0↵"
29/10/2017, 09:51:43node: 4764cb04.8ff4a4
msg.payload : string[18]
"0;255;3;0;2;2.1.1↵"
29/10/2017, 09:51:53node: 4764cb04.8ff4a4
msg.payload : string[18]
"0;255;3;0;2;2.1.1↵"
29/10/2017, 09:51:54node: 4764cb04.8ff4a4
msg.payload : string[15]
"2;1;1;0;0;16.8↵"
29/10/2017, 09:52:03node: 4764cb04.8ff4a4
msg.payload : string[18]
"0;255;3;0;2;2.1.1↵"
29/10/2017, 09:52:13node: 4764cb04.8ff4a4
msg.payload : string[18]
"0;255;3;0;2;2.1.1↵"
29/10/2017, 09:52:23node: 4764cb04.8ff4a4
msg.payload : string[18]
"0;255;3;0;2;2.1.1↵"
29/10/2017, 09:52:31node: 4764cb04.8ff4a4
msg.payload : string[15]
"2;0;1;0;0;19.1↵"
29/10/2017, 09:52:34node: 4764cb04.8ff4a4
msg.payload : string[18]
"0;255;3;0;2;2.1.1↵"
29/10/2017, 09:52:39node: 4764cb04.8ff4a4
msg.payload : string[16]
"67;5;1;0;0;27.0↵"
29/10/2017, 09:52:41node: 4764cb04.8ff4a4
msg.payload : string[16]
"67;5;1;0;0;27.5↵"So I want to separate the information so that I can show a gauge and graph and use in a thermostat. so nodeId 67 childSensorId 0 is a sensor I want the value for, and also nodeId 67 childSensorId 5. I have tried with this script in a function, but it does not output anything.
if (msg.payload.nodeId == 67 && msg.payload.childSensorId === 0) {
var msg;
msg.payload = msg.payload.value;
msg.topic = "Temperature";
return msg;
}Could someone point me in the right direction to what i am doing wrong.
-
Hi All
I am having a go with Node-red. I have several temp sensors which I know are working as they are on home assistant. I know I am getting the values into Node-red using the debug.
This is an example of the info coming in.
msg.payload : string[15]
"2;0;1;0;0;19.1↵"
29/10/2017, 09:51:23node: 4764cb04.8ff4a4
msg.payload : string[15]
"2;1;1;0;0;16.9↵"
29/10/2017, 09:51:23node: 4764cb04.8ff4a4
msg.payload : string[16]
"67;0;1;0;0;63.0↵"
29/10/2017, 09:51:23node: 4764cb04.8ff4a4
msg.payload : string[18]
"0;255;3;0;2;2.1.1↵"
29/10/2017, 09:51:26node: 4764cb04.8ff4a4
msg.payload : string[16]
"67;0;1;0;0;62.5↵"
29/10/2017, 09:51:33node: 4764cb04.8ff4a4
msg.payload : string[18]
"0;255;3;0;2;2.1.1↵"
29/10/2017, 09:51:41node: 4764cb04.8ff4a4
msg.payload : string[15]
"2;0;1;0;0;19.0↵"
29/10/2017, 09:51:43node: 4764cb04.8ff4a4
msg.payload : string[18]
"0;255;3;0;2;2.1.1↵"
29/10/2017, 09:51:53node: 4764cb04.8ff4a4
msg.payload : string[18]
"0;255;3;0;2;2.1.1↵"
29/10/2017, 09:51:54node: 4764cb04.8ff4a4
msg.payload : string[15]
"2;1;1;0;0;16.8↵"
29/10/2017, 09:52:03node: 4764cb04.8ff4a4
msg.payload : string[18]
"0;255;3;0;2;2.1.1↵"
29/10/2017, 09:52:13node: 4764cb04.8ff4a4
msg.payload : string[18]
"0;255;3;0;2;2.1.1↵"
29/10/2017, 09:52:23node: 4764cb04.8ff4a4
msg.payload : string[18]
"0;255;3;0;2;2.1.1↵"
29/10/2017, 09:52:31node: 4764cb04.8ff4a4
msg.payload : string[15]
"2;0;1;0;0;19.1↵"
29/10/2017, 09:52:34node: 4764cb04.8ff4a4
msg.payload : string[18]
"0;255;3;0;2;2.1.1↵"
29/10/2017, 09:52:39node: 4764cb04.8ff4a4
msg.payload : string[16]
"67;5;1;0;0;27.0↵"
29/10/2017, 09:52:41node: 4764cb04.8ff4a4
msg.payload : string[16]
"67;5;1;0;0;27.5↵"So I want to separate the information so that I can show a gauge and graph and use in a thermostat. so nodeId 67 childSensorId 0 is a sensor I want the value for, and also nodeId 67 childSensorId 5. I have tried with this script in a function, but it does not output anything.
if (msg.payload.nodeId == 67 && msg.payload.childSensorId === 0) {
var msg;
msg.payload = msg.payload.value;
msg.topic = "Temperature";
return msg;
}Could someone point me in the right direction to what i am doing wrong.
-
If you switch to mqtt gateway, you could just link the gauge to the topic of the sensor and you are done
-
https://www.mysensors.org/build/mqtt_gateway
it is pretty much the same as the ethernet, it just needs a few extra parameters and an mqtt broker running somewhere (if you already have a RPI, just install mosquitto)
-
I don't remember how to use the mysensors nodes, but knowing how mqtt works, just take advantage of it: the sensor is publishing a value to a topic, so just read that.
@gohan I am just thinking about the implications of moving to mqqt. This will break my home assistant setup. I also have over 30 sensors I would have to change the setup of.
If you see this as an example, "67;0;1;0;0;62.5↵" which is my data from a sensor showing in node-red debug. The 67 is the nodeId, the next 0 is the childSensor Id and the 62.5 is the temperature.
This the code I am using in a function of node-red to try and extract the temp value.
if (msg.payload.nodeId == 67 && msg.payload.childSensorId === 0) {
var msg;
msg.payload = msg.payload.value;
msg.topic = "Temperature";
return msg;
}Can anyone spot any reason why this may not work ?
-
I have built an Mqtt gateway as you suggested. from the arduino serial monitor I can see it working, as below.
0;255;3;0;9;Sending message on topic: mygateway1-out/67/3/1/0/0
0;255;3;0;9;TSF:MSG:READ,67-67-0,s=3,c=1,t=0,pt=7,l=5,sg=0:11.5
0;255;3;0;9;Sending message on topic: mygateway1-out/67/3/1/0/0
0;255;3;0;9;TSF:MSG:READ,67-67-0,s=3,c=1,t=0,pt=7,l=5,sg=0:11.0
0;255;3;0;9;Sending message on topic: mygateway1-out/67/3/1/0/0
0;255;3;0;9;TSF:MSG:READ,67-67-0,s=3,c=1,t=0,pt=7,l=5,sg=0:11.5
0;255;3;0;9;Sending message on topic: mygateway1-out/67/3/1/0/0
0;255;3;0;9;TSF:MSG:READ,67-67-0,s=3,c=1,t=0,pt=7,l=5,sg=0:11.0
0;255;3;0;9;Sending message on topic: mygateway1-out/67/3/1/0/0
0;255;3;0;9;TSF:MSG:READ,67-67-0,s=5,c=1,t=0,ptto=7,l=5,sg=0:16.5
0;255;3;0;9;Sending message on topic: mygateway1-out/67/5/1/0/0I have mosquitto broker running on my pi 3. Node-red shows connected to the mqqt broker, yet no data is shown passing.
any ideas how best to fault find this issue
-
@gohan I am just thinking about the implications of moving to mqqt. This will break my home assistant setup. I also have over 30 sensors I would have to change the setup of.
If you see this as an example, "67;0;1;0;0;62.5↵" which is my data from a sensor showing in node-red debug. The 67 is the nodeId, the next 0 is the childSensor Id and the 62.5 is the temperature.
This the code I am using in a function of node-red to try and extract the temp value.
if (msg.payload.nodeId == 67 && msg.payload.childSensorId === 0) {
var msg;
msg.payload = msg.payload.value;
msg.topic = "Temperature";
return msg;
}Can anyone spot any reason why this may not work ?
@lozzer65 I'm playing with node red and a mock TCP gateway at the moment and looking at your code I think the problem is that rather than msg.payload.nodeId it should be msg.nodeId and msg.payload.childSensorId should be msg.childSensorId. I realise you've moved on to MQTT but thought I'd mention it in case others come looking.
-
If you use the node-red-contrib-mysensors nodes, then you can split the sensor string into the different parts.
Then you are able to use for example the switch node, to filter the data..

-
Sorry I don't have more documentation at hand, than what is in the mysensors npm module already. But basically I use the switch node to route messages, on subtype, then on nodeId, and last on childId.
I'm currently remodeling my node-red setup.. Moving everything to MQTT for internal message distribution between all parts (both within node-red and to external systems).