Automation data template issue

I am having trouble with this automation data template.

I have several sensors throughout the house and want to add more and when one of the sensors senses motions I would like the name of the sensor to be in the automation. Anything I do I can’t seem to get it to work.

Thanks,

- id: ios_motion_in_house
  alias: 'iOS Motion in the House'
  initial_state: True
  hide_entity: False
  trigger:
    platform: numeric_state
    entity_id: sensor.masterbedroom_burglar #, sensor.vision_zp3102_pir_motion_sensor_burglar, sensor.vision_zp3102_pir_motion_sensor_burglar_2
    above: 7
    below: 9
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: '{{ states.device_tracker.johnny_5.state != "home" }}'
      - condition: template
        value_template: '{{ states.device_tracker.aimee_moore.state != "home" }}'
  action:
    service: notify.ios_johnny_5
    data_template:
      message: >-
        "{{ trigger.from_state.attributes.friendly_name }} sensed motion in the House, better check it out!"
      title: 'Jarvis:'

I think this discussion is similar to your question. friendly_name
Also, try removing the ‘>-’ after message.

Not really sure which part doesn’t work.
Is it the notification or the condition?

For the notification my automation works fine with

message: '{{ trigger.from_state.name }} is home.'

instead of

message: >-
  "{{ trigger.from_state.attributes.friendly_name }} is home."

I’m not sue about single ’ vs. double " - I think I’ll never understand when to use which one :frowning:

I believe the message is where it fails because when I use the a generic message like below it works.

  action:
    service: notify.ios_johnny_5
    data:
      message: "Motion in the House, better check it out!"
      title: 'Jarvis:'

Not really sure why this works but it works with the below automation.

- id: ios_motion_in_house
  alias: 'iOS Motion in the House'
  initial_state: True
  hide_entity: False
  trigger:
    platform: numeric_state
    entity_id: sensor.masterbedroom_burglar, sensor.vision_zp3102_pir_motion_sensor_burglar, sensor.vision_zp3102_pir_motion_sensor_burglar_2
    above: 7
    below: 9
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: '{{ states.device_tracker.johnny_5.state != "home" }}'
      - condition: template
        value_template: '{{ states.device_tracker.aimee_moore.state != "home" }}'
  action:
    service: notify.ios_johnny_5
    data_template:
      message: >
        {{ trigger.from_state.attributes.friendly_name }} sensed motion in the House, better check it out!
      title: 'Jarvis:'
1 Like