Use Homebridge to connect Apple Homekit to Alexa and others by Jeremy Chan | Do-It-Yourself Home Automation | March 2021

Cupertino, March 11, 2021

You can control Alexa Routine through Homekit with a few simple solutions

Photo by Andres Urena on Unsplash

Ideally, when setting up your smart home, you want to get all your devices in one ecosystem (e.g., Apple HomeKit, Google Home, Alexa, SmartThings).

Your smart devices are like employees of a company. The company works best when all your employees are under the same boss and can work with each other. If you're mixing devices that only work with certain particular hubs or have limited functionality when they're not connected to your preferred hub, you'll need to find a way for different bosses to work with each other.

In my case, I invested in putting Alexa in every room so naturally that I tried to stay as long as possible in my smart devices at home.

Recently I received some very cheap GU10 Wi-Fi smart bulbs (at 5 GBP per bulb) that I put in the hallway. Like many generic smart bulbs in China, they are connected via the Smart Life app and can be controlled by Alexa through an ability. I set up an Alexa routine to turn on the lights an hour before sunset and turn off all the lights when I say good night. Perfect.

However, it remains a problem.

When no one is home, can we turn off the lights automatically? Can we restart them when any of us return?

Because my partner and I are both iPhone users and always have our phones with us when we leave home, the obvious solution would be to use some sort of geofence trigger - for example, trigger an Alexa routine to turn off the lights when the location ours is not Not close to home.

Unfortunately, the location is not available as a routine trigger for Alexa in the UK (no idea why). What now?

Approach 1: Create automation in the Smart Life application.

The Smart Life app that my lights use supports the creation of location automation as a trigger. However, this requires always allowing the app access to the iOS location and I'm worried about battery involvement.

More importantly, the Smart Life app only supports the use of a single device as a shutter, imagine if the lights go out for my partner when I go for a run outside.

Approach 2: Samsung SmartThings Hub

With some online research, it seems that SmartThings accepts both "no one is home" and "everyone is home" triggers. Moreover, SmartThings can create a "virtual sensor" that can then be used to trigger an Alexa routine. I could build a switch in SmartThings that switches depending on whether there are people at home and run the rest of the logic in Alexa.

It looks good, but I don't intend to invest in SmartThings.

Approach 3: Apple HomeKit comes to the rescue 💪

Triggers for Apple Home Automation

Similar to SmartThings, the Home app supports triggers using device locations. He is also aware of who is in your household and can tell the difference between "Anyone leaving" and "Last person leaving". This is great, I can expect it to work well on iOS as it is officially maintained. Apple Home requires a hub, but I can only use my iPad for that.

Automation logic:

  1. When someone gets home + after sunset -> Turn on the lights

However, as I said at the beginning, my lights are not supported HomeKit, so although I have my triggers, I have nothing to control from the Home app!

In short, Homebridge is simply a NodeJS server that you can run on a machine on your home network to emulate the HomeKit API. It is typically used to connect devices that do not implement the HomeKit protocol in the Apple Home ecosystem. Many people have contributed plugins to support various devices from Nest, IKEA, Logitech, etc.

I host homebridge on a Raspberry Pi, but you can run it on Windows, Mac and Linux. See this page for setup instructions.

One approach to solving my problem is to control my lights in the Home application. Since my lights are all in Smart Life (Tuya), I can use the homebridge-tuya plugin for that. However, I prefer to use Alexa routines as much as possible for automation. We can do this using the homebridge-alexa and homebridge-delay-switch plugins.

Triggering the Alexa routine in the HomeKit

We will use two homebridge plugins: homebridge-alexa and homebridge-delay-switch.

  • homebridge-alexa: allows Alexa to discover and control homebridge devices. In our case, we need Alexa to discover the fake motion sensor created by homebridge-delay-switch

I don't know exactly why, but Alexa doesn't accept the virtual homebridge switch as a routine trigger. homebridge-delay-switch provides a solution by coupling the switch with a motion sensor, which Alexa can use to trigger a routine.

Let's take as an example "When the last person leaves -> Turn off the lights", we will have to:

Step 1: In the homebridge setup, make sure routine is set to true in the platform section. This will allow homebridge devices to trigger Alexa routines.

Step 2: Create a virtual switch + virtual motion sensor homebridge-delay-switch, configure the virtual switch to stop and trigger the motion sensor after 100ms

Step 3: In the Apple Home app, create an automation to turn on the virtual switch when the last person leaves home

Step 4: In Alexa, create a routine, with the trigger "when motion is detected by the virtual motion sensor", turn off the lights

Test automation in the Apple Home app. Everything works as expected, although there is a 1-2 second delay due to the numerous network breaks in HomeKit + homebridge + Alexa + Smart Life + Wi-Fi.

I also tested the sensitivity of the HomeKit geofence trigger by asking Alexa to send me a notification when the routine starts. I got a notification when I was about 100 meters from the house, well enough.

Although it is quite boastful, I am happy with the way it worked!

Best selling & Top trending HomeKit product in our shop at this moment

HomeKit.Blog is in no way affiliated with or endorsed by Apple Inc. or Apple related subsidiaries.

All images, videos and logos are the copyright of the respective rights holders, and this website does not claim ownership or copyright of the aforementioned.

All information about products mentioned on this site has been collected in good faith. However, the information relating to them, may not be 100% accurate, as we only rely on the information we are able to gather from the companies themselves or the resellers who stock these products, and therefore cannot be held responsible for any inaccuracies arising from the aforementioned sources, or any subsequent changes that are made that we have not been made aware of.

HomeKit.Blog Is A Participant In The Amazon Services LLC Associates Program, An Affiliate Advertising Program Designed To Provide A Means For Sites To Earn Advertising Fees By Advertising And Linking To Amazon Store (Amazon.com, Or Endless.com, MYHABIT.com, SmallParts.com, Or AmazonWireless.com).

The opinions expressed on this website by our contributors do not necessarily represent the views of the website owners. 

Copyright © 2022 HomeKit Blog
. All rights reserved
United States