Cheap IoT with SenseHAT and MQTT
I’ve had a SenseHAT since they came out. Much like my first Raspberry Pi, I bought it with no real vision of what I’d use it for, and it’s been sat in the box for literally years.
Since the pandemic, everyone in my house has been working from home exclusively. This has meant repurposing various rooms as makeshift office space, installing desks, network points, etc. One of the big issues has been room temperature; I’ve set up Home Assistant to do some clever thermostat kung-fu throughout the day, using the various temperature sensors around the house at different times of the day to ensure the house is the correct temperature in the place we’re most likely to be at any given time. Problem is, the AEOTEC multi-sensors I have are expensive and all I really want is a decent temperature reading in the various home offices that now exist within the house so that I can keep the temperature comfortable during the work day. The SenseHAT was the obvious candidate.
The AEOTEC sensors I have are Z-wave. They talk to a Z-Way board on a Raspberry Pi, which in turn is running Home Assistant. All they really do is report their temperature every 30 minutes or so. But Home Assistant will also listen to reports sent via an MQTT topic, so all I need is a python script that runs every 30 minutes or so that gets the temperature from the SenseHAT and publishes it to MQTT where Home Assistant can act upon it.
The code is very simple, it’s essentially a single python script (publish.py) that needs to have a configuration file (config.json) within the same directory. Then just call it from cron. It uses quite a few Python libraries, so I’ve included a requirements.txt in the repo as well. But I suggest following some tutorial on setting up the SenseHAT in Python 3 because it’s not straightforward, you’ll need to use apt to install some packages as well. Specifically, when running this on a Raspberry Pi 1 using the latest (2020-08-20) version of Raspberry Pi OS Lite, I needed to install the following packages using apt:
Once the code is installed and running, and you’ve mounted the Pi sonewhere, you can set up a sensor entity in the configuration.yaml as shown on the Home Assistant website