Triggering and sorting timer event detail in automation

For a while now, I have had several automations written and working around being able to temporarily disable my security camera array. For example, if we wanted to work out in the yard for a few hours, we’d select the 2hr sleep. It kicks off a timer and when the timer expires it turns them back on. It’s been on my to-do list to take advantage of the choose: option added to the automation capabilities recently and combine the 4-5 automations handling this temporary disable into one.

Since the holidays are here, I decided to try to tackle it and it’s going very well. I ran into a snag when trying to combine the notification messaging into the massive automation block. Simply, I cannot figure out how to really take advantage of the event object that comes back so I can include it properly inside my conditions statement.

I have my choose set up generically matching platform == 'event' and the default case falls through and it will create a persistent notification with the trigger, trigger.event and trigger.event.data so I can see what it looks like:

Trigger:{'platform': 'event', 'event': <Event timer.finished[L]: entity_id=timer.zm_cameras_timer>, 'description': "event 'timer.finished'"}
Event:<Event timer.finished[L]: entity_id=timer.zm_cameras_timer>
Data:{"entity_id": "timer.zm_cameras_timer"}

I’d like to take test for timer.finished inside the condition: template below but not sure how to go about doing that. Clearly, the ‘event’ is a timer object but I don’t know how to address it since it’s not json. :upside_down_face: how?

          - conditions:
              - condition: template
                value_template: "{{ trigger.platform == 'event' }}"
            sequence:
              - service: input_select.select_option
                data:
                  entity_id: input_select.zm_disable_select
                  option: Cameras on
              - service: notify.group_everything
                data:
                  message: "Camera timer has expired, cameras are back on"
                  title: Camera timer
                  data:
                    tag: camera_alert
                    priority: normal
                    importance: default
                    actions:
                      - action: cameras_off_5mins
                        title: +5min
                      - action: cameras_off_1hr
                        title: +1hr

I just found this thread from @petro where he mentioned using trigger.event.as_dict() which I had never seen before so I tried it on my persistent notification.

It gave me this:

Trigger:{'platform': 'event', 'event': <Event timer.finished[L]: entity_id=timer.zm_cameras_timer>, 'description': "event 'timer.finished'"}
Event:{"context": {"id": "2845acdac82e5c7e6d7611f618327683", "parent_id": null, "user_id": null}, "data": {"entity_id": "timer.zm_cameras_timer"}, "event_type": "timer.finished", "origin": "LOCAL", "time_fired": "2020-12-27T06:51:47.001008+00:00"}
Data:{"entity_id": "timer.zm_cameras_timer"}

And that led me to use:

          - conditions:
              - condition: template
                value_template: "{{ trigger.platform == 'event' and trigger.event.as_dict()['event_type'] == 'timer.finished' }}"

Works like a charm but I wonder if there’s any better ways to use the trigger.event object…

I’m not sure if the as_dict is needed. I would expect it to work without it using dot notation.

{{ trigger.platform == 'event' and trigger.event.event_type == 'timer.finished' }}

You’re right! Thanks @petro! What’s the best way to know what options are available for all the different types of objects? I’ve been referencing this page that describes some generic stuff but where can I find the various options with a given event?

Thank you!