- alias: "Snapshot garage and send photo when motion detected"
trigger:
- platform: state
entity_id: binary_sensor.garage_exterior_door
from: 'off'
to: 'on'
action:
- service: aarlo.camera_request_snapshot_to_file
data:
entity_id: camera.aarlo_garage
filename: '/config/www/cameras/garage_latest.jpg'
- wait_for_trigger:
- platform: event
event_type: aarlo_image_updated
timeout: "00:01:00"
- service: notify.mobile_app_andrew_phone
data:
message: "Motion in garage!"
data:
image: !secret garage_image_url
I have this automation in place and when I watch the event bus I see the aarlo_image_updated event pass by (and also see it in dev tools listener) but my automation only continues after timeout instead of after the event as Iād expect.
- id: '1602677251779'
alias: wait for trigger test aneisch
description: ''
trigger:
- platform: state
entity_id: input_boolean.wait_for_trigger
to: 'on'
condition: []
action:
- service: persistent_notification.create
data_template:
message: Triggered at {{ as_timestamp(now()) | timestamp_custom("%I:%M %p")
}}
- wait_for_trigger:
- platform: event
event_type: aarlo_image_updated
timeout: '00:01:00'
- service: persistent_notification.create
data_template:
message: Wait for trigger at {{ as_timestamp(now()) | timestamp_custom("%I:%M
%p") }}
mode: single
I also notice that this automation will not wait for a trigger if you fire it again inside the 1 minute timeout. If you want it to reset, you need to change it to mode: restart
So to recap:
Verify that your event_type is actually called aarlo_image_updated.
Change mode: restart so that it can fire more than once per minute.
if the event_type is correct, then heās running into the āsingleā automation waiting the full minute before triggering again āissueā. Which is not an issue, itās just how single mode works.
You got me thinking that might be the culprit but your test example used single mode and wait_for_trigger was successful. Interesting problem we have here.
Either way, the event_type appears to be the name of the event seen in the logs. I think we need @aneisch to subscribe to the event on the events page.
FWIW, iāve seen this ārestartā trip up alot of people when it comes to wait_for_trigger. It acts the same way as delay. Itās basically waiting for a trigger or the timeout before the automation can be fired again.
A scriptās default mode is single. Just for fun, set it to parallel. I doubt it will improve anything but letās try it to, if for no other reason, eliminate it as a potential factor.
Good, because it shouldnāt have influenced the automationās behavior in this particular case.
Bad, because now Iām not sure where else to look.
EDIT
What I find interesting is that the first service call is at 08:45:21 but wait_for_trigger gives up waiting at 08:45:31. Thatās not a minute, thatās 10 seconds.
Looking at your debug messages, it appears as if the event is occurring before the wait trigger is starting or itās occurring exactly when itās starting.
At 08:45:21 the call to take the snapshot is made, at 08:45:26 the event fires letting us know that the snapshot has completed. At that time I expect that the automation will continue and close out.
08:45:21 <automation_triggered: name=Snapshot garage and send photo when motion detected, entity_id=automation.snapshot_garage_and_send_photo_when_motion_detected>
08:45:21 <call_service: domain=aarlo, service=camera_request_snapshot_to_file, service_data=entity_id=camera.aarlo_garage, filename=/config/www/cameras/garage_latest.jpg>
08:45:26 <aarlo_snapshot_updated: entity_id=aarlo.garage>
08:45:26 <aarlo_image_updated: entity_id=aarlo.garage>
08:45:26 <aarlo_snapshot_ready: entity_id=camera.aarlo_garage, file=/config/www/cameras/garage_latest.jpg>
08:45:31 Service did not complete before timeout: <ServiceCall automation.trigger (c:80e7864d0e2311ebaef9859348d55c06): entity_id=['automation.snapshot_garage_and_send_photo_when_motion_detected'], skip_condition=True, variables=>
08:46:26 <call_service: domain=notify, service=mobile_app_andrew_phone, service_data=message=Motion in garage!, data=image=https://FQDN/local/cameras/garage_latest.jpg>
08:46:27 <state_changed: entity_id=automation.snapshot_garage_and_send_photo_when_motion_detected, old_state=<state automation.snapshot_garage_and_send_photo_when_motion_detected=on; last_triggered=2020-10-14T08:45:21.425626-05:00, mode=single, current=1, friendly_name=Snapshot garage and send photo when motion detected @ 2020-10-13T22:18:11.191407-05:00>, new_state=<state automation.snapshot_garage_and_send_photo_when_motion_detected=on; last_triggered=2020-10-14T08:45:21.425626-05:00, mode=single, current=0, friendly_name=Snapshot garage and send photo when motion detected @ 2020-10-13T22:18:11.191407-05:00>>
Thereās something peculiar about the timestamps. The timestamp for āService did not completeā ought to be closer (in time) to the end of the actionās execution yet it occurs (08:45:31) almost a full minute before the last reported message (08:46:27).
Yes I agree, let me run a test. I think I have an idea of whatās going on
EDIT: Iām not getting this to occur
08:45:31 Service did not complete before timeout: <ServiceCall automation.trigger (c:80e7864d0e2311ebaef9859348d55c06): entity_id=['automation.snapshot_garage_and_send_photo_when_motion_detected'], skip_condition=True, variables=>
- alias: "Snapshot garage and send photo when motion detected"
trigger:
- platform: state
entity_id: binary_sensor.garage_exterior_door
from: 'off'
to: 'on'
action:
- service: script.take_snapshot
- wait_for_trigger:
- platform: event
event_type: aarlo_image_updated
timeout: "00:01:00"
- service: notify.mobile_app_andrew_phone
data:
message: "Motion in garage!"
data:
image: !secret garage_image_url
I think whatās happening is that the service is finishing exactly when the wait is starting and the event is getting lost.
Hopefully this will fire the script and the wait_for_trigger should start prior to the event firing. I think youāll see the timeout error go away too