Nearly 7 years ago I started down a project to use existing oregon scientific weather sensors to collect temperature data throughout our house. The basic idea is that Oregon Scientific weather sensors all communicate unencrypted over 433Mhz wireless. With a receiver you can capture that data yourself and put it into other systems.
4th Generation of the Project
Over the last 7 years, and many iterations, lots has changed
- Switched from heyu to directly talking to the rfxcom port in python
- Moved from running on primary server to running on raspberry pi
- Moved from storing data in mysql to publishing on MQTT bus
- Abandoned the display layer entirely in favor of Home Assistant integration
- Published the project on github and pypi
All of these have made the whole project a much more reasonable scope, and easier to understand what it is doing. So lets dive into some of the reasons for the more major ones.
Giving up on the Display Layer
When this project started the UI for it was a read only set of rrdtool generated graphs. One of the things you realize after a while is that while graphs are nice to understand trends, it’s not enough. Min, Max, Current temperature is important, especially if you are using this information to understand tuning your HVAC system. How much differential is there between 2 points in the house right now. I started to imagine what the interface would have to look like to get all the data I wanted, and that became a giant visualization code base I never could get around to writing. But then along came Home Assistant.
Home Assistant is an open source home automation hub written in python. It already has a UI for displaying temperature sensors.
This also includes a detailed view:
While not perfect, that’s a huge ton of work that I don’t need to do any more. Yay! And better yet, by getting data into Home Assistant, these sensors can be used to trigger other parts of home automation. Even if that’s just sending out an alert because a temperature went over a threshold.
MQTT
Ok, so now I am building a system with no UI, so the next question is how to get the data from this device into Home Assistant. For that I changed the architecture to being basically stateless and publishing data via MQTT.
MQTT is a lightweight message bus standard designed with IoT applications in mind. The protocol is pretty simple, there are multiple brokers that implement it, and there are client libraries for everything you can imagine (including arduino).
The ARWN project now is largely a relay that is blocked on the serial port reading data frames from the weather sensors and immediately publishing them out to MQTT
ribos:# mosquitto_sub -h 10.42.0.3 -t arwn/# -v arwn/totals/rain {"bat": 9, "sensor_id": "96:00", "timestamp": 1484110832, "rate": 0.0, "sig": 7, "units": "in", "total": 25.49} arwn/status {"status": "alive", "timestamp": 1483883801} arwn/temperature/Arwen Room {"bat": 9, "sensor_id": "ce:08", "sig": 6, "temp": 67.8, "dewpoint": 41.3, "timestamp": 1484235988, "units": "F", "humid": 38.0} arwn/temperature/Bomb Shelter {"bat": 9, "sensor_id": "e3:02", "sig": 5, "temp": 44.8, "dewpoint": 22.0, "timestamp": 1484235991, "units": "F", "humid": 40.0} arwn/temperature/Outside {"bat": 9, "sensor_id": "ec:01", "sig": 6, "temp": 51.6, "dewpoint": 51.1, "timestamp": 1484235994, "units": "F", "humid": 98.0} arwn/rain {"bat": 9, "sensor_id": "96:00", "sig": 6, "units": "in", "timestamp": 1484235994, "total": 26.07, "rate": 0.0} arwn/rain/today {"timestamp": 1484235994, "since_midnight": 0.5800000000000018} arwn/temperature/Freezer {"bat": 9, "sensor_id": "a9:04", "sig": 4, "temp": -5.1, "dewpoint": -32.5, "timestamp": 1484235996, "units": "F", "humid": 24.0} arwn/wind {"bat": 9, "sensor_id": "33:00", "sig": 5, "timestamp": 1484235998, "units": "mph", "gust": 0.0, "speed": 0.0, "direction": 157} arwn/temperature/Garage {"bat": 9, "sensor_id": "e9:04", "sig": 7, "temp": 52.9, "dewpoint": 10.6, "timestamp": 1484236000, "units": "F", "humid": 18.0} arwn/wind {"bat": 9, "sensor_id": "33:00", "sig": 5, "timestamp": 1484236012, "units": "mph", "gust": 0.0, "speed": 0.0, "direction": 157} arwn/barometer {"pressure": 1012, "bat": 9, "sensor_id": "f6:00", "sig": 6, "units": "mbar", "timestamp": 1484236013} arwn/temperature/Refrigerator {"bat": 9, "sensor_id": "f6:00", "sig": 6, "temp": 36.3, "dewpoint": 7.9, "timestamp": 1484236013, "units": "F", "humid": 30.0}
You can think of MQTT as a key / value bus. You publish on a topic, like ‘arwn/temperature/Refrigerator’ with an arbitrary payload. In my case I’m sending a json blob with all the relevant sensor data, as well as a timestamp. There is no timestamping inherent in MQTT, so if you care about when an event showed up, you have to insert the timestamp yourself in the payload.
I picked MQTT because Home Assistant already had very good support for it (while the primary message bus remains a python internal one, MQTT is strongly integrated in the project). Other open source projects like OpenHAB use MQTT as their primary bus. Bus architectures aren’t a new thing, but the growth of the IoT space is making them even more relevant today.
There is code in Home Assistant now that will discover that that you’ve got ARWN running, and dynamically represent all the sensors it finds.
Even Better Dashboards
Home Assistant is limited by what it can store and what it can display. Fortunately it also can pump the data on it’s bus into other systems as well. This include graphite and grafana.
Those are SVG by default and fully interactive, so you can mouse over points and get dropdowns about all the data at those points. It can be exported to PNG files as well.
Going forward
Since I started this project, there has been a whole revolution in software defined radio. For this project to be useful to people other than myself, the next step is to be able to pull the 433Mhz off an SDR (which runs $20) instead of the rfxcom (which is about $120).
There are definitely pieces of Home Assistant integration to make better. One of which is to expose the rain data in Home Assistant at all. The other is a UX element to build a better way to visualize current wind / temp / rain in Home Assistant. That would be a new polymer component, which I haven’t yet had time to dive into.
It’s also been hugely valuable in the recent insulation work we got done, as I’ve got some data showing how effectively it changed the dynamics of the upstairs.
If you are interested in learning more, leave a comment/question, or checkout the code on github.