mjmccans / airthings-mqtt-ha

Python script for Airthings devices that uses mqtt to integrate with Home Assistant via mqtt discovery.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple devices

corvy opened this issue · comments

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.

I only have one device so, while I programmed support for multiple devices, I was never able to test it. That being said, I think I see a few issues with your config.toml file. First, I believe you need to include another "[[devices]]" line above the second mac address that you have specified. The script expects an "array of tables" to come from the toml file and that is the correct syntax. Second, I believe you need to have unique names defined for your sensors so that they appear in Home Assistant correctly. For example, for one you may have 'name = "Basement Radon (1 day avg.)"' and for the other you may have 'name = "Main Floor Radon (1 day avg.)"'. Please give these suggestions a try and let me know if they work or if you continue to have issues. Thank you.

Thanks @mjmccans 👍 :) I got it working better now. Found that I was editing the wrong config.toml file aswell ... #newb

These are the logs I get:

The config I am running now is like this:

[[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"

[[devices]]
mac = "XX:XX:XX:XX:XX:X2"
    [devices.radon_1day_avg]
        name = "Washing Room Radon (1 day avg.)"
        unit_of_measurement = "Bq/m3"
        icon = "mdi:radioactive"
    [devices.radon_longterm_avg]
        name = "Washing Room Radon (longterm avg.)"
        unit_of_measurement = "Bq/m3"
        icon = "mdi:radioactive"
    [devices.co2]
        name = "Washing Room CO2"
        unit_of_measurement = "ppm"
        icon = "mdi:molecule-co2"
    [devices.voc]
        name = "Washing Room VOC"
        unit_of_measurement = "ppb"
        icon = "mdi:cloud"
    [devices.temperature]
        name = "Washing Room Temperature"
        device_class = "temperature"
        unit_of_measurement = "°C"
    [devices.humidity]
        name = "Washing Room Humidity"
        device_class = "humidity"
        unit_of_measurement = "%"
    [devices.rel_atm_pressure]
        name = "Washing Room Pressure"
        device_class = "pressure"
        unit_of_measurement = "mbar"

Timeout on 1 device:

juli 06 09:12:19 thinkserver systemd[1]: Started airthings-mqtt-ha control script.
juli 06 09:12:19 thinkserver python3[19366]: INFO:airthings-mqtt-ha:Setting up Airthings sensors...
juli 06 09:12:19 thinkserver python3[19366]: DEBUG:airthings-mqtt-ha:Getting info about device(s)...
juli 06 09:12:26 thinkserver python3[19366]: INFO:airthings-mqtt-ha:XX:XX:XX:XX:XX:X1: Manufacturer: Airthings AS Model: 2930 Serial: 002507 Device:Airthings Wave+
juli 06 09:12:26 thinkserver python3[19366]: INFO:airthings-mqtt-ha:XX:XX:XX:XX:XX:X2: Manufacturer: Airthings AS Model: 2930 Serial: 024140 Device:Airthings Wave+
juli 06 09:12:26 thinkserver python3[19366]: DEBUG:airthings-mqtt-ha:Getting sensors...
juli 06 09:12:29 thinkserver python3[19366]: ERROR:pygatt.backends.gatttool.gatttool:Timed out connecting to XX:XX:XX:XX:XX:X1 after 3 seconds.
juli 06 09:12:29 thinkserver python3[19366]: ERROR:airthings:Failed to discover sensors
juli 06 09:12:29 thinkserver python3[19366]: Traceback (most recent call last):
juli 06 09:12:29 thinkserver python3[19366]:   File "/root/.local/lib/python3.7/site-packages/pygatt/backends/gatttool/gatttool.py", line 415, in connect
juli 06 09:12:29 thinkserver python3[19366]:     self.sendline(cmd)
juli 06 09:12:29 thinkserver python3[19366]:   File "/usr/lib/python3.7/contextlib.py", line 119, in __exit__
juli 06 09:12:29 thinkserver python3[19366]:     next(self.gen)
juli 06 09:12:29 thinkserver python3[19366]:   File "/root/.local/lib/python3.7/site-packages/pygatt/backends/gatttool/gatttool.py", line 191, in event
juli 06 09:12:29 thinkserver python3[19366]:     self.wait(event, timeout)
juli 06 09:12:29 thinkserver python3[19366]:   File "/root/.local/lib/python3.7/site-packages/pygatt/backends/gatttool/gatttool.py", line 157, in wait
juli 06 09:12:29 thinkserver python3[19366]:     raise NotificationTimeout()
juli 06 09:12:29 thinkserver python3[19366]: pygatt.exceptions.NotificationTimeout: None
juli 06 09:12:29 thinkserver python3[19366]: During handling of the above exception, another exception occurred:
juli 06 09:12:29 thinkserver python3[19366]: Traceback (most recent call last):
juli 06 09:12:29 thinkserver python3[19366]:   File "/usr/local/src/airthings/airthings.py", line 241, in get_sensors
juli 06 09:12:29 thinkserver python3[19366]:     dev = self.adapter.connect(mac, 3)
juli 06 09:12:29 thinkserver python3[19366]:   File "/root/.local/lib/python3.7/site-packages/pygatt/backends/gatttool/gatttool.py", line 421, in connect
juli 06 09:12:29 thinkserver python3[19366]:     raise NotConnectedError(message)
juli 06 09:12:29 thinkserver python3[19366]: pygatt.exceptions.NotConnectedError: Timed out connecting to XX:XX:XX:XX:XX:X1 after 3 seconds.
juli 06 09:12:33 thinkserver python3[19366]: DEBUG:airthings-mqtt-ha:XX:XX:XX:XX:XX:X2: Found sensor UUID: b42e2a68-ade7-11e4-89d3-123b93f75cba Handle: 13
juli 06 09:12:33 thinkserver python3[19366]: INFO:airthings-mqtt-ha:Done Airthings setup.
juli 06 09:12:33 thinkserver python3[19366]: DEBUG:airthings-mqtt-ha:Getting sensor data...
juli 06 09:12:33 thinkserver python3[19366]: INFO:airthings-mqtt-ha:Sending HA mqtt discovery configuration messages...
juli 06 09:12:33 thinkserver python3[19366]: INFO:airthings-mqtt-ha:Sending messages to mqtt broker...
juli 06 09:12:33 thinkserver python3[19366]: INFO:airthings-mqtt-ha:Done sending messages to mqtt broker.
juli 06 09:12:33 thinkserver python3[19366]: INFO:airthings-mqtt-ha:Done sending HA mqtt discovery configuration messages.
juli 06 09:12:38 thinkserver python3[19366]: INFO:airthings-mqtt-ha:Collecting sensor value messages...
juli 06 09:12:38 thinkserver python3[19366]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X2/humidity = 53
juli 06 09:12:38 thinkserver python3[19366]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X2/radon_1day_avg = 127
juli 06 09:12:38 thinkserver python3[19366]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X2/radon_longterm_avg = 147
juli 06 09:12:38 thinkserver python3[19366]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X2/temperature = 25.8
juli 06 09:12:38 thinkserver python3[19366]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X2/rel_atm_pressure = 993
juli 06 09:12:38 thinkserver python3[19366]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X2/co2 = 740
juli 06 09:12:38 thinkserver python3[19366]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X2/voc = 95
juli 06 09:12:38 thinkserver python3[19366]: INFO:airthings-mqtt-ha:Sending messages to mqtt broker...
juli 06 09:12:38 thinkserver python3[19366]: INFO:airthings-mqtt-ha:Done sending messages to mqtt broker.
juli 06 09:12:38 thinkserver python3[19366]: INFO:airthings-mqtt-ha:Waiting 150 seconds.

Another attempt, connect to both devices:

juli 06 08:46:56 thinkserver systemd[1]: Started airthings-mqtt-ha control script.
juli 06 08:46:56 thinkserver python3[3207]: INFO:airthings-mqtt-ha:Setting up Airthings sensors...
juli 06 08:46:59 thinkserver python3[3207]: ERROR:pygatt.backends.gatttool.gatttool:Timed out connecting to XX:XX:XX:XX:XX:X1 after 3 seconds.
juli 06 08:46:59 thinkserver python3[3207]: WARNING:airthings-mqtt-ha:Bluetooth error on attempt 1. Retrying in 3 seconds.
juli 06 08:47:07 thinkserver python3[3207]: INFO:airthings-mqtt-ha:XX:XX:XX:XX:XX:X1: Manufacturer: Airthings AS Model: 2930 Serial: 002507 Device:Airthings Wave+
juli 06 08:47:07 thinkserver python3[3207]: INFO:airthings-mqtt-ha:XX:XX:XX:XX:XX:X2: Manufacturer: Airthings AS Model: 2930 Serial: 024140 Device:Airthings Wave+
juli 06 08:47:18 thinkserver python3[3207]: INFO:airthings-mqtt-ha:Done Airthings setup.
juli 06 08:47:20 thinkserver python3[3207]: INFO:airthings-mqtt-ha:Sending HA mqtt discovery configuration messages...
juli 06 08:47:20 thinkserver python3[3207]: INFO:airthings-mqtt-ha:Sending messages to mqtt broker...
juli 06 08:47:20 thinkserver python3[3207]: INFO:airthings-mqtt-ha:Done sending messages to mqtt broker.
juli 06 08:47:20 thinkserver python3[3207]: INFO:airthings-mqtt-ha:Done sending HA mqtt discovery configuration messages.
juli 06 08:47:25 thinkserver python3[3207]: INFO:airthings-mqtt-ha:Collecting sensor value messages...
juli 06 08:47:25 thinkserver python3[3207]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/humidity = 64
juli 06 08:47:25 thinkserver python3[3207]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/radon_1day_avg = 79
juli 06 08:47:25 thinkserver python3[3207]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/radon_longterm_avg = 153
juli 06 08:47:25 thinkserver python3[3207]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/temperature = 23.4
juli 06 08:47:25 thinkserver python3[3207]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/rel_atm_pressure = 993
juli 06 08:47:25 thinkserver python3[3207]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/co2 = 679
juli 06 08:47:25 thinkserver python3[3207]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X1/voc = 99
juli 06 08:47:25 thinkserver python3[3207]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X2/humidity = 53
juli 06 08:47:25 thinkserver python3[3207]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X2/radon_1day_avg = 129
juli 06 08:47:25 thinkserver python3[3207]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X2/radon_longterm_avg = 448
juli 06 08:47:25 thinkserver python3[3207]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X2/temperature = 25.9
juli 06 08:47:25 thinkserver python3[3207]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X2/rel_atm_pressure = 993
juli 06 08:47:25 thinkserver python3[3207]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X2/co2 = 757
juli 06 08:47:25 thinkserver python3[3207]: INFO:airthings-mqtt-ha:airthings/XX:XX:XX:XX:XX:X2/voc = 80
juli 06 08:47:25 thinkserver python3[3207]: INFO:airthings-mqtt-ha:Sending messages to mqtt broker...
juli 06 08:47:25 thinkserver python3[3207]: INFO:airthings-mqtt-ha:Done sending messages to mqtt broker.
juli 06 08:47:25 thinkserver python3[3207]: INFO:airthings-mqtt-ha:Waiting 150 seconds.

Just note that of 20 restarts only 1 time I got connect on both. It usually needs to retry quite a few times.

Sorry about the delay getting back to you. If you are still having problems getting both devices to connect you may want to try playing with the "retry_count" and "retry_wait" variables in the "[general]" section of the config file. Increasing those may help increase the chances of both devices connecting. In addition, I believe there can be some issues if the Airthings app tries to connect with the devices at the same time so you can also try turning off bluetoon on any device upon which that app is installed when you start the script. I hope that helps make connecting more reliable. My single Airthings device is only about 3 meters from the RaspberryPi that runs the script and even then I get a connection timeout every once in a while.

Thanks @mjmccans. No problems on the delay, just happy you respond at all!

I have tried to add this to the config:

[general]
# How many seconds to wait before next refresh. Note that the sensors on the 
# Airthings Wave + only update every 5 minutes, but this has been set to half 
# that to avoid delays in getting new sensor values.
refresh_interval = 150

# Number of times to retry when there is a bluetooth error befor exiting.
retry_count = 50

# Time to wait between reties in seconds.
retry_wait = 15

But still it is very hit and miss. Usually I only get data from one sensor. To get both I need to manually restart until, if I am very lucky, it gets contact with both sensors. The detection seems to "be happy" and move on as soon as one sensor responds. Then the other one is just disregarded. See here:

juli 09 22:15:56 thinkserver systemd[1]: airthings-mqtt-ha.service: Main process exited, code=killed, status=15/TERM
juli 09 22:15:56 thinkserver systemd[1]: airthings-mqtt-ha.service: Succeeded.
juli 09 22:15:56 thinkserver systemd[1]: Stopped airthings-mqtt-ha control script.
juli 09 22:16:59 thinkserver systemd[1]: Started airthings-mqtt-ha control script.
juli 09 22:16:59 thinkserver python3[32595]: INFO:airthings-mqtt-ha:Setting up Airthings sensors...
juli 09 22:16:59 thinkserver python3[32595]: DEBUG:airthings-mqtt-ha:Getting info about device(s)...
juli 09 22:17:02 thinkserver python3[32595]: ERROR:pygatt.backends.gatttool.gatttool:Timed out connecting to C4:64:E3:F0:51:62 after 3 seconds.
juli 09 22:17:02 thinkserver python3[32595]: WARNING:airthings-mqtt-ha:Bluetooth error on attempt 1. Retrying in 15 seconds.
juli 09 22:17:21 thinkserver python3[32595]: INFO:airthings-mqtt-ha:C4:64:E3:F0:51:62: Manufacturer: Airthings AS Model: 2930 Serial: 002507 Device:Airthings Wave+
juli 09 22:17:21 thinkserver python3[32595]: INFO:airthings-mqtt-ha:E0:7D:EA:07:1A:B4: Manufacturer: Airthings AS Model: 2930 Serial: 024140 Device:Airthings Wave+
juli 09 22:17:21 thinkserver python3[32595]: DEBUG:airthings-mqtt-ha:Getting sensors...
juli 09 22:17:24 thinkserver python3[32595]: ERROR:pygatt.backends.gatttool.gatttool:Timed out connecting to C4:64:E3:F0:51:62 after 3 seconds.
juli 09 22:17:24 thinkserver python3[32595]: ERROR:airthings:Failed to discover sensors
juli 09 22:17:24 thinkserver python3[32595]: Traceback (most recent call last):
juli 09 22:17:24 thinkserver python3[32595]:   File "/root/.local/lib/python3.7/site-packages/pygatt/backends/gatttool/gatttool.py", line 415, in connect
juli 09 22:17:24 thinkserver python3[32595]:     self.sendline(cmd)
juli 09 22:17:24 thinkserver python3[32595]:   File "/usr/lib/python3.7/contextlib.py", line 119, in __exit__
juli 09 22:17:24 thinkserver python3[32595]:     next(self.gen)
juli 09 22:17:24 thinkserver python3[32595]:   File "/root/.local/lib/python3.7/site-packages/pygatt/backends/gatttool/gatttool.py", line 191, in event
juli 09 22:17:24 thinkserver python3[32595]:     self.wait(event, timeout)
juli 09 22:17:24 thinkserver python3[32595]:   File "/root/.local/lib/python3.7/site-packages/pygatt/backends/gatttool/gatttool.py", line 157, in wait
juli 09 22:17:24 thinkserver python3[32595]:     raise NotificationTimeout()
juli 09 22:17:24 thinkserver python3[32595]: pygatt.exceptions.NotificationTimeout: None
juli 09 22:17:24 thinkserver python3[32595]: During handling of the above exception, another exception occurred:
juli 09 22:17:24 thinkserver python3[32595]: Traceback (most recent call last):
juli 09 22:17:24 thinkserver python3[32595]:   File "/usr/local/src/airthings/airthings.py", line 241, in get_sensors
juli 09 22:17:24 thinkserver python3[32595]:     dev = self.adapter.connect(mac, 3)
juli 09 22:17:24 thinkserver python3[32595]:   File "/root/.local/lib/python3.7/site-packages/pygatt/backends/gatttool/gatttool.py", line 421, in connect
juli 09 22:17:24 thinkserver python3[32595]:     raise NotConnectedError(message)
juli 09 22:17:24 thinkserver python3[32595]: pygatt.exceptions.NotConnectedError: Timed out connecting to C4:64:E3:F0:51:62 after 3 seconds.
juli 09 22:17:28 thinkserver python3[32595]: DEBUG:airthings-mqtt-ha:E0:7D:EA:07:1A:B4: Found sensor UUID: b42e2a68-ade7-11e4-89d3-123b93f75cba Handle: 13
juli 09 22:17:28 thinkserver python3[32595]: INFO:airthings-mqtt-ha:Done Airthings setup.
juli 09 22:17:28 thinkserver python3[32595]: DEBUG:airthings-mqtt-ha:Getting sensor data...
juli 09 22:17:28 thinkserver python3[32595]: INFO:airthings-mqtt-ha:Sending HA mqtt discovery configuration messages...
juli 09 22:17:28 thinkserver python3[32595]: INFO:airthings-mqtt-ha:Sending messages to mqtt broker...
juli 09 22:17:28 thinkserver python3[32595]: INFO:airthings-mqtt-ha:Done sending messages to mqtt broker.
juli 09 22:17:28 thinkserver python3[32595]: INFO:airthings-mqtt-ha:Done sending HA mqtt discovery configuration messages.
juli 09 22:17:33 thinkserver python3[32595]: INFO:airthings-mqtt-ha:Collecting sensor value messages...
juli 09 22:17:33 thinkserver python3[32595]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/humidity = 49
juli 09 22:17:33 thinkserver python3[32595]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/radon_1day_avg = 175
juli 09 22:17:33 thinkserver python3[32595]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/radon_longterm_avg = 390
juli 09 22:17:33 thinkserver python3[32595]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/temperature = 25.8
juli 09 22:17:33 thinkserver python3[32595]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/rel_atm_pressure = 1005
juli 09 22:17:33 thinkserver python3[32595]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/co2 = 811
juli 09 22:17:33 thinkserver python3[32595]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/voc = 195
juli 09 22:17:33 thinkserver python3[32595]: INFO:airthings-mqtt-ha:Sending messages to mqtt broker...
juli 09 22:17:33 thinkserver python3[32595]: INFO:airthings-mqtt-ha:Done sending messages to mqtt broker.
juli 09 22:17:33 thinkserver python3[32595]: INFO:airthings-mqtt-ha:Waiting 150 seconds.
juli 09 22:20:04 thinkserver python3[32595]: DEBUG:airthings-mqtt-ha:Getting sensor data...
juli 09 22:20:04 thinkserver python3[32595]: INFO:airthings-mqtt-ha:Collecting sensor value messages...
juli 09 22:20:04 thinkserver python3[32595]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/humidity = 49
juli 09 22:20:04 thinkserver python3[32595]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/radon_1day_avg = 175
juli 09 22:20:04 thinkserver python3[32595]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/radon_longterm_avg = 390
juli 09 22:20:04 thinkserver python3[32595]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/temperature = 25.8
juli 09 22:20:04 thinkserver python3[32595]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/rel_atm_pressure = 1005
juli 09 22:20:04 thinkserver python3[32595]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/co2 = 811
juli 09 22:20:04 thinkserver python3[32595]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/voc = 195
juli 09 22:20:04 thinkserver python3[32595]: INFO:airthings-mqtt-ha:Sending messages to mqtt broker...
juli 09 22:20:04 thinkserver python3[32595]: INFO:airthings-mqtt-ha:Done sending messages to mqtt broker.
juli 09 22:20:04 thinkserver python3[32595]: INFO:airthings-mqtt-ha:Waiting 150 seconds.

I dug deeper into this issue and it appears to be an issue with the underlying airthings.py script that I call (or me not understanding how it is intended to work), and that script is what actually does all of the communication with the device itself. However, the potential good news is that the author of that script has updated it and moved to another python bluetooth library for reliability reasons and I am going to see how much work it would be to update my script to use this new version. It may be a drop in replacement, but I find things are usually not that easy. I will provide an update once I have tested it out.

I have done a preliminary update to the new version of airthings.py and pushed it to the repository, and it would be great if you could give it a test to see if it works any better for you. It seems to be working for me, but I have not done much testing yet. Note that you will have to install the bluepy library for this to work, and there are updated instructions in the README.md file for how to do that if you need it. Please let me know if this improves anything for you.

Thanks a lot for looking into this!! :D

Just tested now with the new master. The only think that did not work for me was the bluepy oneliner. Bluepy-helper was not in ~/.local/lib/ but in /usr/local/lib…

So I ran this:
setcap 'cap_net_raw,cap_net_admin+eip' find /usr/local/lib/ | grep bluepy-helper | grep -v bluepy-helper.c

After this commit it seems to work ALOT better. It consistently (at least so far!) finds both sensors. And when one times out on a refresh it still gets polled the next. That is just perfect!

Logs:

juli 14 22:03:16 thinkserver systemd[1]: Started airthings-mqtt-ha control script.
juli 14 22:03:16 thinkserver python3[31250]: INFO:airthings-mqtt-ha:Setting up Airthings sensors...
juli 14 22:03:16 thinkserver python3[31250]: DEBUG:airthings-mqtt-ha:Getting info about device(s)...
juli 14 22:03:36 thinkserver python3[31250]: INFO:airthings-mqtt-ha:C4:64:E3:F0:51:62: Manufacturer: Airthings AS Model: 2930 Serial: 002507 Device:Airthings Wave+
juli 14 22:03:36 thinkserver python3[31250]: INFO:airthings-mqtt-ha:E0:7D:EA:07:1A:B4: Manufacturer: Airthings AS Model: 2930 Serial: 024140 Device:Airthings Wave+
juli 14 22:03:36 thinkserver python3[31250]: DEBUG:airthings-mqtt-ha:Getting sensors...
juli 14 22:03:42 thinkserver python3[31250]: DEBUG:airthings-mqtt-ha:C4:64:E3:F0:51:62: Found sensor UUID: b42e2a68-ade7-11e4-89d3-123b93f75cba Handle: 12
juli 14 22:03:42 thinkserver python3[31250]: DEBUG:airthings-mqtt-ha:E0:7D:EA:07:1A:B4: Found sensor UUID: b42e2a68-ade7-11e4-89d3-123b93f75cba Handle: 12
juli 14 22:03:42 thinkserver python3[31250]: INFO:airthings-mqtt-ha:Done Airthings setup.
juli 14 22:03:42 thinkserver python3[31250]: DEBUG:airthings-mqtt-ha:Getting sensor data...
juli 14 22:03:45 thinkserver python3[31250]: INFO:airthings-mqtt-ha:Sending HA mqtt discovery configuration messages...
juli 14 22:03:45 thinkserver python3[31250]: INFO:airthings-mqtt-ha:Sending messages to mqtt broker...
juli 14 22:03:45 thinkserver python3[31250]: INFO:airthings-mqtt-ha:Done sending messages to mqtt broker.
juli 14 22:03:45 thinkserver python3[31250]: INFO:airthings-mqtt-ha:Done sending HA mqtt discovery configuration messages.
juli 14 22:03:50 thinkserver python3[31250]: INFO:airthings-mqtt-ha:Collecting sensor value messages...
juli 14 22:03:50 thinkserver python3[31250]: INFO:airthings-mqtt-ha:airthings/C4:64:E3:F0:51:62/humidity = 70
juli 14 22:03:50 thinkserver python3[31250]: INFO:airthings-mqtt-ha:airthings/C4:64:E3:F0:51:62/radon_1day_avg = 90
juli 14 22:03:50 thinkserver python3[31250]: INFO:airthings-mqtt-ha:airthings/C4:64:E3:F0:51:62/radon_longterm_avg = 78
juli 14 22:03:50 thinkserver python3[31250]: INFO:airthings-mqtt-ha:airthings/C4:64:E3:F0:51:62/temperature = 23.4
juli 14 22:03:50 thinkserver python3[31250]: INFO:airthings-mqtt-ha:airthings/C4:64:E3:F0:51:62/rel_atm_pressure = 998
juli 14 22:03:50 thinkserver python3[31250]: INFO:airthings-mqtt-ha:airthings/C4:64:E3:F0:51:62/co2 = 652
juli 14 22:03:50 thinkserver python3[31250]: INFO:airthings-mqtt-ha:airthings/C4:64:E3:F0:51:62/voc = 105
juli 14 22:03:50 thinkserver python3[31250]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/humidity = 58
juli 14 22:03:50 thinkserver python3[31250]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/radon_1day_avg = 302
juli 14 22:03:50 thinkserver python3[31250]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/radon_longterm_avg = 362
juli 14 22:03:50 thinkserver python3[31250]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/temperature = 25.6
juli 14 22:03:50 thinkserver python3[31250]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/rel_atm_pressure = 997
juli 14 22:03:50 thinkserver python3[31250]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/co2 = 931
juli 14 22:03:50 thinkserver python3[31250]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/voc = 270
juli 14 22:03:50 thinkserver python3[31250]: INFO:airthings-mqtt-ha:Sending messages to mqtt broker...
juli 14 22:03:50 thinkserver python3[31250]: INFO:airthings-mqtt-ha:Done sending messages to mqtt broker.
juli 14 22:03:50 thinkserver python3[31250]: INFO:airthings-mqtt-ha:Waiting 150 seconds.
juli 14 22:05:21 thinkserver systemd[1]: Stopping airthings-mqtt-ha control script...
juli 14 22:05:21 thinkserver systemd[1]: airthings-mqtt-ha.service: Main process exited, code=killed, status=15/TERM
juli 14 22:05:21 thinkserver systemd[1]: airthings-mqtt-ha.service: Succeeded.
juli 14 22:05:21 thinkserver systemd[1]: Stopped airthings-mqtt-ha control script.
juli 14 22:05:30 thinkserver systemd[1]: Started airthings-mqtt-ha control script.
juli 14 22:05:30 thinkserver python3[32686]: INFO:airthings-mqtt-ha:Setting up Airthings sensors...
juli 14 22:05:30 thinkserver python3[32686]: DEBUG:airthings-mqtt-ha:Getting info about device(s)...
juli 14 22:05:47 thinkserver python3[32686]: INFO:airthings-mqtt-ha:C4:64:E3:F0:51:62: Manufacturer: Airthings AS Model: 2930 Serial: 002507 Device:Airthings Wave+
juli 14 22:05:47 thinkserver python3[32686]: INFO:airthings-mqtt-ha:E0:7D:EA:07:1A:B4: Manufacturer: Airthings AS Model: 2930 Serial: 024140 Device:Airthings Wave+
juli 14 22:05:47 thinkserver python3[32686]: DEBUG:airthings-mqtt-ha:Getting sensors...
juli 14 22:06:09 thinkserver python3[32686]: DEBUG:airthings-mqtt-ha:C4:64:E3:F0:51:62: Found sensor UUID: b42e2a68-ade7-11e4-89d3-123b93f75cba Handle: 12
juli 14 22:06:09 thinkserver python3[32686]: DEBUG:airthings-mqtt-ha:E0:7D:EA:07:1A:B4: Found sensor UUID: b42e2a68-ade7-11e4-89d3-123b93f75cba Handle: 12
juli 14 22:06:09 thinkserver python3[32686]: INFO:airthings-mqtt-ha:Done Airthings setup.
juli 14 22:06:09 thinkserver python3[32686]: DEBUG:airthings-mqtt-ha:Getting sensor data...
juli 14 22:06:30 thinkserver python3[32686]: INFO:airthings-mqtt-ha:Sending HA mqtt discovery configuration messages...
juli 14 22:06:30 thinkserver python3[32686]: INFO:airthings-mqtt-ha:Sending messages to mqtt broker...
juli 14 22:06:30 thinkserver python3[32686]: INFO:airthings-mqtt-ha:Done sending messages to mqtt broker.
juli 14 22:06:30 thinkserver python3[32686]: INFO:airthings-mqtt-ha:Done sending HA mqtt discovery configuration messages.
juli 14 22:06:35 thinkserver python3[32686]: INFO:airthings-mqtt-ha:Collecting sensor value messages...
juli 14 22:06:35 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/humidity = 58
juli 14 22:06:35 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/radon_1day_avg = 110
juli 14 22:06:35 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/radon_longterm_avg = 122
juli 14 22:06:35 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/temperature = 25.6
juli 14 22:06:35 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/rel_atm_pressure = 997
juli 14 22:06:35 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/co2 = 931
juli 14 22:06:35 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/voc = 270
juli 14 22:06:35 thinkserver python3[32686]: INFO:airthings-mqtt-ha:Sending messages to mqtt broker...
juli 14 22:06:35 thinkserver python3[32686]: INFO:airthings-mqtt-ha:Done sending messages to mqtt broker.
juli 14 22:06:35 thinkserver python3[32686]: INFO:airthings-mqtt-ha:Waiting 150 seconds.
juli 14 22:09:05 thinkserver python3[32686]: DEBUG:airthings-mqtt-ha:Getting sensor data...
juli 14 22:09:05 thinkserver python3[32686]: INFO:airthings-mqtt-ha:Collecting sensor value messages...
juli 14 22:09:05 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/humidity = 58
juli 14 22:09:05 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/radon_1day_avg = 110
juli 14 22:09:05 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/radon_longterm_avg = 122
juli 14 22:09:05 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/temperature = 25.6
juli 14 22:09:05 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/rel_atm_pressure = 997
juli 14 22:09:05 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/co2 = 931
juli 14 22:09:05 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/voc = 270
juli 14 22:09:05 thinkserver python3[32686]: INFO:airthings-mqtt-ha:Sending messages to mqtt broker...
juli 14 22:09:05 thinkserver python3[32686]: INFO:airthings-mqtt-ha:Done sending messages to mqtt broker.
juli 14 22:09:05 thinkserver python3[32686]: INFO:airthings-mqtt-ha:Waiting 150 seconds.
juli 14 22:11:35 thinkserver python3[32686]: DEBUG:airthings-mqtt-ha:Getting sensor data...
juli 14 22:11:41 thinkserver python3[32686]: INFO:airthings-mqtt-ha:Collecting sensor value messages...
juli 14 22:11:41 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/humidity = 58
juli 14 22:11:41 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/radon_1day_avg = 110
juli 14 22:11:41 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/radon_longterm_avg = 122
juli 14 22:11:41 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/temperature = 25.6
juli 14 22:11:41 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/rel_atm_pressure = 997
juli 14 22:11:41 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/co2 = 911
juli 14 22:11:41 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/E0:7D:EA:07:1A:B4/voc = 359
juli 14 22:11:41 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/C4:64:E3:F0:51:62/humidity = 70
juli 14 22:11:41 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/C4:64:E3:F0:51:62/radon_1day_avg = 90
juli 14 22:11:41 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/C4:64:E3:F0:51:62/radon_longterm_avg = 78
juli 14 22:11:41 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/C4:64:E3:F0:51:62/temperature = 23.3
juli 14 22:11:41 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/C4:64:E3:F0:51:62/rel_atm_pressure = 998
juli 14 22:11:41 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/C4:64:E3:F0:51:62/co2 = 618
juli 14 22:11:41 thinkserver python3[32686]: INFO:airthings-mqtt-ha:airthings/C4:64:E3:F0:51:62/voc = 112
juli 14 22:11:41 thinkserver python3[32686]: INFO:airthings-mqtt-ha:Sending messages to mqtt broker...
juli 14 22:11:41 thinkserver python3[32686]: INFO:airthings-mqtt-ha:Done sending messages to mqtt broker.
juli 14 22:11:41 thinkserver python3[32686]: INFO:airthings-mqtt-ha:Waiting 150 seconds.

The one sensor that is most reliable is close to the server (washing room) and the other one is in the basement TV room. Maybe some 10 meters away (and two walls).

This is a great upgrade for me. Seems perfect for now :) and I will close this ticket for now. Thanks for a great service!

Great to hear and I am glad it is working better for you. I still have some cleanup to do in the code, but I will do that when I have a bit more time. Just let me know if you have any other issues and I will do my best to help solve them.

Thank again, just following up that this has now been working 100% for the last week. No dropouts! :D

Thank you for letting me know. I have done a bit more cleanup on the code so when you have a chance you may want to update again.

Updated now :) will let you know!