How to get sensor data into influxdb?
-
Hey guys,
I am running several sensors (mysensors) and would like to push them into an influxDB instance in order to visualize it with Grafana.
Influxdb and Grafana are already running on my Pi3 but I'm not sure what is the most elegant and easy way to push the data into the database.
Any hint is appreciated.
-
@MaKin I'm running an MQTT gateway and use Node-Red to glue things together:
Node-Red subscribes to some relevant MQTT topics. As data comes in it can be formatted or whatever is required; the RBE blocks make sure only changes in values are recorded.
Then a query is created and depending on the MQTT topic the measurement is set and stored in an InfluxDB database.
This is just one way to organize stuff, but I find it very flexible and powerful!If you like, I can post the 'code' behind the flow in the picture above, which can directly be imported in Node-Red.
-
Thanks a lot and yes please, that'd be very helpful!
-
@MaKin Here you go:
[{"id":"da963db0.0867b","type":"debug","z":"2f969f93.19b74","name":"","active":true,"console":"false","complete":"true","x":1329.2905349731445,"y":185.33306121826172,"wires":[]},{"id":"b83858ac.4ac2e8","type":"influxdb out","z":"2f969f93.19b74","influxdb":"3f3f1a0f.6ffe36","name":"","measurement":"","x":1367.6238708496094,"y":128.66622734069824,"wires":[]},{"id":"1ed7a7f.80dd758","type":"switch","z":"2f969f93.19b74","name":"","property":"topic","propertyType":"msg","rules":[{"t":"regex","v":"/0/1/0/0$","vt":"str","case":false},{"t":"regex","v":"0/1/0/1$","vt":"str","case":false},{"t":"regex","v":"6/1/0/4$","vt":"str","case":false},{"t":"regex","v":"/255/3/0/0$","vt":"str","case":false},{"t":"regex","v":"/7/1/0/24$","vt":"str","case":false},{"t":"regex","v":"/7/1/0/25$","vt":"str","case":false},{"t":"regex","v":"/7/1/0/26$","vt":"str","case":false}],"checkall":"true","outputs":7,"x":802.123908996582,"y":139.33292198181152,"wires":[["801cd988.7e82d8"],["c28e857e.6d6ed8"],["8354a90c.dcd808"],["60a92141.810fb"],["9b06911c.0fa8c"],["9dd58b0.4d51178"],["3c4b9e9c.e42232"]]},{"id":"801cd988.7e82d8","type":"change","z":"2f969f93.19b74","name":"temp","rules":[{"t":"set","p":"measurement","pt":"msg","to":"temp","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1000.7904052734375,"y":44.666215896606445,"wires":[["6c56a47c.b486ec"]]},{"id":"c28e857e.6d6ed8","type":"change","z":"2f969f93.19b74","name":"hum","rules":[{"t":"set","p":"measurement","pt":"msg","to":"hum","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":998.2904052734375,"y":86.66621589660645,"wires":[["6c56a47c.b486ec"]]},{"id":"60a92141.810fb","type":"change","z":"2f969f93.19b74","name":"batt","rules":[{"t":"set","p":"measurement","pt":"msg","to":"batt","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1001.29052734375,"y":179.33305549621582,"wires":[["6c56a47c.b486ec"]]},{"id":"ad56ce03.4ea93","type":"function","z":"2f969f93.19b74","name":"Format query","func":"msg.payload = [\n [{\n value: parseFloat(msg.payload),\n },\n {\n location:\"capacitive_rain_gauge\",\n }],\n];\nreturn msg;","outputs":1,"noerr":0,"x":634.9572448730469,"y":135.33306884765625,"wires":[["1ed7a7f.80dd758"]]},{"id":"62ada75b.f34ab8","type":"mqtt in","z":"2f969f93.19b74","name":"","topic":"mySensors/0/in/126/0/1/0/0","qos":"2","broker":"fb1ad45d.04e528","x":142.6240234375,"y":95.99990844726562,"wires":[["bdf94461.98ebc8"]]},{"id":"f3a6161b.ee8328","type":"mqtt in","z":"2f969f93.19b74","name":"","topic":"mySensors/0/in/126/0/1/0/1","qos":"2","broker":"fb1ad45d.04e528","x":138,"y":156.00001525878906,"wires":[["bf2405b6.04e9c8"]]},{"id":"23239f4b.0508f","type":"mqtt in","z":"2f969f93.19b74","name":"","topic":"mySensors/0/in/126/255/3/0/0","qos":"2","broker":"fb1ad45d.04e528","x":136.68701171875,"y":245.9999542236328,"wires":[["ee4b3125.b6179"]]},{"id":"bdf94461.98ebc8","type":"rbe","z":"2f969f93.19b74","name":"","func":"rbe","gap":"","x":452.6239929199219,"y":99.9998779296875,"wires":[["ad56ce03.4ea93"]]},{"id":"bf2405b6.04e9c8","type":"rbe","z":"2f969f93.19b74","name":"","func":"rbe","gap":"","x":448.2809753417969,"y":147.83416748046875,"wires":[["ad56ce03.4ea93"]]},{"id":"ee4b3125.b6179","type":"rbe","z":"2f969f93.19b74","name":"","func":"rbe","gap":"","x":453.6869812011719,"y":246.33282470703125,"wires":[["ad56ce03.4ea93"]]},{"id":"8354a90c.dcd808","type":"change","z":"2f969f93.19b74","name":"pres","rules":[{"t":"set","p":"measurement","pt":"msg","to":"pres","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":999.2905426025391,"y":129.33308601379395,"wires":[["6c56a47c.b486ec"]]},{"id":"d658a498.ae0158","type":"mqtt in","z":"2f969f93.19b74","name":"","topic":"mySensors/0/in/126/6/1/0/4","qos":"2","broker":"fb1ad45d.04e528","x":136.48825073242188,"y":197.4251708984375,"wires":[["8aebab69.e1b3f8"]]},{"id":"8aebab69.e1b3f8","type":"rbe","z":"2f969f93.19b74","name":"","func":"rbe","gap":"","x":461.5662536621094,"y":198.40170288085938,"wires":[["ad56ce03.4ea93"]]},{"id":"6b37c9c8.9da608","type":"mqtt in","z":"2f969f93.19b74","name":"","topic":"mySensors/0/in/126/7/1/0/+","qos":"2","broker":"fb1ad45d.04e528","x":426.3333282470703,"y":306.33333587646484,"wires":[["ad56ce03.4ea93"]]},{"id":"9b06911c.0fa8c","type":"change","z":"2f969f93.19b74","name":"cap0","rules":[{"t":"set","p":"measurement","pt":"msg","to":"cap0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":998.333366394043,"y":218.33333015441895,"wires":[["6c56a47c.b486ec"]]},{"id":"9dd58b0.4d51178","type":"change","z":"2f969f93.19b74","name":"cap1","rules":[{"t":"set","p":"measurement","pt":"msg","to":"cap1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":996.333366394043,"y":258.33335304260254,"wires":[["6c56a47c.b486ec"]]},{"id":"3c4b9e9c.e42232","type":"change","z":"2f969f93.19b74","name":"cap2","rules":[{"t":"set","p":"measurement","pt":"msg","to":"cap2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":992.333366394043,"y":302.3333549499512,"wires":[["6c56a47c.b486ec"]]},{"id":"6c56a47c.b486ec","type":"function","z":"2f969f93.19b74","name":"Show","func":"node.status({text:(msg.payload+'')});\nreturn msg;","outputs":1,"noerr":0,"x":1174.3332481384277,"y":152.3333339691162,"wires":[["da963db0.0867b","b83858ac.4ac2e8"]]},{"id":"3f3f1a0f.6ffe36","type":"influxdb","z":"","hostname":"localhost","port":"8086","protocol":"http","database":"test","name":""},{"id":"fb1ad45d.04e528","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":15,"cleansession":true,"willQos":"0","birthQos":"0"}]
-
I have just discovered that there is an option for external servers like influxdb in mycontrollers. Can you say something about it compared to red node?
And thanks for the code!
-
@MaKin no, sorry, I don't have experience with it.
-
@Yveaux do you also use Grafana in order to visualize the data? I am not sure what fields/attributes are necessary despite "time" and "value" for a binary sensor.
Suggested Topics
-
FHEM requesting time from controller
FHEM • 17 Feb 2015, 10:37 • l154 27 Aug 2015, 15:30 -
MyController 0.0.3.Alpha2 released!! :)
MyController.org • 29 Jul 2016, 19:53 • jkandasa 11 Oct 2016, 21:22 -
Update RF24 library to latest version
Bug Reports • 23 Mar 2014, 23:37 • andriej 24 Mar 2014, 22:52 -
Simple Temp/Light/Time setup with LCD 1.4 (no beta anymore)
My Project • 13 Aug 2014, 12:00 • John 31 Aug 2014, 21:47 -
MySensorsTracker - a simple logger for MySensors MQTT messages
My Project • 5 Aug 2021, 08:44 • canyouhearmenow 1 Nov 2021, 15:18 -
ESP32 with LoRa
General Discussion • 31 Jan 2023, 11:06 • dhanushmh 9 days ago