Display 'Name' in alert rather than entity ID

I have the following automation to alert on battery going low from my binary sensors:

- alias: Announce Sensor Battery Low
  hide_entity: false
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id:
        - binary_sensor.north_east_PIR_battery_low
        - binary_sensor.north_central_PIR_battery_low
        - binary_sensor.north_west_PIR_battery_low
        - binary_sensor.south_east_PIR_battery_low
        - binary_sensor.south_central_PIR_battery_low
        - binary_sensor.pergola_PIR_battery_low
        - binary_sensor.firepit_PIR_battery_low
        - binary_sensor.firepit_2_PIR_battery_low
        - binary_sensor.garage_north_PIR_battery_low
        - binary_sensor.garage_west_PIR_battery_low
        - binary_sensor.courtyard_PIR_battery_low
        - binary_sensor.carpark_PIR_battery_low
        - binary_sensor.driveway_1_PIR_battery_low
        - binary_sensor.driveway_2_PIR_battery_low
        - binary_sensor.courtyard_gates_battery
        - binary_sensor.front_door_battery
        - binary_sensor.awning_vibration_battery
        - binary_sensor.catflap_battery
        - binary_sensor.south_central_2_pir_batter_low
      from: 'off'
      to: 'on'
  action:
    - service: script.notifications
      data_template:
        speaker: 'media_player.downstairs'
        message: '{{trigger.entity_id}} has gone low'

However, the alert message reads like this…

…rather than using the name and showing North East PIR Battery, as in the binary_sensor config.

The names display correctly in the front end.

What do I need to change to get the name in the alert instead of the entity ID?

{{trigger.to_state.attributes.friendly_name}}
1 Like

Thank you, Tom. Do I need to define friendly_name separately from name in the binary_sensor config or is it the same thing?

Same thing.

FYI, I think it’s generally better to use:

{{ trigger.to_state.name }}

See State objects. The name field works whether or not the entity has a friendly name (and so won’t cause an error if it doesn’t. It used to fall back to the entity_id or object_id – don’t remember – but I just tested it and it seems to create a “pretty” name based on the object_id. E.g., switch.front_door would result in “Front Door”.)

1 Like

Thank you. I’ll give that a go.

I appreciate your time.