Can’t get trigger.id into message

I’m trying to improve my jinja2 coding. It’s slow!

I have the below script that I’m trying to generalise. When a camera detects a person, I want to send a message to my phone and the message indicate which camera detected the person.

I’ve tried everything I can think of and looked here for other posts, but can’t get it to work. Where the trigger.id is in the message just comes up blank.


alias: Person is detected road while away
description: ""
triggers:
  - type: turned_on
    device_id: fd7f30c91a2fd03d
    entity_id: 146255844bcb84
    domain: binary_sensor
    trigger: device
    id: Road
  - type: turned_on
    device_id: 4442601d6a03e490
    entity_id: 40b1f3fcbe9a510409
    domain: binary_sensor
    trigger: device
    id: Balcony
conditions:
  - condition: state
    entity_id: input_boolean.home_status
    state: "off"
actions:
  - action: script.send_notification_to_multiple_devices
    data:
      devices:
        - mobile_app_matts_phone
        - mobile_app_matts_ipad_air
      title: {{ trigger.id }}
      message: Person detected by {{ trigger.id }} Camera
      sound: Sherwood_Forest.caf
mode: single

I would appreciate any guidance.

OMG! I think I have worked it out. I am testing it by using “run action” and it’s coming through blank. It just occurred to me that “run action” wouldn’t actually create the trigger. Is that correct? Is there any way to test it other than wait?

Yep run actions does what it says, it wont run triggers. Find your device in developer options - states and change its state there, it may work. Or just wait.

1 Like

That is correct.

Also, I think you need quotes around title and message because you are using templates

      title: "{{ trigger.id }}"
      message: "Person detected by {{ trigger.id }} Camera"
1 Like

You do in the first case, where the template is at the start of the title. You strictly don’t in the message where it’s embedded in a string but it’s a good idea to get into the habit.

2 Likes

I appreciate the responses. There’s a lot to learn, but super fun.