forked from JsBergbau/MiTemperature2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node-RED flows MQTT mode.json
1 lines (1 loc) · 8.03 KB
/
Node-RED flows MQTT mode.json
1
[{"id":"351f900d.544e6","type":"mqtt in","z":"892ece47.eea0d","name":"","topic":"ATCThermometer","qos":"1","datatype":"json","broker":"8d18e86.ba01d18","x":140,"y":560,"wires":[["93969fbd.0f2a4"]]},{"id":"57b315eb.0da8cc","type":"debug","z":"892ece47.eea0d","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":890,"y":400,"wires":[]},{"id":"e45c522b.f8b92","type":"http response","z":"892ece47.eea0d","name":"","statusCode":"","headers":{},"x":370,"y":620,"wires":[]},{"id":"93969fbd.0f2a4","type":"change","z":"892ece47.eea0d","name":"sensorlist","rules":[{"t":"set","p":"sensors","pt":"msg","to":"{\"info\":{\"info1\":\"MAC Adresses must be in UPPERCASE otherwise sensor won't be found by the script\",\"info2\":\"now all available options are listet. If offset1, offset2, calpoint1 and calpoint2 are given 2Point calibration is used instead of humidityOffset.\",\"info3\":\"Note options are case sensitive\",\"sensorname\":\"Specify an easy readable name\",\"humidityoffset\":-5,\"offset1\":-10,\"offset2\":10,\"calpoint1\":33,\"calpoint2\":75},\"BD:AD:CA:1F:4D:12\":{\"sensorname\":\"Living Room\",\"offset1\":-2,\"offset2\":2,\"calpoint1\":33,\"calpoint2\":75}}","tot":"json"},{"t":"set","p":"processOnlyListedSensors","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":560,"wires":[["7787fd9b.8642f4"]]},{"id":"7787fd9b.8642f4","type":"function","z":"892ece47.eea0d","name":"Process and calibrate sensors","func":"processOnlyListedSensors = msg.processOnlyListedSensors || false;\n\nfunction calibrateHumidity2Points(humidity, offset1, offset2, calpoint1, calpoint2)\n{\n p1y=calpoint1\n\tp2y=calpoint2\n\tp1x=p1y - offset1\n\tp2x=p2y - offset2\n\tm = (p1y - p2y) * 1.0 / (p1x - p2x)\n\tb = p2y - m * p2x //would be more efficient to do this calculations only once\n\thumidityCalibrated=m*humidity + b\n\tif (humidityCalibrated > 100 ) //with correct calibration this should not happen\n\t{\n\t humidityCalibrated = 100\n\t}\n\telse if (humidityCalibrated < 0)\n\t{\n\t\thumidityCalibrated = 0\n\t}\n\thumidityCalibrated=Math.round(humidityCalibrated,0)\n\treturn humidityCalibrated\n}\n\n//\"A4:C1:38:69:E2:7C\"\nmsg.topic = msg.payload.sensor;\n\nif (msg.payload.sensor in msg.sensors )\n{\n sensor = msg.payload.sensor;\n sensordaten = msg.sensors[sensor];\n msg.payload.sensor = sensordaten.sensorname;\n msg.topic = msg.payload.sensor;\n if (\"offset1\" in sensordaten && \"offset2\" in sensordaten && \"calpoint1\" in sensordaten && \"calpoint2\" in sensordaten)\n {\n msg.payload.humidity = calibrateHumidity2Points(msg.payload.humidity, sensordaten.offset1, sensordaten.offset2, sensordaten.calpoint1,sensordaten.calpoint2);\n }\n else if (\"humidityOffset\" in sensordaten)\n {\n msg.payload.humidity = msg.payload.humidity + sensordaten.humidityOffset\n }\n \n return msg;\n}\nelse if (! processOnlyListedSensors)\n{\n return msg;\n}\n//drop message because only listed sensors should be processed here","outputs":1,"noerr":0,"initialize":"","finalize":"","x":650,"y":560,"wires":[["57b315eb.0da8cc","4678cbb.b4fefb4","69667736.cd7788","f1a92177.2fc7d8"]]},{"id":"4678cbb.b4fefb4","type":"change","z":"892ece47.eea0d","name":"Process for influxdb","rules":[{"t":"set","p":"measurement","pt":"msg","to":"tempMeasurement","tot":"str"},{"t":"set","p":"precision","pt":"msg","to":"s","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"[\t{\t \"Temperature\" : $.payload.temperature,\t \"humidity\" : $.payload.humidity,\t \"voltage\": $.payload.voltage,\t \"time\" : $floor($.payload.timestamp/25)*25\t},\t{\t \"Sensorname\": $.topic\t}\t]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":980,"y":560,"wires":[["59874483.4e6ca4"]]},{"id":"59874483.4e6ca4","type":"influxdb out","z":"892ece47.eea0d","influxdb":"f1b4eaef.a4fb88","name":"","measurement":"","precision":"","retentionPolicy":"","x":1310,"y":560,"wires":[]},{"id":"a8e49a31.bed248","type":"comment","z":"892ece47.eea0d","name":"Change here for your sensorlist","info":"If you want to output all your sensors, not only from your sensorlist, set \"processOnlyListedSensors\" to \"false\"","x":450,"y":520,"wires":[]},{"id":"8fa6b367.fe7938","type":"comment","z":"892ece47.eea0d","name":"Change here your measurement name","info":"The time for influx chunked into 25s segments, ideal for an advertisment intervall of 10s in ATC firmware. With storing the data every 25s, almost every timestamp is stored. This leads to RLE compression of the timestamp thus saving a lot of space in influxdb.\nWith an interval of 20 seconds in tests it occured quite often, that timestamp slots were not filled and thus no RLE compression can be used.","x":1030,"y":520,"wires":[]},{"id":"f1a92177.2fc7d8","type":"switch","z":"892ece47.eea0d","name":"Filter sensor","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"Living Room","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":950,"y":760,"wires":[["e6a18c8.296f6f"]]},{"id":"e6a18c8.296f6f","type":"debug","z":"892ece47.eea0d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1270,"y":760,"wires":[]},{"id":"69667736.cd7788","type":"switch","z":"892ece47.eea0d","name":"Filter receiver","property":"payload.receiver","propertyType":"msg","rules":[{"t":"eq","v":"raspberrypi","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":960,"y":700,"wires":[["371f249a.54c51c"]]},{"id":"371f249a.54c51c","type":"debug","z":"892ece47.eea0d","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1270,"y":700,"wires":[]},{"id":"643bae82.95a078","type":"comment","z":"892ece47.eea0d","name":"Debug / informational part","info":"You can filter here for output of the values of different sensors\n\nAnd you can filter which device sent the input in case you have multiple receivers.","x":990,"y":640,"wires":[]},{"id":"f722f286.c6a718","type":"exec","z":"892ece47.eea0d","command":"/home/pi/MiTemperature2/LYWSD03MMC.py","addpay":true,"append":"","useSpawn":"true","timer":"","oldrc":false,"name":"","x":910,"y":220,"wires":[["1ca2f79a.4a6238"],[],[]]},{"id":"a0392f91.c1e29","type":"inject","z":"892ece47.eea0d","name":"Start LYWSD03MMC.py in ATC Mode","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"--atc --watchdogtimer 5 --mqttconfigfile mqtt.conf","payloadType":"str","x":210,"y":160,"wires":[["1b65dbfa.15efb4"]]},{"id":"1ca2f79a.4a6238","type":"debug","z":"892ece47.eea0d","name":"Check if everything is correct running","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1310,"y":200,"wires":[]},{"id":"6d5ad8a3.f210c","type":"comment","z":"892ece47.eea0d","name":"Execute LYWSD03MMC.py directly in Node-RED with MQTT mode","info":"Of course you can still run it via normal commandline / cronjob / ...\n","x":270,"y":100,"wires":[]},{"id":"1f2785de.cd190a","type":"inject","z":"892ece47.eea0d","name":"Stop Process","props":[{"p":"kill","v":"","vt":"date"},{"p":"reset","v":"","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":130,"y":220,"wires":[["1b65dbfa.15efb4","f722f286.c6a718"]]},{"id":"1b65dbfa.15efb4","type":"trigger","z":"892ece47.eea0d","name":"Ensure only one instance","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"0","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":550,"y":160,"wires":[["f722f286.c6a718"]]},{"id":"8d18e86.ba01d18","type":"mqtt-broker","name":"","broker":"127.0.0.1","port":"1883","clientid":"SensorReader","usetls":false,"compatmode":false,"keepalive":"60","cleansession":false,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]