home-assistant-config icon indicating copy to clipboard operation
home-assistant-config copied to clipboard

Component: Airthings Wave integration

Open renemarc opened this issue 7 years ago • 42 comments

As a user, I want to access the output of an Airthings Wave radon detector so that I can get a overview of indoor radiation hazards.

Acceptance criteria

  1. It's done when Airthings Wave Bluetooth data can be read accurately within Home Assistant.
  2. It's done when alerts are set when Radon levels are too high.

References

  • https://airthings.com/raspberry-pi/
  • https://blog.donbowman.ca/2018/01/02/decoding-the-airthings-wave-radon-output/

renemarc avatar Feb 22 '18 18:02 renemarc

Probably not exactly what you want but my HA server is not within BTLE range of my Airthings Wave nor does it have bluetooth, so I'm running this on a Pi0w and publishing to HA's MQTT server:

https://github.com/hpeyerl/airthingswave-mqtt

  - platform: mqtt
    state_topic: basement-radon/Radon-Day
    name: "Radon Daily"
  - platform: mqtt
    state_topic: basement-radon/Radon-Long-Term
    name: "Radon Long Term"
  - platform: mqtt
    state_topic: basement-radon/Temperature
    name: "Basement Temperature"
  - platform: mqtt
    state_topic: basement-radon/Humidity
    name: "Basement Humidity"

How many story points do I get?

hpeyerl avatar Jun 30 '18 12:06 hpeyerl

hpeyerl: Can this be adapted to include the upcoming Wave Plus due this month? It adds CO2, VOC and Pressure. I might order one tomorrow.

Cavemanz avatar Jul 12 '18 20:07 Cavemanz

I don't know. I'm guessing probably but I don't have one nor have I ordered one.

On July 12, 2018 2:43:57 PM MDT, Cavemanz [email protected] wrote:

hpeyerl: Can this be adapted to include the upcoming Wave Plus due this month? It adds CO2, VOC and Pressure. I might order one tomorrow.

-- You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/renemarc/home-assistant-config/issues/9#issuecomment-404644532

hpeyerl avatar Jul 12 '18 20:07 hpeyerl

Ok, is the integration you made working as it should? How have you presented the data in Home Assistant?

Cavemanz avatar Jul 12 '18 21:07 Cavemanz

It publishes to MQTT.

On July 12, 2018 3:37:01 PM MDT, Cavemanz [email protected] wrote:

Ok, is the integration you made working as it should? How have you presented the data in Home Assistant?

-- You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/renemarc/home-assistant-config/issues/9#issuecomment-404658628

hpeyerl avatar Jul 12 '18 21:07 hpeyerl

Ooh, I like! Very nice job, thanks for sharing, you definitely deserve a 🍺 at the retro! 😃

Indeed, having such a dedicated bridge that can be located closer to the AirThings Wave looks like a much better idea than trying to rely on a sometimes less ideally placed Home Assistant Pi host. And it's mode modular to boot. I am definitely trying out your code ...and updating my documentation to link to your repo. 👍

renemarc avatar Jul 13 '18 16:07 renemarc

I just put in an order for the Wave Plus which is supposed to ship 19th of July. Please report back on your experiences. According to Wave Plus specs it requires minimum BT 4.2. Only the Pi 3 B+ meets this, but Ill test with my regular 3B first..

Cavemanz avatar Jul 13 '18 16:07 Cavemanz

Airthings is not an open source friendly company. I asked for documentation so I could implement a python API and was told they don't have any documentation but pointed me at their two example scripts. I just wrapped a simple API around one of those and added some MQTT publishing. Unfortunately, all of my readings are coming in with a date stamp of 2010 because I've never installed their Android app and mated it with my phone. So I subsequently contacted them to see if they could tell me what UUID and format so I could set the date from my API and was told they wouldn't release that information.

So I wouldn't hold my breath hoping to get any information on the Wave Plus out of them unless they decide to get around to updating their example script.

hpeyerl avatar Jul 14 '18 12:07 hpeyerl

