Homeautomation using Home Assistant
Posted on Fri 16 October 2020 in misc • 3 min read
Early in the summer we had the idea to change the lights on our back porch from various switches inside the garage to something one could control without going anywhere. As I had an old RaspberryPi lying around I ordered a small relay board and installed domoticz to switch the GPIOs.
There were a few downsides: The system is unintuitive with a not so nice interface, the documentation is not the best and I do not know C++. There is also the problem that I had to maintain another operating system and the fact that one should not power off a linux system by disconnecting the power. That poses a problem as one would switch off the power for the whole garden when working on the wiring.
Switching to Home Assistant
I found a much better solution with ESP32 based boards in combination with Home Assistant (using the virtualenv install), which is running on the local RaspberryPi based homeserver. The ESP microcontroller are now running with ESPHome and are connected directly through the ESPHome API to Home Assistant.
After that turned out to be working quite nicely I added two other smart lights which are using an ESP8266 internally and a Sonoff Basic Relais to control another light in the garden. The only problem was that you always needed your smartphone to turn the lights on. It was usually fine in the summer on the porch, but in the winter when one is just doing some short things in the garden it is problematic. I thought about repurposing a switch with an ESP8266 for that task, but in the end I decided to substitute a time switch we had next to our front door with a Sonoff S20. I flashed ESPHome and used homeassistant to do the timed switches while the button on the S20 is now used to switch some garden lights.
Remote 433 MHz sensors
I have also a MQTT broker which is solely used to add 433 MHz based remote
temperature senders to Home Assistant, as these have been around the house for
quite a long time already. This is done with a Realtek DVB-T USB Stick in
combination with rtl_433 and a bridging
script which can be found
here.
The additional script is only needed to add autodiscovery for Home Assistant,
as rtl_433
can publish the values directly to MQTT.
Collecting data from the remote sensors is done via
rtl_433 -R 8 -R 18 -R 75 -R 50 -f 433.92M -f 433.66M -f 433.88M -f 868.33M -H 120 -C si -M newmodel -F mqtt://mqqt.server.local:1883,user=username,pass=password -F kv
Note the specified protocols, you most likely have to adjust them. Limiting the protocols was quite important, as otherwise even tire pressure sensors from passing cars were added to Home Assistant. As I am also using sensors operating at 868 MHz I have to use an 17cm antenna, otherwise the reception is very bad. I am therefore also cycling the used frequencies every 2 minutes (most sensors transmit the signal once every minute.)
As there are 5 sensors in total I used the Min/Max integration from Home Assistant to generate a single value for the outside temperature. As usually some of the sensors are in direct sunlight this value is just the lowest reported. I then generate a 24 hour average using a custom ha-average component to remove the daily cycle.
Power meter
There is now also a ESP8266 based sensor to monitor the power meter. The power meter provided by the local grid operator has three different communication interfaces utilizing infrared LEDs. There is an info interface which provides the total energy in kWh via the SML protocol, but the power meter does not provide the current power (if yours does provide the power, there is a nice firmware by Michael Rüttgers available on Github to process the output and publish the information via MQTT). A bidirectional interface is sealed and requires additional commands via an IR LED.
Luckily there is another interface where the IR LED simply emits 10000 pulses/kWh. I used a BPW 40 phototransistor to register the pulses which are emitted and count them via the ESPHome pulse counter. See here for details, wiring as for the SML reader.