2021-06-22
Getting the first zigbee environment data into influxdb
I thought somebody must have been doing zigbee2mqtt measurements to influxdb before and I was somewhat right: it was mentioned in a bugreport! In issue Can't receive messages from mqtt #3 it shows that someone is already trying to do this but it's not completely there yet. So I cloned mhaas / mqtt-to-influxdb-forwarder : IoT MQTT to InfluxDB forwarder after a few updates it does what I want: correctly use the sensor id as tag and only parse messages that have live sensor data. Zigbee2mqtt likes to publish its internal housekeeping as mqtt messages and I don't need those. So now I get fromzigbee2mqtt/0x00158d0006fafb00 {"battery":100,"humidity":37.86,"linkquality":84,"pressure":1032,"temperature":28.67,"voltage":3045}ToDEBUG:forwarder.InfluxStore:Writing InfluxDB point: {'fields': {u'linkquality': 84.0, u'temperature': 28.67, u'battery': 100.0, u'humidity': 37.86, u'pressure': 1032.0, u'voltage': 3045.0}, 'tags': {'sensor_address': u'0x00158d0006fafb00'}, 'measurement': 'environment'}And available as:$ influx -database environment -precision rfc3339 Connected to http://localhost:8086 version 1.6.4 InfluxDB shell version: 1.6.4 > select * from environment; name: environment time battery humidity linkquality pressure sensor_address temperature voltage ---- ------- -------- ----------- -------- -------------- ----------- ------- [..] 2021-06-22T21:05:10.227577886Z 100 37.86 84 1032 0x00158d0006fafb00 28.67 3045I will need to add something with friendly names, but this is a nice start. Data flows! And regex101 regular expression tester and debugger saved the day in finding how to change the Python regular expression to only accept data from zigbee messages with a sensor address.