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.


  • Mod

    @lozzer65 have you tried the mysensors nodes?



  • Hi
    Yes I have. They just seem to to reformat the whole data. I just want to extract the temp value from each sensor to display in a gauge and a graph.


  • Mod

    Are you using mqtt gateway or ethernet?



  • @gohan Ethernet gateway. As you can see above I have data. Just can't seem to extract the temp value for each sensor to make it usable for a gauge and graph


  • Mod

    If you switch to mqtt gateway, you could just link the gauge to the topic of the sensor and you are done



  • @gohan Hi, Can you give me some pointers on what I need to do to change to MQQT Gateway. I am not overly sure on the difference.


  • Mod

    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)



  • @gohan Ok, thanks for the advise. Strange that I can't use what I have, especially seeing as I can see the data coming from the sensors in node-red.


  • Mod

    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 ?


  • Mod

    You don't need to change the sensors. Did you check if HA doesn't support mqtt gateway?



  • 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/0

    I 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


  • Mod

    If you use a mqtt client and subscribe to the topic mygateway1-out/67/5/1/0/0 do you actually see messages? Or subscribe to mygateway1-out/# and see all mqtt messages. If you see correct messages your setup is correct



  • Gohan

    Thanks very much for that pointer. You have been very helpful. All working now.


  • Mod

    Do you think it is easier with mqtt or with serial?


  • Admin

    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..

    0_1509910711235_flow-mysensors.png


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.