I have an automation set to warn us by phone notification (and turns on a light at home) if our indoor cameras detect a person while we are out.
My automation code is naive, and I feel sure that rather than all the repeated code I could simplify it and use a template to add the camera name as a variable, but I can’t work out how to achieve this.
Any help gratefully received.
Here is my code:
alias: Frigate Motion Detection Inside
description: ""
triggers:
- trigger: state
entity_id:
- binary_sensor.lounge_person_occupancy
from: "off"
to: "on"
for:
hours: 0
minutes: 0
seconds: 10
id: Lounge Motion Detected
- trigger: state
entity_id:
- binary_sensor.kitchen_person_occupancy
from: "off"
to: "on"
for:
hours: 0
minutes: 0
seconds: 10
id: Kitchen Motion Detected
- trigger: state
entity_id:
- binary_sensor.office_person_occupancy
from: "off"
to: "on"
for:
hours: 0
minutes: 0
seconds: 10
id: Office Motion Detected
- trigger: state
entity_id:
- binary_sensor.lounge_person_occupancy
from: "on"
to: "off"
for:
hours: 0
minutes: 0
seconds: 30
id: Lounge Motion Cleared
- trigger: state
entity_id:
- binary_sensor.kitchen_person_occupancy
from: "on"
to: "off"
for:
hours: 0
minutes: 0
seconds: 30
id: Kitchen Motion Cleared
- trigger: state
entity_id:
- binary_sensor.office_person_occupancy
from: "on"
to: "off"
for:
hours: 0
minutes: 0
seconds: 30
id: Office Motion Cleared
conditions:
- condition: state
state: "off"
entity_id: input_boolean.someone_home
actions:
- parallel:
- choose:
- conditions:
- condition: trigger
id:
- Lounge Motion Detected
- Kitchen Motion Detected
- Office Motion Detected
sequence:
- type: turn_on
device_id: 2e9c07d975f9ad0e9fe72adb31f5630c
entity_id: a3604aa3c5225fc269502782663f535d
domain: light
enabled: true
brightness_pct: 100
- conditions:
- condition: trigger
id:
- Lounge Motion Cleared
- Kitchen Motion Cleared
- Office Motion Cleared
sequence:
- type: turn_off
device_id: 2e9c07d975f9ad0e9fe72adb31f5630c
entity_id: a3604aa3c5225fc269502782663f535d
domain: light
- if:
- condition: trigger
id:
- Lounge Motion Detected
then:
- parallel:
- action: notify.mobile_app_phone_a
data:
message: Person detected in living room
- action: notify.mobile_app_phone_b
data:
message: Person detected in living room
- if:
- condition: trigger
id:
- Kitchen Motion Detected
then:
- parallel:
- action: notify.mobile_app_phone_a
data:
message: Person detected in kitchen
- action: notify.mobile_app_phone_b
data:
message: Person detected in kitchen
- if:
- condition: trigger
id:
- Office Motion Detected
then:
- parallel:
- action: notify.mobile_app_phone_a
data:
message: Person detected in office
- action: notify.mobile_app_phone_b
data:
message: Person detected in office
mode: single