Skip to content

Occupancy delay sensor implementation in Homebridge

While being on a quest of trying to minimise the amount of energy use in my home, I asked myself: Can I disable certain devices when I’ve left my home?

That answer to that question is of course yes. Any occupancy sensor will do that trick. It can either be the default geolocation presence functionality that the Apple Home app provides or a different way of detecting your presence. I myself use the Unifi occupancy sensor which works perfect and can even see me roaming through my house based on connectivity to the various Unifi Accesspoints.

So if the occupancy sensor does not ‘see’ you anymore, you can turn off devices based on automations. But what if that automation is occurring due to a false positive? Or if certain devices should not ‘immediately’ shutdown after you’ve left.

This last scenario is what I wanted to resolve. But while doing my research I found out that I’m actually also solving false positives because of the delay strategy.

I found various solutions that support delaying a trigger:

  • triggering an switch ‘on’ action with a delayed shutdown as supported by the Home app
  • Turn an automation into a Siri Shortcuts and implement a delay action there
  • A plugin named homebridge-occupancy-delay

I’ve tried to setup the delayed trigger using the Home app, but that did not work out in case of the situation when a sensor is already on ‘true’ or on ‘false’ and you try to set it to that value again, reverting that situation using the delay. This strategy only works when a real change is occurring.

Using the second solution, via Siri Shortcuts does work, but it makes your phone or tablet the controlling mechanism instead of your Apple TV or Homepod. Although this might work, it might also fail if your phone is not able to communicate with Homekit anymore while being outside of your home.

That’s why I ended up on researching the homebridge-occupancy-delay plugin. Although that plugin is not very active in development, in my experience it does work perfectly with the new stable release 1.0.0 of Homebridge.

So what I did I do to achieve a delayed trigger, that is reset in case the trigger is canceled before executing the trigger?

Configuration

First install the homebrige-occupancy-delay plugin and add it to the config.json with a slaveCount of 1 and your preferred delay

homebridge config.json configuration of occupancy delay plugin

When you’ve restarted your Homebridge instance you can start configuring 2 scenes necessary to trigger and reset the delay.

Reset countdown scene
A reset scene to enable the countdown clock
Reset countdown scene
A countdown scene that disable the countdown click, which then starts the count down before actually disabling the sensor
Occupancy with scenes configured
Result of scene creation

Create 3 automations

List of needed automations to enable occupancy delay triggering

Create an automation tying the countdown scene to a trigger you’d like, in my case that no occupancy is detected in my house anymore

Create an automation that checks if the occupancy delay sensor is false that should disable the devices you want disabled after the delay

Create an automation tying the reset scene to the trigger you’d like to inverse. This will reset the countdown to zero so the delay sensor will not trigger.

Using this setup I’m able to leave the house during the day, and when all devices that are monitored for occupancy have left the countdown sensor is triggered. If we’re not returning within 15 minutes the devices which just not consume any power anymore are powered down! Works perfect and in case of a false positive, it’s automatically reset to the right state.

Automatic energy saving power achievement unlocked!

3 thoughts on “Occupancy delay sensor implementation in Homebridge”

  1. Thanks for sharing this. I was looking for a simple way to state whether I was home or not (and subsequently turning off some appliances after I left.
    Great and useful tutorial!
    Henri

  2. Have you ever figured out how to change a state for example a thermostat when you are home but want to change the temperature setting/scene when present at a certain time.

    1. That shouldn’t be too hard to configure with the Eve app. Automations configuration in the Eve app more powerful than the standard home app.

Leave a Reply

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