Indeed, I dont have very high hopes that they will somehow open up very much. HeatIt (Norwegian company selling various Z-Wave products) were cooperating with Airthings on a Z-Wave version of the Wave. That was supposed to launch right about now but was cancelled entirely in May. The likelyhood of Airthings being the one to say no is 99%.

If theres no way to get any meaningful data out of this Wave Plus, I have a deal to sell the unit on to a friend who has real issues with radon.

Cavemanz avatar Jul 14 '18 22:07 Cavemanz

I would encourage you to ask them to be more open-sourcey... I sent mail to their sales channel.

hpeyerl avatar Jul 15 '18 13:07 hpeyerl

Several Norwegians into home automation have tried, but they dont seem to care at the moment. I can understand their take with a hub in a commercial setting. However, being based on BT is a bad design decision to begin with.

Cavemanz avatar Jul 15 '18 14:07 Cavemanz

I ended up cancelling my order. It was pushed back to september, so I didnt wanna wait.

Cavemanz avatar Jul 28 '18 20:07 Cavemanz

class AirthingsWave: def init(self, config_file): Class instantiation requires a path to a config file in YAML format.

How do i set the path to the config file?

grangemd avatar Dec 07 '18 16:12 grangemd

@grangemd You can set the path as a command-line argument, for example:

python -m airthingswave-mqtt ~/config.yaml

renemarc avatar Dec 07 '18 17:12 renemarc

maybe i am doing this wrong because i am getting an error of

Unable to find component waves and Setup failed for waves: Component not found.

Not sure if I put the file in the wrong location or if I have done something else wrong

grangemd avatar Dec 07 '18 17:12 grangemd

From the instructions: https://github.com/hpeyerl/airthingswave-mqtt

waves:

  • name: "basement-radon" addr: 98:07:2d:43:4d:ff

hpeyerl avatar Dec 07 '18 20:12 hpeyerl

I guess what I am trying to do may not be correct. I am trying run this directly from a python file from HA from my Unraid server using the custom components. I am sure I am doing this wrong but not sure how to do this or if I can do it this way.

grangemd avatar Dec 07 '18 20:12 grangemd

Oh, that's different. I can't help you with that because I have no experience with the HA custom components mechanism.

Sorry, you're on your own.

On December 7, 2018 1:26:10 PM MST, grangemd [email protected] wrote:

I guess what I am trying to do may not be correct. I am trying run this directly from a python file from HA from my Unraid server using the custom components. I am sure I am doing this wrong but not sure how to do this or if I can do it this way.

-- You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/renemarc/home-assistant-config/issues/9#issuecomment-445355334

hpeyerl avatar Dec 07 '18 23:12 hpeyerl

Maybe this is the wrong place to put this but I can't find anywhere else to direct message so I will see if I can get help here. I set up a pi to do this. What exactly do I need to do? I can download the zip file and extract it to a folder. Then do I need to setup a cron job and call what file? Also do I need to create a conf.yaml file and how or where do I put the path to this conf.yaml file? Does it get called out in airthingswave.py? Sorry this is new to me.

grangemd avatar Dec 13 '18 00:12 grangemd

@grangemd: A quick and easy way to install airthingswave-mqtt on a Raspberry Pi is to use this project I've uploaded lately. It uses @hpeyerl's code, is based on balena (an open-source Docker-compatible stack for IoT) and creates a stand-alone, plug-in, secure bridge that's easy to manage:

https://github.com/renemarc/balena-airthingswave

I've been using this solution for a few months now and it's clicking along fine. Hopefully the included README.md should be useful to get you going, and your you prefer to go the manual route then the Dockerfiles and simple shell scripts should help you in any case. It is Alpine-based for simplicity and has a relatively small size; a Debian-based alternative is also available here for reference, but I've done fewer tests on it and am no longer using it.

