A very simple (and naive) Prometheus exporter for deCONZ Phoscon zigbee gateway. Exports prometheus metrics for sensors connected to Conbee II USB gateway.
# HELP deconz_gateway_info Gateway static info
# TYPE deconz_gateway_info gauge
deconz_gateway_info{apiversion, name}
# HELP deconz_battery Battery level of sensors
# TYPE deconz_battery gauge
deconz_battery{manufacturername, modelid, name, swversion}
# HELP deconz_humidity Relative humidity in percentage
# TYPE deconz_humidity gauge
deconz_humidity_ratio{manufacturername, modelid, name, swversion, type}
# HELP deconz_pressure Pressure in hPa
# TYPE deconz_pressure gauge
deconz_pressure_hpa{manufacturername,modelid, name, swversion, type}
# HELP deconz_temperature Temperature in degree Celsius
# TYPE deconz_temperature gauge
deconz_temperature_celsius{manufacturername, modelid, name, swversion, type}
-
Enable discovery in gateway settings
-
Generate a new username for the exporter
$ curl -X POST -s http://deconz:4501/api -d '{"devicetype": "deconz-exporter"}' | jq [{"success":{"username":"0E87CDA111"}}]
Save the returned username as
DECONZ_API_USERNAME. -
Start the exporter.
docker run -p 9199:9199 \ -e DECONZ_API_URL=http://deconz:4501 \ -e DECONZ_API_USERNAME=0E87CDA111 \ -e DECONZ_PORT=9199 \ ghcr.io/jaseemabid/deconz-exporter:latest # Optional: override websocket URL docker run -p 9199:9199 \ -e DECONZ_API_URL=http://deconz:4501 \ -e DECONZ_API_USERNAME=0E87CDA111 \ -e DECONZ_WS_URL=ws://deconz:4502 \ -e DECONZ_PORT=9199 \ ghcr.io/jaseemabid/deconz-exporter:latest# Using flags cargo run -- --api-url $DECONZ_API_URL --username $DECONZ_API_USERNAME --port 9199 # Optional: override websocket URL cargo run -- --api-url $DECONZ_API_URL --username $DECONZ_API_USERNAME --ws-url ws://deconz:4502 --port 9199 # Using env vars (supported by clap) DECONZ_API_URL=http://deconz:4501 \ DECONZ_API_USERNAME=0E87CDA111 \ DECONZ_WS_URL=ws://deconz:4502 \ DECONZ_PORT=9199 \ cargo run
-
Optionally override websocket url.
The exporter will try to discover the websocket url by default from the API url,
but use --ws-url ws://deconz:4502 or DECONZ_WS_URL=ws://deconz:4502 if you
need to explicitly use a different url.
- Profit! 🥇
- The exporter must be configured with a valid username and url to connect to deCONZ REST API.
- The websocket port is discovered though the REST API.
- The Websocket API provides streaming updates to the exporter, which gets converted to metrics.
-
websocat is a handy tool to see the raw websocket events emitted. Use it to debug issues, capture some sample events etc.
$ websocat ws://nyx.jabid.in:4502 {"attr":{"id":"1","lastannounced":null,"lastseen":"2022-03-04T22:42Z","manufacturername":"dresden elektronik","modelid":... -
Run
$ cargo testjust to be sure.
- This exporter is only tested with a few devices I own. There is no guarantee that it would work with anything else.
- Feel free to send me PRs for other devices supported by Conbee II
- The auth flow is cumbersome and manual, would be great to automate this.
- Reconnect cleanly on websocket errors, right now the exporter just dies and gets restarted
- Process metrics are missing, should bring them back.
- Auto discovery of gateways might be nice.
- Add metrics on the number of events handled

