mjmccans / airthings-mqtt-ha Goto Github PK
View Code? Open in Web Editor NEWPython script for Airthings devices that uses mqtt to integrate with Home Assistant via mqtt discovery.
License: MIT License
Python script for Airthings devices that uses mqtt to integrate with Home Assistant via mqtt discovery.
License: MIT License
I really appreciate your script here and trying to use it to its fullest ability. So thank you 1st and foremost.
Currently able to send 4/5 devices to HA Broker.
airthings-mqtt-ha.py seem to see and pulls data for all 4 devices.
[2022-06-07 15:03:35] INFO: Setting up Airthings sensors...
[2022-06-07 15:04:05] INFO: d8:71:4d:aa:0a:f0: Manufacturer: Airthings AS Model: 2920 Serial: 045589 Device:Airthings Wave Mini
[2022-06-07 15:04:05] INFO: d8:71:4d:a9:a3:e1: Manufacturer: Airthings AS Model: 2920 Serial: 047816 Device:Airthings Wave Mini
[2022-06-07 15:04:05] INFO: d8:71:4d:a9:ac:5b: Manufacturer: Airthings AS Model: 2920 Serial: 047318 Device:Airthings Wave Mini
[2022-06-07 15:04:05] INFO: d8:71:4d:af:a7:4d: Manufacturer: Airthings AS Model: 2920 Serial: 046544 Device:Airthings Wave Mini
[2022-06-07 15:04:15] INFO: Done Airthings setup.
[2022-06-07 15:04:33] INFO: Sending HA mqtt discovery configuration messages...
[2022-06-07 15:04:33] ERROR: Failed while creating HA mqtt discovery messages.
Traceback (most recent call last):
File "/home/pi/airthings-mqtt-ha/src/./airthings-mqtt-ha.py", line 341, in <module>
config["name"] = s["name"]+" "+SENSORS[name]["name"]
KeyError: 'name'
[2022-06-07 15:04:33] ERROR: Failed while creating HA mqtt discovery messages.
Traceback (most recent call last):
File "/home/pi/airthings-mqtt-ha/src/./airthings-mqtt-ha.py", line 341, in <module>
config["name"] = s["name"]+" "+SENSORS[name]["name"]
KeyError: 'name'
[2022-06-07 15:04:33] ERROR: Failed while creating HA mqtt discovery messages.
Traceback (most recent call last):
File "/home/pi/airthings-mqtt-ha/src/./airthings-mqtt-ha.py", line 341, in <module>
config["name"] = s["name"]+" "+SENSORS[name]["name"]
KeyError: 'name'
[2022-06-07 15:04:33] INFO: Sending messages to mqtt broker...
[2022-06-07 15:04:33] INFO: Done sending messages to mqtt broker.
[2022-06-07 15:04:33] INFO: Done sending HA mqtt discovery configuration messages.
After this error,
The scripts reports all the values for the temp, hum, and voc.
but it just stops there, the last device in my config will not show up in HA.
If this an HA issue or can i tweak the script?
I have very little python experience, but i tend to have good success though google resarch. Although, im stuck here lol
[2022-06-07 15:18:46] INFO: Waiting 150 seconds.
[2022-06-07 15:21:16] INFO: Collecting sensor value messages...
[2022-06-07 15:21:16] INFO: airthings/d8:71:4d:aa:0a:f0/temperature = 27.1
[2022-06-07 15:21:16] INFO: airthings/d8:71:4d:aa:0a:f0/humidity = 38
[2022-06-07 15:21:16] INFO: airthings/d8:71:4d:aa:0a:f0/voc = 88
[2022-06-07 15:21:16] INFO: airthings/d8:71:4d:a9:a3:e1/temperature = 29.1
[2022-06-07 15:21:16] INFO: airthings/d8:71:4d:a9:a3:e1/humidity = 37
[2022-06-07 15:21:16] INFO: airthings/dd8:71:4d:a9:a3:e1/voc = 157
[2022-06-07 15:21:16] INFO: airthings/d8:71:4d:a9:ac:5b/temperature = 38.7
[2022-06-07 15:21:16] INFO: airthings/d8:71:4d:a9:ac:5b/humidity = 19
[2022-06-07 15:21:16] INFO: airthings/d8:71:4d:a9:ac:5b/voc = 339
[2022-06-07 15:21:16] INFO: airthings/d8:71:4d:af:a7:4d/temperature = 27.6
[2022-06-07 15:21:16] INFO: airthings/d8:71:4d:af:a7:4d/humidity = 39
[2022-06-07 15:21:16] INFO: airthings/d8:71:4d:af:a7:4d/voc = 957
[2022-06-07 15:21:16] INFO: Sending messages to mqtt broker...
[2022-06-07 15:21:16] INFO: Done sending messages to mqtt broker.
I'm getting the following error even though i have paho-mqtt installed via pip3
Requirement already satisfied: paho-mqtt in /home/pi/.local/lib/python3.10/site-packages (1.6.1)
Traceback (most recent call last): File "/home/pi/airthings-mqtt-ha/src/./airthings-mqtt-ha.py", line 24, in <module> import paho.mqtt.publish as publish ModuleNotFoundError: No module named 'paho'
I am running Ubunut 22.04 (jammy) on rpi3.
Would it be possible to read battery levels?
Hi !
Thanks for the great work ! Would it be possible create a docker image with your script ?
Regards,
WM
IT would be great if this was available as a system add-on or as a HAC's plugin. Just a thought especially for folks running on HASSOS
I am unable to use the options file when running as a service, using a rpi3 on raspbian, it works fine running it from the prompt.
Sep 30 00:41:57 piTre systemd[1]: Started airthings-mqtt-ha control script.
Sep 30 00:41:57 piTre python3[19593]: [2022-09-30 00:41:57] WARNING: Error reading ./options.json file. This script will search for devices and output a suggested configuration file.
Sep 30 00:41:57 piTre python3[19593]: [2022-09-30 00:41:57] INFO: Setting up Airthings sensors...
Sep 30 00:41:57 piTre python3[19593]: [2022-09-30 00:41:57] INFO: No devices provided, so searching for Airthings sensors...
Sep 30 00:41:57 piTre python3[19593]: [2022-09-30 00:41:57] INFO: Starting search for Airthings sensors...
I tried adding options.json to Environment="PATH=/usr/local/bin but it does not seem to help. Changing PATH to the directory where I run the python script from using prompt does not hjelp either.
Hello, I have 2 airthings wave plus devices, and found them both. But I cannot get the script to pull status from both devices.
My config looks like:
[[devices]]
mac = "XX:XX:XX:XX:XX:X1"
[devices.radon_1day_avg]
name = "Radon (1 day avg.)"
unit_of_measurement = "Bq/m3"
icon = "mdi:radioactive"
[devices.radon_longterm_avg]
name = "Radon (longterm avg.)"
unit_of_measurement = "Bq/m3"
icon = "mdi:radioactive"
[devices.co2]
name = "CO2"
unit_of_measurement = "ppm"
icon = "mdi:molecule-co2"
[devices.voc]
name = "VOC"
unit_of_measurement = "ppb"
icon = "mdi:cloud"
[devices.temperature]
name = "Temperature"
device_class = "temperature"
unit_of_measurement = "°C"
[devices.humidity]
name = "Humidity"
device_class = "humidity"
unit_of_measurement = "%"
[devices.rel_atm_pressure]
name = "Pressure"
device_class = "pressure"
unit_of_measurement = "mbar"
mac = "XX:XX:XX:XX:XX:X2"
[devices.radon_1day_avg]
name = "Radon (1 day avg.)"
unit_of_measurement = "Bq/m3"
icon = "mdi:radioactive"
[devices.radon_longterm_avg]
name = "Radon (longterm avg.)"
unit_of_measurement = "Bq/m3"
icon = "mdi:radioactive"
[devices.co2]
name = "CO2"
unit_of_measurement = "ppm"
icon = "mdi:molecule-co2"
[devices.voc]
name = "VOC"
unit_of_measurement = "ppb"
icon = "mdi:cloud"
[devices.temperature]
name = "Temperature"
device_class = "temperature"
unit_of_measurement = "°C"
[devices.humidity]
name = "Humidity"
device_class = "humidity"
unit_of_measurement = "%"
[devices.rel_atm_pressure]
name = "Pressure"
device_class = "pressure"
unit_of_measurement = "mbar"
Any tips? I am wondering if I should make a separate service for each device perhaps.
These are my logs:
juli 05 08:30:19 thinkserver python3[16861]: INFO:airthings-mqtt-ha:Setting up Airthings sensors...
juli 05 08:30:22 thinkserver python3[16861]: ERROR:pygatt.backends.gatttool.gatttool:Timed out connecting to XX:XX:XX:XX:XX:X1 after 3 seconds.
juli 05 08:30:22 thinkserver python3[16861]: WARNING:airthings-mqtt-ha:Bluetooth error on attempt 1. Retrying in 3 seconds.
juli 05 08:30:29 thinkserver python3[16861]: ERROR:pygatt.backends.gatttool.gatttool:Timed out connecting to XX:XX:XX:XX:XX:X1 after 3 seconds.
juli 05 08:30:29 thinkserver python3[16861]: WARNING:airthings-mqtt-ha:Bluetooth error on attempt 2. Retrying in 3 seconds.
juli 05 08:30:35 thinkserver python3[16861]: ERROR:pygatt.backends.gatttool.gatttool:Timed out connecting to XX:XX:XX:XX:XX:X1 after 3 seconds.
juli 05 08:30:35 thinkserver python3[16861]: WARNING:airthings-mqtt-ha:Bluetooth error on attempt 3. Retrying in 3 seconds.
juli 05 08:30:42 thinkserver python3[16861]: ERROR:pygatt.backends.gatttool.gatttool:Timed out connecting to XX:XX:XX:XX:XX:X1 after 3 seconds.
juli 05 08:30:42 thinkserver python3[16861]: WARNING:airthings-mqtt-ha:Bluetooth error on attempt 4. Retrying in 3 seconds.
juli 05 08:30:47 thinkserver python3[16861]: INFO:airthings-mqtt-ha:XX:XX:XX:XX:XX:X1: Manufacturer: Airthings AS Model: 2930 Serial: 002507 Device:Airthings Wave+
juli 05 08:30:50 thinkserver python3[16861]: INFO:airthings-mqtt-ha:Done Airthings setup.
juli 05 08:30:51 thinkserver python3[16861]: INFO:airthings-mqtt-ha:Sending HA mqtt discovery configuration messages...
juli 05 08:30:51 thinkserver python3[16861]: INFO:airthings-mqtt-ha:Sending messages to mqtt broker...
juli 05 08:30:51 thinkserver python3[16861]: INFO:airthings-mqtt-ha:Done sending messages to mqtt broker.
juli 05 08:30:51 thinkserver python3[16861]: INFO:airthings-mqtt-ha:Done sending HA mqtt discovery configuration messages.
juli 05 08:30:56 thinkserver python3[16861]: INFO:airthings-mqtt-ha:Collecting sensor value messages...
juli 05 08:30:56 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/humidity = 64
juli 05 08:30:56 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/radon_1day_avg = 20
juli 05 08:30:56 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/radon_longterm_avg = 167
juli 05 08:30:56 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/temperature = 21.6
juli 05 08:30:56 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/rel_atm_pressure = 998
juli 05 08:30:56 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/co2 = 518
juli 05 08:30:56 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/voc = 61
juli 05 08:30:56 thinkserver python3[16861]: INFO:airthings-mqtt-ha:Sending messages to mqtt broker...
juli 05 08:30:56 thinkserver python3[16861]: INFO:airthings-mqtt-ha:Done sending messages to mqtt broker.
juli 05 08:30:56 thinkserver python3[16861]: INFO:airthings-mqtt-ha:Waiting 150 seconds.
juli 05 08:33:26 thinkserver python3[16861]: INFO:airthings-mqtt-ha:Collecting sensor value messages...
juli 05 08:33:26 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/humidity = 64
juli 05 08:33:26 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/radon_1day_avg = 20
juli 05 08:33:26 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/radon_longterm_avg = 167
juli 05 08:33:26 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/temperature = 21.6
juli 05 08:33:26 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/rel_atm_pressure = 998
juli 05 08:33:26 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/co2 = 518
juli 05 08:33:26 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/voc = 61
juli 05 08:33:26 thinkserver python3[16861]: INFO:airthings-mqtt-ha:Sending messages to mqtt broker...
juli 05 08:33:26 thinkserver python3[16861]: INFO:airthings-mqtt-ha:Done sending messages to mqtt broker.
juli 05 08:33:27 thinkserver python3[16861]: INFO:airthings-mqtt-ha:Waiting 150 seconds.
juli 05 08:36:00 thinkserver python3[16861]: ERROR:pygatt.backends.gatttool.gatttool:Timed out connecting to XX:XX:XX:XX:XX:X1 after 3 seconds.
juli 05 08:36:00 thinkserver python3[16861]: WARNING:airthings-mqtt-ha:Bluetooth error on attempt 1. Retrying in 3 seconds.
juli 05 08:36:03 thinkserver python3[16861]: INFO:airthings-mqtt-ha:Collecting sensor value messages...
juli 05 08:36:03 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/humidity = 64
juli 05 08:36:03 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/radon_1day_avg = 20
juli 05 08:36:03 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/radon_longterm_avg = 167
juli 05 08:36:03 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/temperature = 21.6
juli 05 08:36:03 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/rel_atm_pressure = 998
juli 05 08:36:03 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/co2 = 518
juli 05 08:36:03 thinkserver python3[16861]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/voc = 61
juli 05 08:36:03 thinkserver python3[16861]: INFO:airthings-mqtt-ha:Sending messages to mqtt broker...
juli 05 08:36:03 thinkserver python3[16861]: INFO:airthings-mqtt-ha:Done sending messages to mqtt broker.
juli 05 08:36:03 thinkserver python3[16861]: INFO:airthings-mqtt-ha:Waiting 150 seconds.
Seems the script only requests information from the first device and not the next one.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.