If you prefer a more manual approach:

  1. Assuming that you have Python, PIP and Bluez installed, you still need to install the Python packages:

    pip install --no-cache-dir airthingswave-mqtt==0.2 PyYAML
    
  2. Once set, you first scan for your Airthings Wave MAC accress like described here: https://airthings.com/raspberry-pi/

  3. Then you create a configuration file like so with the MAC address(es) of your wave(s) and place it wherever you want, like in your home directory (~).

    mqtt:
      broker: 192.168.1.5
      port: 1883
      username: user
      password: super-secret-password
    
    waves:
      - name: "basement/radon"
        addr: "cc:78:ab:00:00:00"
    
  4. And finally, you create cron or systemd job that runs the following line:

    python -m airthingswave-mqtt /path/to/your/config.yaml
    

Each project above uses either cron (Alpine) or systemd (Debian).

Enjoy! 😃

renemarc avatar Dec 16 '18 03:12 renemarc

@renemarc I am trying to follow the readme and I get to the Installation Section. When I enter the line

git push balena master

I end up getting an error

mgranger@Millennium-Falcon MINGW64 /c/git/balena-airthingswave (master)
$ git push balena master
Enumerating objects: 15, done.
Counting objects: 100% (15/15), done.
Delta compression using up to 8 threads
Compressing objects: 100% (12/12), done.
Writing objects: 100% (15/15), 13.39 KiB \| 4.46 MiB/s, done.
Total 15 (delta 1), reused 15 (delta 1)
[Info]     Starting build for airthings-mqtt, user grangemd
[Info]     Dashboard link: https://dashboard.balena-cloud.com/apps/1320241/devices
[Info]     Building on arm02
[Info]     Pulling previous images for caching purposes...
[Success]  Successfully pulled cache images
[main]     Step 1/12 : FROM balenalib/raspberrypi3-alpine-python:2
[main]      ---> db31fd961548
[main]     Step 2/12 : ENV AIRTHINGSWAVE_VERSION 0.2
[main]     Using cache
[main]      ---> fd22eedfcb9f
[main]     Step 3/12 : ENV VERSION 0.2
[main]     Using cache
[main]      ---> 4fc32ee0257d
[main]     Step 4/12 : ENV CRON_PERIOD hourly
[main]     Using cache
[main]      ---> 50026ee9452c
[main]     Step 5/12 : LABEL org.label-schema.name "balena AirthingsWave" org.label-schema.description
"Airthings Wave radon detector bridge for single-board computers." org.label-schema.vcs-url
"https://github.com/renemarc/balena-airthingswave" org.label-schema.url "htt ps://airthings.com/wave/"
org.label-schema.version ${VERSION} org.label-schema.schema-version "1.0"
[main]     Using cache
[main]      ---> 3cf7678d66cd
[main]     Step 6/12 : WORKDIR /usr/src/app
[main]     Using cache
[main]      ---> cca174e69ea7
[main]     Step 7/12 : RUN apk add       bluez       g++       glib-dev       make       py-setuptools  && pip
install --no-cache-dir       airthingswave-mqtt==${AIRTHINGSWAVE_VERSION}       PyYAML  && wget
airthings.com/tech/find_wave.py  && find /usr/local       \( -ty pe d -a -name test -o -name tests \)       -o
\( -type f -a -name '*.pyc' -o -name '*.pyo' \)       -exec rm -rf '{}' +  && apk del       g++       glib-dev
make       py-setuptools
[main]      ---> Running in 38143235bd8c
[main]     fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/armhf/APKINDEX.tar.gz
[main]     fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/armhf/APKINDEX.tar.gz
[main]     (1/44) Installing libintl (0.19.8.1-r2)
[main]     (2/44) Installing libmount (2.32-r0)
[main]     (3/44) Installing pcre (8.42-r0)
[main]     (4/44) Installing glib (2.56.1-r0)
[main]     (5/44) Installing polkit (0.105-r8)
[main]     (6/44) Installing libxau (1.0.8-r2)
[main]     (7/44) Installing libbsd (0.8.6-r2)
[main]     (8/44) Installing libxdmcp (1.1.2-r4)
[main]     (9/44) Installing libxcb (1.13-r2)
[main]     (10/44) Installing libx11 (1.6.6-r0)
[main]     (11/44) Installing consolekit2 (1.2.1-r0)
[main]     (12/44) Installing bluez (5.49-r2)
[main]     (13/44) Installing libstdc++ (6.4.0-r9)
[main]     (14/44) Installing binutils (2.30-r5)
[main]     (15/44) Installing isl (0.18-r0)
[main]     (16/44) Installing libgomp (6.4.0-r9)
[main]     (17/44) Installing libatomic (6.4.0-r9)
[main]     (18/44) Installing mpfr3 (3.1.5-r1)
[main]     (19/44) Installing mpc1 (1.0.3-r1)
[main]     (20/44) Installing gcc (6.4.0-r9)
[main]     (21/44) Installing musl-dev (1.1.19-r10)
[main]     (22/44) Installing libc-dev (0.7.1-r0)
[main]     (23/44) Installing g++ (6.4.0-r9)
[main]     (24/44) Installing perl (5.26.3-r0)
[main]     (25/44) Installing gdbm (1.13-r1)
[main]     (26/44) Installing python2 (2.7.15-r1)
[main]     (27/44) Installing gettext-asprintf (0.19.8.1-r2)
[main]     (28/44) Installing gettext-libs (0.19.8.1-r2)
[main]     (29/44) Installing libxml2 (2.9.8-r1)
[main]     (30/44) Installing gettext (0.19.8.1-r2)
[main]     (31/44) Installing gettext-dev (0.19.8.1-r2)
[main]     (32/44) Installing zlib-dev (1.2.11-r1)
[main]     (33/44) Installing bzip2-dev (1.0.6-r6)
[main]     (34/44) Installing libffi-dev (3.2.1-r4)
[main]     (35/44) Installing libfdisk (2.32-r0)
[main]     (36/44) Installing libsmartcols (2.32-r0)
[main]     (37/44) Installing util-linux-dev (2.32-r0)
[main]     (38/44) Installing libpcre16 (8.42-r0)
[main]     (39/44) Installing libpcre32 (8.42-r0)
[main]     (40/44) Installing libpcrecpp (8.42-r0)
[main]     (41/44) Installing pcre-dev (8.42-r0)
[main]     (42/44) Installing glib-dev (2.56.1-r0)
[main]     (43/44) Installing make (4.2.1-r2)
[main]     (44/44) Installing py-setuptools (39.1.0-r0)
[main]     Executing busybox-1.28.4-r1.trigger
[main]     Executing glib-2.56.1-r0.trigger
[main]     No schema files found: doing nothing.
[main]     Executing dbus-1.10.24-r1.trigger
[main]     OK: 260 MiB in 112 packages
[main]     Collecting airthingswave-mqtt==0.2
[main]       Downloading
https://files.pythonhosted.org/packages/93/2b/450fede825f25fcccefcbb05f1fd3cb15b15a8393c743811
2182e26baaa/airthingswave-mqtt-0.2.tar.gz
[main]     Collecting PyYAML
[main]       Downloading
https://files.pythonhosted.org/packages/9e/a3/1d13970c3f36777c583f136c136f804d70f500168edc1edea6daa7200769/PyYAML-3.13.tar.gz (270kB)
[main]     Collecting bluepy>=1.1.4 (from airthingswave-mqtt==0.2)
[main]       Downloading
https://files.pythonhosted.org/packages/27/91/6cfca10bee9862f93015413cf9e6a52c3081a71f1518963396a055128f8e/bluepy-1.3.0.tar.gz (217kB)
[main]     Collecting paho-mqtt>=1.3.1 (from airthingswave-mqtt==0.2)
[main]       Downloading
https://files.pythonhosted.org/packages/25/63/db25e62979c2a716a74950c9ed658dce431b5cb01fde29eb6cba9489a904/paho-mqtt-1.4.0.tar.gz (88kB)
[main]     Installing collected packages: bluepy, paho-mqtt, airthingswave-mqtt, PyYAML
[main]       Running setup.py install for bluepy: started
[main]         Running setup.py install for bluepy: finished with status 'error'
[main]         Complete output from command /usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-4XeoOx/bluepy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__,  'exec'))" install --record /tmp/pip-record-SJWK6g/install-record.txt --single-version-externally-managed --compile:
[main]         running install
[main]         running build
[main]         running build_py
[main]         Working dir is /tmp/pip-install-4XeoOx/bluepy
[main]         execute make -C ./bluepy clean
[main]         execute make -C bluepy -j1
[main]         Failed to compile bluepy-helper. Exiting install.
[main]         Command was 'make -C bluepy -j1' in /tmp/pip-install-4XeoOx/bluepy
[main]         Return code was 2
[main]         Output was:
[main]         make: Entering directory '/tmp/pip-install-4XeoOx/bluepy/bluepy'
[main]         tar xzf bluez-src.tgz
[main]         touch ./bluez-5.47/lib/bluetooth.c ./bluez-5.47/lib/hci.c ./bluez-5.47/lib/sdp.c ./bluez-5.47/lib/uuid.c ./bluez-5.47/attrib/att.c ./bluez-5.47/attrib/gatt.c ./bluez-5.47/attrib/gattrib.c ./bluez-5.47/attrib/utils.c ./bluez-5.47/btio/btio.c ./bluez-5.47/sr c/log.c ./bluez-5.47/src/shared/mgmt.c ./bluez-5.47/src/shared/crypto.c ./bluez-5.47/src/shared/att.c ./bluez-5.47/src/shared/queue.c ./bluez-5.47/src/shared/util.c ./bluez-5.47/src/shared/io-glib.c ./bluez-5.47/src/shared/timeout-glib.c
[main]         cc -L. -g -Wall  -Os -DHAVE_CONFIG_H -I./bluez-5.47/attrib -I./bluez-5.47 -I./bluez-5.47/lib -I./bluez-5.47/src -I./bluez-5.47/gdbus -I./bluez-5.47/btio -I./bluez-5.47/sys -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include  -o bluepy-helper bluepy-helper. c ./bluez-5.47/lib/bluetooth.c ./bluez-5.47/lib/hci.c ./bluez-5.47/lib/sdp.c ./bluez-5.47/lib/uuid.c ./bluez-5.47/attrib/att.c ./bluez-5.47/attrib/gatt.c ./bluez-5.47/attrib/gattrib.c ./bluez-5.47/attrib/utils.c ./bluez-5.47/btio/btio.c ./bluez-5.47/src/log.c ./bluez-5.4 7/src/shared/mgmt.c ./bluez-5.47/src/shared/crypto.c ./bluez-5.47/src/shared/att.c ./bluez-5.47/src/shared/queue.c ./bluez-5.47/src/shared/util.c ./bluez-5.47/src/shared/io-glib.c ./bluez-5.47/src/shared/timeout-glib.c -lglib-2.0 -lintl
[main]         ./bluez-5.47/src/shared/crypto.c:68:26: fatal error: linux/if_alg.h: No such file or directory
[main]          #include
[main]                                   ^
[main]         compilation terminated.
[main]         make: *** [Makefile:30: bluepy-helper] Error 1
[main]         make: Leaving directory '/tmp/pip-install-4XeoOx/bluepy/bluepy'
[main]         ----------------------------------------
[main]     Command "/usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-4XeoOx/bluepy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n',
'\n');f.close();exec(compile(code, __file__, 'exec'))" install --reco rd /tmp/pip-record-SJWK6g/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-4XeoOx/bluepy/                                                                                                                        
[main]
[main]     You are using pip version 10.0.1, however version 18.1 is available.
[main]     You should consider upgrading via the 'pip install --upgrade pip' command.
[main]
[main]     Removing intermediate container 38143235bd8c
[main]     The command '/bin/sh -c apk add       bluez       g++       glib-dev       make       py-setuptools && pip install --no-cache-dir       airthingswave-mqtt==${AIRTHINGSWAVE_VERSION}       PyYAML  && wget airthings.com/tech/find_wave.py  && find /usr/local        \( -type d -a -name test -o -name tests \)
-o \( -type f -a -name '*.pyc' -o -name '*.pyo' \)       -exec rm -rf '{}' +  && apk del       g++       glib-dev
make       py-setuptools' returned a non-zero code: 1                                                
[Info]     Uploading images
[Success]  Successfully uploaded images
[Error]    Some services failed to build:
[Error]      Service: main
[Error]        Error: The command '/bin/sh -c apk add       bluez       g++       glib-dev       make       py-setuptools  && pip install --no-cache-dir       airthingswave-mqtt==${AIRTHINGSWAVE_VERSION}       PyYAML  && wget airthings.com/tech/find_wave.py  && find /usr /local       \( -type d -a -name test -o -name tests \)       -o \( -type f -a -name '*.pyc' -o -name '*.pyo' \)       -exec rm -rf '{}' +  && apk del       g++       glib-dev       make       py-setuptools' returned a non-zero code: 1
[Error]    Not deploying release.
remote: error: hook declined to update refs/heads/master
To git.balena-cloud.com:grangemd/Airthings-MQTT.git
! [remote rejected] master -> master (hook declined)
error: failed to push some refs to '[email protected]:grangemd/Airthings-MQTT.git'
--

