Using Motion Sensor as Occupancy Sensor for HomeKit with Homebridge

Requirements:

  • A HomeKit enabled motion sensor. I use Aqara Motion Sensor
  • A HomeKit enabled accessory to be controlled
  • Homebridge with homebridge-delay-switch plugin installed

Goals:

  • Trigger an open/turn on/start event when motion detected
  • When no motion for specific minutes. Trigger another event to close/turn off/stop

Why? This method no longer depends on the buggy HomeKit built-in “Turn Off” and Stops Detecting Motion feature. Common HomeKit motion sensors only update the motion state every minute. When Stops Detecting Motion triggers. It won’t be canceled or delayed when it detects another motion. That causes your accessory to turn off even it detects motion during the time you set.

With my method. Your accessory won’t be turned off if your motion sensor detects motion during the specific time you set. Make your motion sensor work more like an occupancy sensor.

First. Add a delay switch in Homebridge:

{
    "name": "Living Room Delay Switch",
    "delay": 360000,
    "disableSensor": false,
    "startOnReboot": false,
    "accessory": "DelaySwitch"
},

The delay time is in milliseconds so 360000 equals 6 minutes here.

In your Home app. Create the following automations:

First Automation

  • When: Living Room Motion Sensor – Detects Motion
  • Accessories:
    • Turn on your accessory
    • Turn on your Living Room Delay Switch

Second Automation

  • When: Living Room Delay Switch Trigger – Detects Motion
  • Accessories:
    • Turn off your accessory

Third Automation

This automation is important. It can ensure your accessory can still be turned off at a specific time if the accessory was opened/turned on/started manually.

  • When: Living Room Sensor – Stops Detecting Motion
  • Accessories:
    • Turn on your Living Room Delay Switch

Leave a Reply

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