This post describes how to use Homebridge and Home Assistant to extend Apple HomeKit to enable it to support complex automations using motion sensors and switches. These automations create powerful solutions to address security and safety problems in the home.
No single vendor provides a completely automated solution for smart lighting
I have been looking for a way to further automate some smart lighting I have installed in our home. I currently have a couple of table lamps, one in the hall and one on the landing, that are programmed to come on at sunset and go off at the time we normally go to bed. I currently use Belkin Wemo Switches for this purpose and their built-in software to schedule the switching on and off. However, I would like some more flexibility in how I program the switches and ideally I would like to be able to trigger the lights with motion sensors in the middle of the night.
A typical smart lighting use case
My requirement looks like this:
- Hall and Landing lights to on come at sunset and switch off at bed time.
- Hall light to come on for 5-10 mins when someone gets up in the middle of the night to go to the bathroom.
- Hall Light to come on, and stay on, if someone gets up early (before 4.30am) to go to work.
- Hall and Landing lights to be turned off at sunrise (always after 4.30am where I live!)..
Ideally I would like to put this together using Apple HomeKit compatible devices, as eventually I want to be able to trigger lights according to the location of our iPhones. Unfortunately, HomeKit isn’t flexible enough to address this requirement, yet, nor the requirement above. It also doesn’t support the types and makes of smart devices I already own – Belkin Wemo, T-Link HS100, Logitech Harmony Hub and Ring Video Doorbell 2. Again I’m hopeful that this will be resolved soon now that Apple is offering HomeKit software certification rather imposing a hardware certification process on the vendors.
How do I connect non-HomeKit certified devices to HomeKit?
I have experimented with Homebridge, an open source project which provides “HomeKit support for the impatient”. Homebridge allows me to connect devices which haven’t got HomeKit certification yet, such as Belkin Wemo and TP-Link HS100 switches, and control them using the HomeKit Home App on my iPhone or iPad. Unfortunately, Homebridge has lost some momentum recently and some of the plugins I tried weren’t very robust. For example, the Hive Thermostat and Logitech Harmony Hub plugins both fell short. However, it does work OK for my Wemo and TP-Link switches.
How do I create the automations I need?
Homebridge answers some of the connectivity issues but none of the automation issues. For that I use Home Assistant, an open-source home automation platform. Home Assistant is well maintained and has plugin “components” for around 750 of the most commonly used smart technologies, including Amazon Echo, Belkin Wemo, Hue, Logitech Harmony, Nest, Ring and Sonos as well as some less commonly used ones. It also has a very rich scripting capability for programming automations based on triggers, conditions and actions. Home Assistant doesn’t have any native integration with HomeKit, but through a plugin to Homebridge you can easily connect them up. Luckily the Home Assistant plugin to Homebridge appears to be fairly robust.
Using both Homebridge and Home Assistant, and a little configuration of each, I can now see all my smart devices in the Home app on my iPhone. This includes the Elgato Eve Motion Sensor I’ve just bought, which has native HomeKit support.
Connecting Elgato Eve Motion to Home Assistant
Initially it wasn’t obvious how to connect a HomeKit sensor to an automation in Home Assistant without a lot of coding. As Home Assistant can’t see the Eve device you need to create a virtual device in Home Assistant. This can be, for example, an Input Boolean device, that HomeKit can access via Homebridge. You then simply set up an automation in HomeKit that sets the Input Boolean device to “On” when motion is detected by the Eve Motion sensor. Then you can use this virtual device to trigger automations in Home Assistant which in turn switches on or off the required lights.
What does the automation look like?
I decided to do as much of the automation as I could in HomeKit and then do the harder stuff in Home Assistant. Therefore, in the iOS Home app I created the following automations that HomeKit would execute:
- Turn on hall and landing lights at sunset
- Turn off hall and landing lights at 23.00
- Turn off hall and landing lights at sunrise
- When Eve senses motion on the landing after sunset (with before sunrise implied) turn on both the hall light and the Input Boolean device.
I then created the two automations that Home Assistant would execute as follows:
- If Input Boolean device is “On”, set Input Boolean device to “Off”
- After 23.00 and before 04.30, turn off hall light when Input Boolean switch has been “Off” for 10 mins
The automations I have created improve both the security and safety of the household. The lights coming on in the evening make the house look inhabited, even when we’re not there. The lights coming on automatically at night help the occupants to safely see where there are going when they get up in the night to go to the bathroom. It also helps the majority of the household to not be disturbed when one member of the household gets up much earlier than the rest.