Any way to shorten the entity_id sent in notifications?

The automation below sends a script notification to my phone and a media player. The entity ID’s are rather long. Is there any way to send a truncated name in the notifications?

-Thanks



alias: Water Sensors Notification
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.water_sensor_half_bath_water
      - binary_sensor.water_sensor_air_conditioner_water
      - binary_sensor.water_sensor_dishwasher_water
      - binary_sensor.water_sensor_bernard_bath_toilet_water
    from: "off"
conditions: []
actions:
  - action: script.notification_text_message_to_pixel_8
    metadata: {}
    data:
      message: Water leak detected by device {{ trigger.entity_id }}
  - action: notify.mobile_app_pixel_8
    metadata: {}
    data:
      priority: high
      message: >-
        Water leak detected by device {{ trigger.entity_id }} at {{
        now().strftime('%H:%M %A %B %d %Y ') }}
    enabled: false
  - action: tts.speak
    metadata: {}
    data:
      cache: false
      media_player_entity_id: media_player.office
      message: Water leak detected by device {{ trigger.entity_id }}
    enabled: true
    target:
      entity_id: tts.google_translate_en_com
  - action: switch.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: switch.vswitch
    enabled: false
mode: single
{{ trigger.entity_id | replace('binary_sensor.water_sensor_', '') | replace('_', ' ') }}

Or perhaps use

{{ state_attr(trigger.entity_id, 'friendly_name') }}

If you have friendly names that is better

2 Likes

If Hellis81’s options don’t work for you, there are always others like:

{{ device_name(trigger.entity_id) }}
{{ area_name(trigger.entity_id) }}

or if you want specific names just for this, you could always setup a mapping in a variable:

alias: Water Sensors Notification
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.water_sensor_half_bath_water
      - binary_sensor.water_sensor_air_conditioner_water
      - binary_sensor.water_sensor_dishwasher_water
      - binary_sensor.water_sensor_bernard_bath_toilet_water
    from: "off"
conditions: []
actions:
  - variables:
      mapper:
        binary_sensor.water_sensor_half_bath_water: Half Bath
        binary_sensor.water_sensor_air_conditioner_water: A C
        binary_sensor.water_sensor_dishwasher_water: Diswasher
        binary_sensor.water_sensor_bernard_bath_toilet_water: Toilet
      short_name: "{{ mapper.get(trigger.entity_id, 'Unknown Location') }}"
  - action: script.notification_text_message_to_pixel_8
    metadata: {}
    data:
      message: Water leak detected by device {{ short_name }}
  - action: notify.mobile_app_pixel_8
    metadata: {}
    data:
      priority: high
      message: >-
        Water leak detected by device {{ short_name }} at {{
        now().strftime('%H:%M %A %B %d %Y ') }}
    enabled: false
  - action: tts.speak
    metadata: {}
    data:
      cache: false
      media_player_entity_id: media_player.office
      message: Water leak detected by device {{ short_name }}
    enabled: true
    target:
      entity_id: tts.google_translate_en_com
  - action: switch.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: switch.vswitch
    enabled: false
mode: single
1 Like

That’s good to know thank you!

Thanks I’ll give this a try.