Notifications - Yaml assistance please

I am new to Home Assistant, started using it last Christmas, Not new to Home Automation.

Just getting into Yaml. First foray.

Any suggestions very much a appreciated.

I am trying to Home Assistant to notify me when a security camera identifies someone without having to do a new automation for each camera and each recognisable face.

I have it so on any camera if a known person is recognised it notifies me.

I am now trying to change the message so that it includes Camera name and Name of recognised person. But I am getting an error when I save it.


alias: Security Camera Person Detected
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.front_door_person_name
      - sensor.backyard_person_name
      - sensor.side_gate_person_name
      - sensor.front_left_person_name
      - sensor.spare_person_name
      - sensor.back_of_sheds_person_name
      - sensor.lounge_hallway_person_name
    to: Mike
  - platform: state
    entity_id:
      - sensor.front_door_person_name
      - sensor.backyard_person_name
      - sensor.side_gate_person_name
      - sensor.front_left_person_name
      - sensor.spare_person_name
      - sensor.back_of_sheds_person_name
      - sensor.lounge_hallway_person_name
    to: Window Cleaner
  - platform: state
    entity_id:
      - sensor.front_door_person_name
      - sensor.backyard_person_name
      - sensor.side_gate_person_name
      - sensor.front_left_person_name
      - sensor.spare_person_name
      - sensor.back_of_sheds_person_name
      - sensor.lounge_hallway_person_name
    to: Dawn
  - platform: state
    entity_id:
      - sensor.front_door_person_name
      - sensor.backyard_person_name
      - sensor.side_gate_person_name
      - sensor.front_left_person_name
      - sensor.spare_person_name
      - sensor.back_of_sheds_person_name
      - sensor.lounge_hallway_person_name
condition: []
action:
  - service: notify.mobile_app_phone
    metadata: {}
    data:
      message: Security Camera {{trigger.attributes.friendly_name}} detected {{trigger.to_state]} (Person Detected)
      title: Security
mode: single

I get “ Message malformed: template value should be a string for dictionary value @ data[‘action’][0][‘data’]”

Look closely at your braces:

message: Security Camera {{trigger.attributes.friendly_name}} detected {{trigger.to_state]} (Person Detected)
                                                                                         ^
                                                                                         |
1 Like

Thanks!!

It was my first foray into YAML, I had such a low expectation I might have got it right it never occurred to me to spot the obvious typo!

Thanks

Some other tips:

  • The first two triggers are equal, except for the to: part. You can use a list there for to: the same way you used a list for the entities.
  • The third state condition has no to: so it triggers on any change, even an attribute change. If triggering any state was your intent, you can remove the first two triggers. You can put in to: null there if you have unwanted triggers on attributes.