“Advanced” Home Automations with HomeKit, Eve’s HomeKit app, and Homebridge

From time to time as I’m writing something for another use (I spend an inordinate amount of time updating house planning and house maintenance documents, moreso now that I’ve got a significant investment in “smart” home technologies in the house), I figure “Hey, maybe this’ll be useful for someone else to see!”, so I copy/paste that information (anonymized, of course) so others might use it or find it useful.

This is one of those times. I was writing up some “advanced” home automation. It’s advanced in a couple of ways (beyond what you can do with basic Apple HomeKit and normal Apple HomeKit-compatible home automation devices.

  1. I use Homebridge, which is a Node.js-based platform for integrating non-HomeKit devices and accessories to HomeKit.
  2. I run Homebridge on a Raspberry PI. (And I have some news on that too)
  3. I use Homebridge to create a couple of paired virtual HomeKit devices for automation. (A delay switch and a “motion detector”)
  4. I use Elgato Eve’s HomeKit compatible app to set up automated triggers that are a bit more complicated than you can do in Apple’s HomeKit app. (using Conditions on Automation Rules)

Outside of what I already wrote, let me just say that the news I have on Homebridge running on Raspberry PI is that now, instead of having to install Node.js, npm, and Homebridge on a base Raspberry PI operating system image, you can now just flash your Raspberry PI with a standard image that the Homebridge folks provide. Yay! This makes it a lot easier to get up and running with a standard platform on one of the world’s premier microcomputers, and sort of standardizes the experience for many of us.

How did I find out? My custom build on my Raspberry PI ate it over an upgrade, and since it was so nonstandard I just didn’t feel like rebuilding it, so I grabbed the config.json out of the corrupted build, made sure it was okay, and applied the image to the PI, and put the config.json back in.

Everything worked like a charm – it even preserved the Nest developers’ API setup on the Homebridge end that I was slightly worried I’d have to figure out how to do again.

Anyway, here is the copy/pasted info from the other document I was working on:

Creating Automations

For the easy way to create automations, just use the Home app and set up automation based on triggers and scenes. This will handle most of your needs since triggers are when a detector (like an open/close door or window sensor changes) detects, or a certain time of day (including 15 minute increments around sunrise or sunset), or when people registered to the house (Jen or Mal) come home or leave home.

In two cases, I had to figure out how to do more complex automations, and the answer is in order to do these you have to use a combination of Homebridge and the Eve app on a smartphone or iPad.

I’ll explain them both here in hopes that they’ll be good examples for other future complex automations that either I or you or some expert you retain will use.

Automation: When the sunroom window or the front door are open, set the thermostat to Eco mode. When BOTH the sunroom window AND the front door are closed, turn off Eco mode.

First, know that Eco mode is the right way to turn the thermostat’s heating mode to off or on. With Eco mode enabled, the thermostat only kicks in if the house temperature goes below 60 F. With Eco mode disabled, the thermostat heats at whatever temperature we last set it to. Turning the thermostat off or the heating mode to off actually resets settings so is not ideal.

Here, Homebridge provides the bridge to use the Nest products in conjunction with Homekit standard accessories and parts.

The reason this has to be an advanced automation is that if you just set the open/close sensors independently to control Eco mode, you can have a situation where one is open and one is closed but Eco mode is disabled, so not only are you heating the house but you’re heating the outside too. (This happens if you, for example, open both the door and the window and then only close the door.)

For the advanced automation with Eve, I used Conditions, which are supported in Homekit but are only shown in read only by the Home app, and Eve turns out to be the only app I know of that allows you to set automations that include Conditions. With the Home app, you can only set triggers. But with Eve, you can enable conditions on triggers, so they only evaluate and trigger if someone else is true.

To get the effect I wanted, I need to set up 3 automation rules in Eve:

  1. When Door Or Window Open, Enable Eco Mode
    1. Triggers:
      1. Foyer -> Front Door -> Contact = No
      2. Sunroom -> Window -> Contact = Open
    2. No conditions
    3. Trigger scene: Eco Mode On
  2. When Door Closed, Eco Off, If Sunroom Closed
    1. Trigger:
      1. Foyer -> Front Door -> Contact = Yes
    2. Condition:
      1. Sunroom -> Window -> Contact = Closed
    3. Trigger scene: Eco Mode Off
  3. When Sunroom Closed, Eco Off, if Front Door Closed
    1. Trigger:
      1. Sunroom -> Window -> Contact = Closed
    2. Condition:
      1. Foyer -> Front Door -> Contact = Yes
    3. Trigger scene: Eco Mode Off

This eliminates the problem above, where independent triggers put you in an unwanted state with the Eco Mode disabled but one of the door or window open.

Automation: When the Front Door opens, if the Foyer Light is off, turn it on for 90 seconds.

This is a convenience automation, made possible by Homebridge’s Delay Switch plugin. It’s not vital, but it could be useful for other automations too.

The goal here is to turn the foyer light on if it’s off and we just got home. If it’s already on, we don’t mess with it, which prevents it from turning it off in 90 seconds if it was already on.

Here, Homebridge actually provides this pair of virtual devices, the virtual delay switch and the virtual “motion” sensor. Neither of these actually exist and are only here to help the automation work as intended, by delaying the time between the trigger (the door opening and closing) and the light turning off (after it’s turned on).

This requires a delay switch to be set in Homebridge’s Config file. It’s the section here:

{

“accessory”: “DelaySwitch”,

“name”: “Delay Switch Foyer”,

“disableSensor”: false,

“delay”: 90000

}

(NOTE: if you add any more delay switches to the configuration, BE SUPER CAREFUL TO NOTE AND REPRODUCE COMMAS. The format of the config file is JSON which is notoriously finicky about syntax. A missing comma can break the whole kaboodle.)

Don’t change the “accessory” line. If you make other Delay Switches, you’ll want a different “name” for each one. “delay” is in milliseconds, so 90000 is 90 seconds. Here’s the plugin’s web page. Documentation is right on that page.

To use the Delay Switch and its associated virtual “motion sensor”, you create both in Homebridge, then use it in an automation rule in conjunction with a couple of scenes (so you can control multiple things at once with one triggered action).

Components:

  1. Scene: Foyer Light and Delay Switch On
    1. Foyer Dimmable Hue White:
      1. Power -> On
      2. Brightness -> 100%
    2. Delay Switch Foyer:
      1. Power -> On
  2. Scene: Turn of Foyer Light
    1. Foyer Dimmable Hue White:
      1. Power -> Off
  3. (Automation) Rule: When Front Door Opens, If Foyer Light Off, Turn On Light And Set Delay Switch
    1. Trigger: Foyer -> Front Door -> Contact = No
    2. Condition: Foyer -> Foyer Dimmable Hue White -> Power = Off
    3. Trigger Scene: Foyer Light And Delay Switch On
  4. (Auomation) Rule: When Delay Switch Motion Fires, If Foyer Light On, Turn It Off
    1. Trigger: Foyer -> Delay Switch Foyer Trigger -> Motion = Motion
    2. Condition: Foyer -> Foyer Dimmable Hue White -> Power = On
    3. Trigger Scene: Turn Off Foyer Light

I hope these provide some usable examples for future “advanced” Homekit Home automation.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.