Let me begin by saying that I am a newbie when it comes to home automation. During the past few months, I have come across so many tools and devices that I am absolutely fascinated with the potential that home automation projects have. I will start by charting a course in my home automation journey, which isn’t much, but nevertheless, is a good beginning. This is a three part series. In each post, I have tried to focus only on the integration of the systems and have deliberately tried to veer away from information that can be easily followed from other sources. At the same time,I have tried to provide the relevant links for this kind of available information.
Below is a map of the devices I have at home:
Balcony — There are couple of Ikea Trädfri bulbs in the balcony that are connected to a common Trädfri Remote Control. There is also a Trädfri Gateway that enables controlling the lights using Ikea’s Smart Home App. Using the smartphone app, I can set custom timers to turn these lights ON and OFF respectively. However I cannot configure the lights to turn ON automatically at sunset or turn OFF automatically at sunrise.
Top Floor — There is a temperature and humidity sensor in one of the bathrooms. This is a Xiaomi Sensor that uses BLE (Bluetooth Low Energy) to advertise temperature and humidity readings. I can connect to the sensor using Xiaomi’s Mi Home App and see the instantaneous temperature and relative humidity values. However BLE range is quite poor and the smartphone has to be within 5–7 meters to effectively connect to the sensor. Besides, I do not have a BLE Gateway, which means there is no way I can collect and store values from the sensor for a historical view. There is also a Google Home Mini in the hallway that can be used to control the lights in the balcony. But I cannot use Google Assistant to tell me the temperature and humidity values from the Xiaomi sensor.
Basement — There is a Xiaomi temperature and humidity sensor similar to the one on the top floor and it has the same problems as described above.
At one point I was thinking of investing in a BLE-WiFi Gateway that will help solve the problem with the sensors’ data. However these sensors are placed so far apart that I will not be able to use one single gateway to connect to both sensors — reason being the poor range and interference.
Now that the problem statement is clear, it’s perhaps easier to answer the question in title. HASS or Home Assistant is a python based open source tool created and maintained by awesome people. It helps to integrate and manage a huge list of home automation projects including Ikea Trädfri and Xiaomi’s BLE range of devices. It is not quite easy to completely understand HASS and its entities. There is lot of information scattered in the forums and it can be quite overwhelming at the beginning, when you are looking for specific information. However once you have managed the steep learning curve, home automation can get quite exciting!
There are multiple installation options and steps explained here. I chose to put an old laptop to use that could run HASS in a standalone mode. For this I followed the instructions under “Alternative: install on a generic Linux host” at the link above. Dashboard is visible once the installation is completed successfully. HASS Add-On store provides some very useful plugins. I would recommend to install “Configurator”, “Duck-DNS” and “Google Drive Backup”. “Configurator” add-on provides an easy interface to update the different configuration YAML files in HASS. By default HASS snapshots (backups) are stored in the local system and since I was using an old laptop, it seemed logical to push these snapshots to the cloud as well. “Google Drive Backup” add-on serves this purpose. “Duck-DNS” add-on provides a free dynamic DNS service that enables connecting to the HASS server from external networks. This is essential to get Google Assistant Integration working. For our first task, let’s get the Ikea lights to toggle at sunrise and sunset.
Light On @ Sunset / Light Off @ Sunrise
Once HASS installation is successful, most probably the discovery service would have found the Ikea Trädfri Gateway, Remote Control and the Lights connected to this remote control. They should all show up with the same names as configured in the Ikea Smart Home App. In order to toggle the lights based on Sun’s state, we first need to define an entity that tracks local weather conditions. Fortunately HASS comes with a default “Weather” entity, but in my case, this was not showing the local weather conditions. In order to get this working, we first have to configure our location details in HASS. In
(/config/configuration.yaml) add these lines:
latitude: <find from Google Maps>
longitude: <find from Google Maps>
elevation: <find from freemaptools.com>
time_zone: <find from the timezone database>
name: <name for the hass instance>
More details can be found here. Once this is done, restart HASS to reflect the new configuration. Now, the “Weather Card” shows local weather information more accurately.
Once the required entities (lights and weather) are in place, we need to configure an “Automation” that will toggle the lights based on Sun’s state. Follow the breadcrumbs:
HASS → Configuration → Automation → +. On the landing page, there are options to define an automation. For “Trigger” select “Sun” and appropriate event (Sunrise/Sunset). Finally specify the “Actions” to turn on/off the lights. For example to turn off lights at sunrise, action settings would be something like this:
Note that configuration files use YAML syntax. The entity ids for the lights (or any other entities) can be found from:
HASS → Configuration → Entity Registry. A similar automation will be needed to turn on the lights at sunset. Once the configuration is done, save the changes and restart HASS. Here’s a snapshot from the Logbook entries (
HASS → Logbook) when the automation is triggered based on sunrise:
That’s it! For more exotic weather based automation here are more examples.
This solves the problem with the lights in the balcony. In the next post, we will see how HASS can be used to collect and store sensor values from Xiaomi’s BLE based temperature and humidity sensors.