Hi there!
I tried to access the current snapshot from a “ring” event, analog to the example in the documentation of the Unifi Protect integration’s motion event.
So I just tried to combine the motion event’s example and the ring event’s example in the documentation, to dynamically grab the snapshot via the proxy url.
I know I could use the camera service to take a picture in the automation, but if I see it right, we could just do it dynamically with the event_id?
Here’s the automation’s YAML:
alias: G4 Doorbell Pro - Es klingelt an der Haustür
description: G4 Doorbell Pro Automation - Es klingelt an der Haustür
triggers:
- event_type: state_changed
event_data:
entity_id: event.g4_doorbell_pro_turklingel
trigger: event
conditions:
- condition: template
value_template: |
{{ 'ring' in trigger.event.data.new_state.attributes.event_types }}
actions:
- data:
message: Es klingelt an der Haustür!
data:
image: >-
/api/unifiprotect/thumbnail/{{ config_entry_id(trigger.entity_id)
}}/{{ trigger.from_state.attributes.event_id }}
title: Haustür
action: notify.notify
But I can’t find the right object in this context to use to get the event_id… any help would be appreciated!
Thanks in advance
I have a very similar automation setup that works well. I’ve noticed in mine that I’m using the trigger.to_state
whereas you’re using the trigger.from_state
, this might be the cause of it.
Thank you for chiming in, but {{ trigger.from_state.attributes.event_id }}
was just copied from the documentation’s example.
The trigger object’s dict doesn’t contain from_state or to_state at this point. → UndefinedError: 'dict object' has no attribute 'to_state'
Is there a way I can inspect the objects during runtime and see if and where a property is?
Thanks!
You can see these values in the trace history of when the automation runs.
Good hint! I actually didn’t know you can just map it to the object from the trace.
image: >-
/api/unifiprotect/thumbnail/{{
config_entry_id(trigger.event.data.new_state.entity_id)
}}/{{ trigger.event.data.new_state.attributes.event_id }}
Changed it to that and now I got my URL working and the snapshot is taken 
Now I got a new challenge 
When a package detection event occurs, I want to send the thumbnail from the video/snapshot where the package was detected.
I used the example for motion detection from the documentation, modified it so the package detection event is used and everything works… EXCEPT that the video and the snapshot which is sent with the notification, is the one from the forward facing camera and not the one from the downward facing camera.
What I would like in the end is the video from the forward facing camera and the snapshot from the downward facing camera.
In the media browser the video and its thumbnail is exactly shown as I would like it to be in the notification.
So here’s the automation (even if it’s pretty much clear how it currently looks)
alias: G4 Doorbell Pro - Paketbenachrichtigung
description: >-
Schickt eine Benachrichtigung mit Bild und Video wenn ein Paket vor der Tür
abgelegt wird
triggers:
- entity_id:
- binary_sensor.g4_doorbell_pro_package_detected
trigger: state
from: "on"
to: "off"
actions:
- data:
message: Ein Paket liegt vor der Haustür!
data:
image: >-
/api/unifiprotect/thumbnail/{{ config_entry_id(trigger.entity_id)
}}/{{ trigger.from_state.attributes.event_id }}
video: >-
/api/unifiprotect/video/{{ config_entry_id(trigger.entity_id) }}/{{
trigger.from_state.attributes.event_id }}
title: Haustür
action: notify.notify
mode: single
max_exceeded: silent