How to include automation triggering device's name in notification message (trigger.to_state.name fails)?

Hello,

I’ve found a few other posts about this that suggest I should use “{{ trigger.to_state.name }}”, but when I do this I get an error:

Error: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘to_state’

My automation has 2 triggers, which are 2 different nest cameras triggering when they detect a person, full automation yaml posted below.

I’m sure I’m just doing something stupid, I’m new to HA. If there are useful reference docs on how to better discover this myself, I’d love that too (I’m poking around in the trace to see what properties exist under trigger, and none in there show the friendly name, just device_id … and I also haven’t found something that would let me go from device_id to friendly name?)

Thanks in advance!

alias: Night-time Person Warning
description: ""
trigger:
  - platform: device
    device_id: <xxx>
    domain: nest
    type: camera_person
  - platform: device
    device_id: <yyy>
    domain: nest
    type: camera_person
condition:
  - condition: time
    after: "22:00:00"
    before: "07:00:00"
    weekday:
      - sat
      - fri
      - thu
      - wed
      - tue
      - mon
      - sun
action:
  - service: notify.mobile_app_brandons_iphone_13
    metadata: {}
    data:
      title: Night-time Person Detection
      message: Person detected at {{ trigger.to_state.name }}
      data:
        push:
          sound:
            name: default
            critical: 1
            volume: 1
  - delay:
      hours: 0
      minutes: 15
      seconds: 0
      milliseconds: 0
mode: single

Neither of those triggers are state triggers. They are device triggers.

The to_state variable is not available for device triggers. See the different variables available for different trigger types here: Automation trigger variables - Home Assistant

You need to change your triggers to state triggers. See here for help with that: Why and how to avoid device_ids in automations and scripts

Depending on the chosen device, a Device Trigger can behave like a State Trigger or an Event Trigger. In this case, I believe it’s like an Event Trigger (so the trigger obect doesn’t have a to_state property).

An Event Trigger can report various things buf if you didn’t find what you want in the trace then it isn’t available.

A device trigger does not have any properties except this according to the docs:

Inherits template values from event or state

The words event and state are links to documentation for Event and State Triggers. It inherits their properties.

1 Like

So it does. Call me Blind Pew.

1 Like

ok thanks … I did see mention of using state triggers/actions instead of device triggers, and I tried that but couldn’t figure out how to get that to work with my nest camera … so I guess that is my next question :wink:

When I use the Automation UI to setup a state trigger (Entity → State) on my camera.front_door, I don’t see any attributes listed that would let me trigger when a person is detected?

The only entity in the drop-down related to my front door camera is “camera.front_door”, and if I pick that the only attributes are “model” or “brand”…

If this is not the full set of values available, is there somewhere to see the full set in HA? I found the DevTools → States page which does list those 2 attributes and a couple more, but still nothing that would seem related to person detection?

Thanks again!