How to find Area to a devise for use in message

How to find Area to a devise for use in a message?

Configuring my devices, I add them to an area. For my smoke alarms smoke detection, I want to make one automation sending me a message. I can pick up the {{ trigger.from_state.attributes.friendly_name }} but have not entered the area name to the friendly names.

How do I pick up the area related to the trigger device?
I want to do something like this in my notification:
Smoke alarm in {{trigger.from_state.area.name }}

That’s currently not possible. The state object doesn’t contain any information about the area.

Ill flag this as a feature request.

Found this thread while I was looking for the same thing, I didn’t find a solution other than a for loop:

service: notify.group_alarm_all
data:
  title: Alarm Sensor
  message: |-
    Alarm detected by sensor: {{state_attr(trigger.entity_id, 'friendly_name')}}
    {% for area in areas() -%}
      {{ 'in ' ~ area_name(area) if trigger.entity_id in area_entities(area) }}
    {%- endfor %}

HA came up with this way of finding entity area.

alias: Flood sensor Alarm
description: Water detected
trigger:
  - platform: state
    entity_id:
      - binary_sensor.flood_sensor1_water_alarm_water_leak_detected
    to: "on"
  - platform: state
    entity_id:
      - binary_sensor.flood_sensor2_water_alarm_water_leak_detected
    to: "on"
condition: []
action:
  - service: notify.me
    data:
      title: HA - ALARM
      message: Vannlekasje i {{ area_name(trigger.entity_id) }}!
mode: single
1 Like