For those who don't remember the TEMP05 it is a 1-wire interface that sends device readings to HS via serial port. I have 5x temperature sensors around the house that report in every 5 minutes. Up until now I've been using a VB serial script but decided to re-implement this in Node-Red. The TEMP05 transmits ASCII messages terminated with a <CR><LF>. I'm only interested in the messages that start with "Sensor".
Here is a sample of the messages:
Here is the overall flow:

The "Get Sensor ID" and "Get Sensor Value" nodes are node-red-contrib-string nodes used to parse the ASCII message.
"Get Sensor ID" checks to see if msg.payload startsWith "Sensor", parses the ID in the message. and stores it in msg.sensor_id. otherwise sets msg.sensor_id to '99'.


Similar for "Get Sensor Value" except it stores into msg.sensor_value.


"Prep HS Msg" is a change node that deletes msg.payload since it's no longer needed, sets msg.topic to "update", msg.payload.value to msg.sensor_value, and msg.payload.status to msg.sensor_value:

Finally, a switch node "Select HS Device" routes the msg to the HS Device node based on msg.sensor_id. msg.sensor_id = '99' gets routed to a null output.

Here's the exported code:
Here is a sample of the messages:
Code:
Sensor #01[E40008001E1A0710]=72.15F Sensor #02[760008001E1A2810]=86.66F Sensor #03[FD0008002DDCCC10]=83.96F Sensor #04[3101186E1A7EFF28]=86.28F Sensor #05[EB0008002DF69010]=83.85F
The "Get Sensor ID" and "Get Sensor Value" nodes are node-red-contrib-string nodes used to parse the ASCII message.
"Get Sensor ID" checks to see if msg.payload startsWith "Sensor", parses the ID in the message. and stores it in msg.sensor_id. otherwise sets msg.sensor_id to '99'.
Similar for "Get Sensor Value" except it stores into msg.sensor_value.
"Prep HS Msg" is a change node that deletes msg.payload since it's no longer needed, sets msg.topic to "update", msg.payload.value to msg.sensor_value, and msg.payload.status to msg.sensor_value:
Finally, a switch node "Select HS Device" routes the msg to the HS Device node based on msg.sensor_id. msg.sensor_id = '99' gets routed to a null output.
Here's the exported code:
Code:
[ { "id": "a479ee8e8edc540e", "type": "tab", "label": "Temp05", "disabled": false, "info": "", "env": [] }, { "id": "20352579271c9d55", "type": "serial in", "z": "a479ee8e8edc540e", "name": "USB0", "serial": "ab715bde7f817d82", "x": 90, "y": 480, "wires": [ [ "cf7967b86ac55e05" ] ] }, { "id": "cf7967b86ac55e05", "type": "string", "z": "a479ee8e8edc540e", "name": "Get Sensor ID", "methods": [ { "name": "startsWith", "params": [ { "type": "str", "value": "Sensor" } ] }, { "name": "toString", "params": [] }, { "name": "replaceAll", "params": [ { "type": "str", "value": "true" }, { "type": "msg", "value": "payload" } ] }, { "name": "getRightMost", "params": [ { "type": "str", "value": "#" } ] }, { "name": "getLeftMost", "params": [ { "type": "str", "value": "[" } ] }, { "name": "replaceAll", "params": [ { "type": "str", "value": "false" }, { "type": "str", "value": "99" } ] } ], "prop": "payload", "propout": "sensor_id", "object": "msg", "objectout": "msg", "x": 240, "y": 480, "wires": [ [ "0c57b8750c8df218" ] ] }, { "id": "6a680e1c982d937a", "type": "debug", "z": "a479ee8e8edc540e", "name": "", "active": false, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "targetType": "full", "statusVal": "", "statusType": "auto", "x": 810, "y": 400, "wires": [] }, { "id": "0c57b8750c8df218", "type": "string", "z": "a479ee8e8edc540e", "name": "Get Sensor Value", "methods": [ { "name": "startsWith", "params": [ { "type": "str", "value": "Sensor" } ] }, { "name": "toString", "params": [] }, { "name": "replaceAll", "params": [ { "type": "str", "value": "true" }, { "type": "msg", "value": "payload" } ] }, { "name": "getRightMost", "params": [ { "type": "str", "value": "=" } ] }, { "name": "delRightMost", "params": [ { "type": "str", "value": "F" } ] }, { "name": "replaceAll", "params": [ { "type": "str", "value": "false" }, { "type": "str", "value": "99" } ] } ], "prop": "payload", "propout": "sensor_value", "object": "msg", "objectout": "msg", "x": 450, "y": 480, "wires": [ [ "8a8fe621c6b43892" ] ] }, { "id": "95b79aa0bb97ef1d", "type": "switch", "z": "a479ee8e8edc540e", "name": "Select HS Device", "property": "sensor_id", "propertyType": "msg", "rules": [ { "t": "eq", "v": "01", "vt": "str" }, { "t": "eq", "v": "02", "vt": "str" }, { "t": "eq", "v": "03", "vt": "str" }, { "t": "eq", "v": "04", "vt": "str" }, { "t": "eq", "v": "05", "vt": "str" }, { "t": "eq", "v": "99", "vt": "str" } ], "checkall": "true", "repair": false, "outputs": 6, "x": 870, "y": 480, "wires": [ [ "c9226998c25bf48c" ], [ "60742eb1d40cda7c" ], [ "289c816e9ef4e9c5" ], [ "b54553e73fd54b2a" ], [ "15adf992e3013805" ], [] ] }, { "id": "8a8fe621c6b43892", "type": "change", "z": "a479ee8e8edc540e", "name": "Prep HS Msg", "rules": [ { "t": "delete", "p": "payload", "pt": "msg" }, { "t": "set", "p": "topic", "pt": "msg", "to": "update", "tot": "str" }, { "t": "set", "p": "payload.value", "pt": "msg", "to": "sensor_value", "tot": "msg" }, { "t": "set", "p": "payload.status", "pt": "msg", "to": "sensor_value", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 660, "y": 480, "wires": [ [ "95b79aa0bb97ef1d", "6a680e1c982d937a" ] ] }, { "id": "c9226998c25bf48c", "type": "hs-device", "z": "a479ee8e8edc540e", "name": "Server Rack", "device": "59", "server": "cca8073e1d5285f1", "feature": "60", "reportonstartup": false, "x": 1130, "y": 360, "wires": [ [] ] }, { "id": "60742eb1d40cda7c", "type": "hs-device", "z": "a479ee8e8edc540e", "name": "Front Porch", "device": "59", "server": "cca8073e1d5285f1", "feature": "61", "reportonstartup": false, "x": 1130, "y": 420, "wires": [ [] ] }, { "id": "289c816e9ef4e9c5", "type": "hs-device", "z": "a479ee8e8edc540e", "name": "Attic", "device": "59", "server": "cca8073e1d5285f1", "feature": "62", "reportonstartup": false, "x": 1110, "y": 480, "wires": [ [] ] }, { "id": "b54553e73fd54b2a", "type": "hs-device", "z": "a479ee8e8edc540e", "name": "Backyard", "device": "59", "server": "cca8073e1d5285f1", "feature": "63", "reportonstartup": false, "x": 1120, "y": 540, "wires": [ [] ] }, { "id": "15adf992e3013805", "type": "hs-device", "z": "a479ee8e8edc540e", "name": "Northside", "device": "59", "server": "cca8073e1d5285f1", "feature": "64", "reportonstartup": false, "x": 1120, "y": 600, "wires": [ [] ] }, { "id": "ab715bde7f817d82", "type": "serial-port", "serialport": "/dev/ttyUSB0", "serialbaud": "9600", "databits": "8", "parity": "none", "stopbits": "1", "waitfor": "", "dtr": "none", "rts": "none", "cts": "none", "dsr": "none", "newline": "\\n", "bin": "false", "out": "char", "addchar": "", "responsetimeout": "10000" }, { "id": "cca8073e1d5285f1", "type": "hs-server", "name": "HS4Pi", "host": "172.29.1.17", "port": "80" } ]
Comment