Hi all,
I have the following automation that I use to get notifications if there is motion around my house to send a push notification to my phone with an image. It works fine, however sometimes the automation triggers before the camera entity picture updates. Because these are Ring cameras I don’t have 24/7 streaming ability so I have to use a snapshot camera which updates on a motion event and also updates every 10 seconds.
alias: '📱🏃🏼Notification: Outside Motion'
description: ''
trigger:
- platform: state
entity_id:
- binary_sensor.backyard_camera_outside_motion
- binary_sensor.driveway_camera_outside_motion
- binary_sensor.front_door_camera_outside_motion
from: 'off'
to: 'on'
condition:
- condition: template
value_template: '{{ trigger.to_state.attributes.personDetected == true }}'
action:
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 300
- service: camera.snapshot
data:
filename: >-
/media/{{ trigger.entity_id.split('.')[1].replace('_outside_motion', '')
}}.jpg
target:
entity_id: >-
camera.{{ trigger.entity_id.split('.')[1].replace('_outside_motion', '')
}}
enabled: true
- service: notify.mobile_app_brians_iphone
data:
message: >-
There is a person at your {{ trigger.from_state.attributes.friendly_name
}}
title: Person Detected
data:
image: >-
/media/local/{{
trigger.entity_id.split('.')[1].replace('_outside_motion', '') }}.jpg
push:
thread-id: motion-notify
actions:
- action: MOTION_OUTSIDE_SNOOZE_30_MIN
title: 'Snooze Notifications: 30 Minutes'
- action: MOTION_OUTSIDE_SNOOZE_1_HOUR
title: 'Snooze Notifications: 1 Hour'
- wait_for_trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: MOTION_OUTSIDE_SNOOZE_30_MIN
- platform: event
event_type: mobile_app_notification_action
event_data:
action: MOTION_OUTSIDE_SNOOZE_1_HOUR
continue_on_timeout: false
timeout: '1:00'
- service: script.1621437264318
data:
snooze_time_mins: >-
{% if wait.trigger.event.data.actionName == MOTION_OUTSIDE_SNOOZE_30_MIN
%} 30 {% elif wait.trigger.event.data.actionName ==
MOTION_OUTSIDE_SNOOZE_1_HOUR %} 60 {% endif %}
automation_name: automation.outside_motion_notification
mode: restart
I’m trying to change it so instead of just sleeping 300 ms, it waits until the entity picture changes, but I can’t figure out the logic for this. I’ve tried the following but HA complains that its not valid.
wait_for_trigger:
- platform: state
entity_id: camera.{{ trigger.entity_id.split('.')[1].replace('_outside_motion', '') }}
attribute: entity_picture
My motion sensors for the cameras are as follows:
- binary_sensor.backyard_camera_outside_motion
- binary_sensor.driveway_camera_outside_motion
- binary_sensor.front_door_camera_outside_motion
The cameras associates with them are as follows:
- camera.backyard_camera_snapshot
- camera.driveway_camera_snapshot
- camera.front_door_camera_snapshot
But when I try to save I get the following error:
Message malformed: Entity [object Object] is neither a valid entity ID nor a valid UUID for dictionary value @ data[‘entity_id’]
Any ideas on how I can wait for the camera associated with the binary sensors entity picture to be updated before continuing with the automation?