Frustrated by the cost and lack of transparency attached to the majority of consumer IoT devices, I’ve decided to have a go at building my own connected ecosystem powered by Raspberry Pi. After a slow start I’m finally getting comfortable with Python and physical computing, so I need to step up to something a bit more advanced - I’m also inspired by CityVerve, and my work with FutureEverything and artist Naho Matsuda - if anything, it’ll help me keep up!
I maintain healthy skepticism around consumer IoT but I figured that a small, localised system would be a good way to get my head around the basic components at play. Rather than making everything talk to each other, I’m more interested in keeping an eye on things - the effect of outdoor temperature on indoor conditions, for example. I also want to retain control of as much of my data as possible, although improvements are being made on this front - Ikea’s Trådfri bulb system, for example, only calls out to grab the current time and download firmware updates and operates solely on the local network.
I got started when I came across Pimoroni’s tutorial connecting Mote to Apple’s Homekit - it seemed that the code addressing the Mote sticks should also be compatible with Blinkt, so I switched out the library and relevant code to create a Flask API. Very quickly, I could point my browser to a number of API endpoints to switch all on/off all of the LEDs attached to a seperate Pi Zero, as well as change the colour and brightness. The next step was to set up Homebridge on the Pi 3 running the Flask API, to make the Pi discoverable in Homekit. This went relatively smoothly, although the script will crash if the colour or brightness are addressed from Homekit - I’m not too bothered though as this is just a proof of concept and I’ll be working with Mote sticks eventually, I’m happy enough with on/off for this prototype. I’m also confident that this approach can be adapted for any similar output.
From there I started to think what else would be feasible for me to build, and discovered Freeboard.io - a free, super simple visualisation dashboard that connects to a number of data sources. Unfortunately, it only provides data vis, no control; I thought about using Adafruit IO, but the platform’s still in beta and I’ve found it to be a little buggy (but great for getting started with IoT). Freeboard provides default data sources for Weather and Time, and pretty much anything else can be pulled in from Dweet.io - another free service made by the Freeboard devs that acts like Twitter for data (and my new favourite tool).
Using a simple Python wrapper, any data can be pushed to Dweet to be retrieved later (but only for up to 24 hours, so it’s only really useful for live views). After setting up simple Time and Weather widgets, I decided to jump in at the deep end with a widget that would track the next bus from my local stop. Using a database from Transport API, I wrote a script that queries the database for live updates from my stop (using its’ atco code), checks to see which services are running (in my case the 33 and 63), then sends a Dweet with the latest estimated departure time for each live service. If no data is found for one or both services, ‘No busses’ is sent to Dweet.
The final step was to pull the Dweets in to Freeboard, which couldn’t be simpler thanks to their tutorial. I should point out, it took about a day and a half to get the Python script working, and was not as simple as this post might suggest…
So, by this point I’ve connected some remote LEDs to Homekit and I’ve got a separate dashboard to control data. Thanks to Apple’s retirement schedule my iPad 2 is not compatible with Homekit, which means that I won’t be able to schedule actions or scenes that way - I’ll worry about this later. I do want to use the iPad as a central dashboard (connecting to a Pi 3 via RealVNC), so I needed to figure out a way to add some level of control to work with Freeboard’s visualisation.
guizero turned out to be the perfect tool for the job - I created a really quick GUI with buttons that hit my Blinkt API endpoints to turn the LEDs on and off (which is still accessible via Homekit on my phone). It seems fairly simple to extend the GUI beyond this prototype with more buttons and sliders, and it fits next to the browser running Freeboard so this method is ideal for now.
Not content with two methods of addressing the Blinkt Pi Zero, I also threw together a really quick script that hits the API endpoints each time a button is pressed - I’d quite like to embed arcade buttons into surfaces for manual control (particularly for guests), but this might be a bit much.
A few days after drafting this post, I came across Home Assistant which seems to be an even better solution. There’s a huge number of supported integrations, and the app is compatible with iOS 9 so I’ll still be able to use the iPad 2 as a control dashboard. Next, I’ll get to work on setting up Home Assistant on a new SD card and rebuild these prototypes.
- Set up Home Assistant
- Indoor condition monitor with a DHT sensor, photoresistor and noise sensor
- Bookshelf lighting with Mote sticks
- Experiments with Ikea’s Trådfri bulbs (thanks to another Pimoroni tutorial)
- Mock up mounting plates (eventually to be laser cut acrylic)
These processes are covered in far more detail over at the Pimoroni, Freeboard.io and Dweet.io tutorials (links above) - I’ll also be writing up my progress as I develop this further, so do check back.