Airthings Radon Detector

These are on sale on Bestbuy and Amazon today. They support Bluetooth with a Pi script on their site.

Would this be something that could be added to hass.io

http://airthings.com/raspberry-pi/

Hi @jpreiditsch

I just released a first iteration at a custom component called sensor.airthings_wave. I look forward for you to test and to give me your feedback.

4 Likes

Great work! I have tried this on my hassos Pi 3 with built-in Bluetooth. Looks promising!

Apart from known issues, I have timeout issues after x connects. Not sure why? anyone else?

I have tried timeout setting from 60-1200sec. With 60-300sec timeout happens after random 8-15 connects and longest run was with 1200sec with 17 connects.

Thanks @yada75 !

I used to have stability issues until I upgraded the pygatt library to 4.0.3 but that was using hassio on an Odroid XU4 and using an external bluetooth adaptor. Its been rock solid for a couple of weeks since then. I don’t have a Raspberry Pi 3 to test on. There’s another similar project which has an interesting comment regarding stability. https://github.com/gkreitz/homeassistant-airthings/blob/master/airthings.py#L54

Perhaps someone with a Pi 3 could give it a go either by modifying my project or using the aforementioned?

Thanks @MartyTremblay, yes hopefully someone else will give this a try. But in meanwhile can I easily change something so it continues to try to connect after timeout or could you please add some retry function counter to retry connect x times? My python skills sucks, so I would need big help to do this.

As for the other project I see it’s for the plus and it needs to be changed to work with regular wave, I have no idea how to do that yet.

I changed so try block is inside the while loop so it will keep trying, so far next connect after timeout is ok.

if I understand this correctly, a connection counter that triggers break inside try -> except could be used to break out of while loop?

Works great on my Raspberry Pi 3B running hassio. Copied the code into the new directory and updated my configuration.yaml file. Everything has been running well for 12 hours, look forward to seeing how it does long term. Thanks for your hard work on this!

From what you’re describing, I think you might be using an older version of the component. Can you try downloading the most recent version?

Happy to hear!

I downloaded 6 days ago and component says 9days ago, is there a newer version then this one 9 days ago?

pygatt version 403 was installed in deps/lib/python3.7/site-packages/pygatt.

I changed this to:

Code
def run(self):
    """Thread that keeps connection alive."""
    # pylint: disable=import-error
    import pygatt
    from pygatt.exceptions import (
        BLEError, NotConnectedError, NotificationTimeout)

    adapter = pygatt.backends.GATTToolBackend()
    while self.keep_going:
        try:
            _LOGGER.debug("Connecting to %s", self.name)

            # We need concurrent connect, so lets not reset the device
            adapter.start(reset_on_start=False)
            device = adapter.connect(self.mac, CONNECT_TIMEOUT)

            # Give the adaptor a breather
            self.event.wait(1)
            for s in sensors:
                val = struct.unpack(
                      s.format_type,
                      device.char_read(
                          s.uuid, timeout=CONNECT_TIMEOUT))
                _LOGGER.debug("Sensor %s: %s", s.name, val)

                if s.name == 'date_time':
                    val = str(datetime(val[0], val[1], val[2], val[3],
                                       val[4], val[5]).isoformat())
                    self.data[s.name] = val
                elif s.name == 'illuminance_accelerometer':
                    self.data['illuminance'] = str(val[0] * s.scale)
                    self.data['accelerometer'] = str(val[1] * s.scale)
                else:
                    self.data[s.name] = str(round(val[0] * s.scale, 1))
        except (BLEError, NotConnectedError, NotificationTimeout) as ex:
            _LOGGER.error("Exception: %s ", str(ex))
        finally:
            adapter.stop()
            self.event.wait(self.scan_interval.total_seconds())

Now i get 1-2 connection timeouts/day in log so far. Now it don’t stop on error and just continues…

Just wanted to report that I’m using your custom component successfully on a Raspberry Pi 3 B+ running HASSIO 0.93.2. Just one problem I noticed is that it prevents me from using the Bluetooth LE Tracker component. at the same time.

If I remove this airthings component, then the BLE tracker works and once I add it back, BLE breaks but airthings works again.

I asked AirThings about an official API, this was their response:

We do have a REST API currently in beta testing for our business customers. This will be made available also to consumers a few months after the summer, most likely in September/October timeframe :slight_smile:

is this a known issue?

I don’t think so

has anyone managed to get this component to work on anything other than a rasp pi? I use a NUC running ubuntu and hassio and would love to use this if possible.
Cheers!

Hi,

I installed this custom component using HACS on my HASSIO 0.104.2 on RPI3. It works for a couple of hours and then it just stops working. I see no error messages in the logs.

Restarting Home Assistant starts the syncing again and then it stops working after a couple of hours again.

I have no idea where to start troubleshooting.

//Magnus

I implemented your change in my HassIO installation and after that it works better. It works for about 24 hours instead of previously 2 hours. However, it still stopps eventually and Home Assistant needs to be restarted for it to work again.

I turned on debug logging for the component and normally this is what I see:

2020-01-22 08:31:43 DEBUG (Airthings Wave) [custom_components.airthings_wave.sensor] Connecting to Airthings Wave                                             
2020-01-22 08:31:44 INFO (Thread-289) [pygatt.backends.gatttool.gatttool] Running...                                                                       
2020-01-22 08:31:44 INFO (Airthings Wave) [pygatt.backends.gatttool.gatttool] Connecting to 98:07:2D:49:5F:FC with timeout=30                                 
2020-01-22 08:31:46 DEBUG (Airthings Wave) [custom_components.airthings_wave.sensor] Sensor date_time: (2020, 1, 22, 7, 31, 53)                            
2020-01-22 08:31:46 DEBUG (Airthings Wave) [custom_components.airthings_wave.sensor] Sensor temperature: (2260,)                                              
2020-01-22 08:31:46 DEBUG (Airthings Wave) [custom_components.airthings_wave.sensor] Sensor humidity: (3750,)                                             
2020-01-22 08:31:46 DEBUG (Airthings Wave) [custom_components.airthings_wave.sensor] Sensor radon_1day_avg: (163,)                                            
2020-01-22 08:31:46 DEBUG (Airthings Wave) [custom_components.airthings_wave.sensor] Sensor radon_longterm_avg: (242,)                                     
2020-01-22 08:31:46 DEBUG (Airthings Wave) [custom_components.airthings_wave.sensor] Sensor illuminance_accelerometer: (166, 14)                              
2020-01-22 08:31:46 INFO (Airthings Wave) [pygatt.backends.gatttool.gatttool] Stopping                                                                     
2020-01-22 08:31:47 INFO (Thread-289) [pygatt.backends.gatttool.gatttool] Listener thread finished

But when it stops working, I only get this, and then nothing:

2020-01-22 08:36:47 DEBUG (Airthings Wave) [custom_components.airthings_wave.sensor] Connecting to Airthings Wave

Any ideas?

//Magnus

For me it worked flawlessly in Hassio up to 0.102 something, then a managed to break everything. I haven’t gotten around to get everything up running again. Might be that something changed in newer Hassio versions?

Thought this may be of interest regarding connection issues:

https://sifter.org/~simon/journal/20191210.1.html

Specifically :

Note, as of 2019-12-06, you have to fix a bug in the bluepy btle.py library, which typically resides somewhere like /usr/local/lib/python3.6/dist-packages/bluepy/btle.py: Comment out the _getResp in disconnect() or it can hang on readline when a ‘stat disc’ reply from the helper is overlooked (as in during a call to setMTU). I’ve reported the bug but it’s just crickets over there.