Any advice would be appreciated.

grangemd avatar Dec 16 '18 22:12 grangemd

@renemarc

Sorry i just updated the file as I noticed it was hard to read. I ended up trying a different docker that I wasn't planning on using and it seemed to push correctly so I don't know what is wrong with this one.

grangemd avatar Dec 17 '18 18:12 grangemd

@grangemd: That was a weird bluez compilation bug. Which Pi were you using?

renemarc avatar Dec 17 '18 19:12 renemarc

@renemarc I am using a Raspberry Pi 3 Model B+

grangemd avatar Dec 17 '18 19:12 grangemd

Indeed, I dont have very high hopes that they will somehow open up very much. HeatIt (Norwegian company selling various Z-Wave products) were cooperating with Airthings on a Z-Wave version of the Wave. That was supposed to launch right about now but was cancelled entirely in May. The likelyhood of Airthings being the one to say no is 99%.

If theres no way to get any meaningful data out of this Wave Plus, I have a deal to sell the unit on to a friend who has real issues with radon.

Regarding Airthings Wave Plus: I'm integrating the sensor into my Domoticz, still testing but it seems that it is possible to read meaningful data with RPi from the device. I'll post the BluePy script here is somebody is interested. Need still a b it time to check if the script works ok.

soinipe avatar Dec 18 '18 05:12 soinipe

