Skip to content

Integrating with Home Assistant

danecreekphotography edited this page Jun 30, 2020 · 4 revisions

Home Assistant is a handy place to collect information about the events happening in your world, including knowledge of when motion is detected by a camera.

MQTT binary sensors provide an easy way to get motion status into Home Assistant from the AI detection system. By default the AI detection system sends a payload that includes {"state": "on"} messages when motion starts and a {"state": "off"} payload 30 seconds after motion stops.

The MQTT binary sensor setup in Home Assistant should look something like this:

platform: "mqtt"
device_class: motion
name: "Front door motion"
state_topic: "aimotion/triggers/FrontDoor"
payload_on: "on"
payload_off: "off"
value_template: "{{value_json.state}}"
json_attributes_topic: "aimotion/triggers/FrontDoor"

Simply replace the state_topic value with the topic specified in your triggers.conf file. The length of time required before the off status is reported can be configured with the offDelay property on the trigger configuration.

With sensors configured in Home Assistant you can now do things like show the motion history of a camera using the Lovelace History graph card or trigger HD camera recording using a NodeRed state_changed node.

A similar binary sensor can let Home Assistant know when the AI system goes offline. Create a new MQTT binary sensor that listens to the state event's online and offline payload:

platform: "mqtt"
device_class: "connectivity"
name: "AI system status"
state_topic: "node-deepstackai-trigger/status"
payload_on: "online"
payload_off: "offline"
value_template: "{{value_json.state}}"
json_attributes_topic: "node-deepstackai-trigger/status"