I now have this working very well, my code is not perfect but hopefully it helps someone!.
I have several cameras with a meaningful name ie Frontdoor or Gate. and wanted a way to send notifications to my phone. i also wanted to be able to change some settings for each camera as to weather it will take my phone off silent before sending the alert, and be able to silence each camera individually or have a timer so i dont forget to turn it back on.
The cameras I use for the motion detection come from a MQTT message from an app called AITool that uses deepstack to analyse the images from blue iris. the scope of this is beyond this post, but any camera should work.
Each camera has a few associated entities (using my Frontdoor camera as an example)
camera.Frontdoor - the camera
binary_sensor.Frontdoor_motion - the motion detection signal (from blueiris)
I created some helpers for these automations too, each camera has
timer.Frontdoor_motion_snooze - the timer for snoozing notifications
input_boolean.Frontdoor_motion_enabled - send notifications for this camera
input_boolean.Frontdoor_motion_unmute - take phone off silent before sending notification
input_number.Frontdoor_motion_snooze_time - a slider which starts the snooze timer for that camera
and a couple of global timers
input_number.motion_global_snooze_time
timer.motion_global_snooze
timer.motion_notification_rate
The main automation, with PHONEID and device ID removedā¦ update with your own.
alias: Motion Detection All Camera
description: 'Automation to send notifications for movement detected on security cameras'
trigger:
- platform: state
entity_id:
- input_boolean.test_motion
- binary_sensor.camera1_motion
- binary_sensor.camera2_motion
- binary_sensor.camera3_motion
- binary_sensor.camera4_motion
- binary_sensor.camera5_motion
- binary_sensor.camera6_motion
- binary_sensor.camera7_motion
- binary_sensor.camera8_motion
to: 'on'
condition:
- condition: and
conditions:
- condition: state
entity_id: timer.motion_notification_rate
state: idle
- condition: state
entity_id: timer.motion_global_snooze
state: idle
- condition: template
value_template: {{ is_state('input_boolean.' ~trigger.to_state.object_id~'_enabled', 'on') }}
- condition: template
value_template: {{ is_state('timer.' ~trigger.to_state.object_id~'_snooze', 'idle') }}
action:
- choose:
- conditions:
- condition: and
conditions:
- condition: state
entity_id: sensor.PHONEID_ringer_mode
state: silent
- condition: template
value_template: {{ is_state('input_boolean.' ~trigger.to_state.object_id~'_unmute', 'on') }}
sequence:
- device_id: b6eca04cfb7a63e5e1daxxxxxxxxxxx
domain: mobile_app
type: notify
title: normal
message: command_ringer_mode
default: []
- service: notify.mobile_app_phoneXX
data:
message: '{{trigger.to_state.name[:-7]}} Camera'
title: Motion Alarm
data:
color: red
channel: MotionDetect
ttl: 0
importance: high
priority: high
vibrationPattern: '100, 1000, 100, 1000, 100, 250, 1000, 250 '
clickAction: /lovelace/motion-sensors
actions:
- action: alarm
title: Alarm!
- action: URI
title: Snooze all cameras
uri: entityId:input_number.motion_global_snooze_time
- action: URI
title: Snooze this camera
uri: {{ 'entityId:input_number.' ~trigger.to_state.object_id~'_snooze_time' }}
image: /api/camera_proxy/camera.{{trigger.to_state.object_id}}
- service: timer.start
data:
duration: '00:01:00'
target:
entity_id: timer.motion_notification_rate
mode: single
One thing i searched for and couldnāt find was a nice way to adjust/start a timer from and input sliderā¦ so I made this automation to do just that
alias: Motion Slider moved
description: 'automation to start a timer when a slider is moved. '
trigger:
- platform: state
entity_id:
- input_number.test_motion_snooze_time
- input_number.camera1_motion_snooze_time
- input_number.camera2_motion_snooze_time
- input_number.camera3_motion_snooze_time
- input_number.camera4_motion_snooze_time
- input_number.camera5_motion_snooze_time
- input_number.camera6_motion_snooze_time
- input_number.camera7_motion_snooze_time
- input_number.camera8_motion_snooze_time
- input_number.motion_global_snooze_time
condition: []
action:
- service: timer.start
data:
duration: 00:{{ states(trigger.entity_id)| int }}:00
target:
entity_id: {{ 'timer.' ~trigger.to_state.object_id[:-12]~'_snooze' }}
mode: single
If you look at the actionable notification in the main automation, it opens up the snooze slider for that camera, or the global one. the alarm triggers an alarm script
i also have some scripts to mute/unmute all cameras and have these set as quick access tiles on my phone
mute_camera_12h:
sequence:
- service: timer.start
data:
duration: '12:00:00'
target:
entity_id:
- timer.motion_global_snooze
mode: single
alias: Mute Camera 12h
icon: mdi:cctv-off
unmute_cameras:
alias: UnMute Cameras
sequence:
- service: timer.finish
target:
entity_id:
- timer.camera1_motion_snooze
- timer.camera2_motion_snooze
- timer.camera3_motion_snooze
- timer.camera4_motion_snooze
- timer.camera5_motion_snooze
- timer.camera6_motion_snooze
- timer.camera7_motion_snooze
- timer.camera8_motion_snooze
- timer.motion_notification_rate
- timer.motion_global_snooze
- timer.test_motion_snooze
mode: single
icon: mdi:cctv