@renemarc Any thoughts on the bluez compilation bug?

grangemd avatar Dec 18 '18 15:12 grangemd

@renemarc I am trying to follow the readme and I get to the Installation Section. When I enter the line

git push balena master

I end up getting an error

mgranger@Millennium-Falcon MINGW64 /c/git/balena-airthingswave (master)

Forgive my intrusion but are you really trying to compile this under Windows?

hpeyerl avatar Dec 18 '18 16:12 hpeyerl

Yes. Sorry this is new to me. Should i be doing it somewhere else?

grangemd avatar Dec 18 '18 16:12 grangemd

The balena-airthingswave package is for a RaspberryPi3 which is an ARM processor running Linux and Bluez is the Linux Bluetooth stack. Your windows machine is almost sure to be an x86 machine. So, unless you're cross-compiling, you are almost certainly doing the wrong thing.

Based on your comments, your expertise level may not be sufficient to undertake this project. Maybe this isn't the project for you? I'm just a spectator here.

hpeyerl avatar Dec 18 '18 17:12 hpeyerl

Based on your comments, your expertise level may not be sufficient to undertake this project. Maybe this isn't the project for you? I'm just a spectator here.

I agree my knowledge may not be sufficient enough but I am trying to learn.

So I get the image loaded on my raspberry pi then where do I need to run the git commands for installation. Is the done on the pi? Because if I run them from the terminal window within Balena Cloud I get an error

bash: git: command not found

This is why i tried compiling it on a Windows PC but obviously that is wrong as was pointed out

grangemd avatar Dec 18 '18 17:12 grangemd