Identifying entity in a Binary Sensor Group

HI All

So here is my question. I have a binary sensor group called binary_sensor.doorandwindows which not surprisingly, contains all my doors and windows in a group. When one entity is open, it is on, whilst when they are all closed, its off.

My issue is I have an automation which alerts me if any doors/windows are open after 10:30, however I don’t have an easy way of identifying which one is open. I can see in the logs, it shows which one triggered it, but i want to know how to get this information out via a template.

You can use the following code in your message:

data:
  message: |-
    {{ expand(trigger.entity_id) |selectattr('state', 'eq', 'on')  |map(attribute='name') |join(', ') }}


1 Like

Thanks for getting back to me, unfortunately that didn’t work.

Below is the whole automation:

alias: Notify Doors Windows Open after 22:30
trigger:
  - at: "22:30:00"
    platform: time
    id: Time_2230
condition:
  - condition: state
    entity_id: binary_sensor.doorandwindows
    state: "on"
action:
  - data:
      message: "A door or Window is open"
      title: Alert
    service: notify.mobile_app_**mobile**
mode: single

When I added the code to the message part of the action, it said “Error rendering data template: UndefinedError: ‘trigger’ is undefined”

So I must be doing something wrong.

I assumed that your binary sensor is the trigger, which it isn’t. So my suggestion cannot work. Use it hardcoded:


{{ expand('binary_sensor.doorandwindows')
|selectattr('state', 'eq', 'on') 
|map(attribute='name') |join(', ') }}

1 Like

Thank You, that worked…

Have a great morning/afternoon/evening wherever you are. (It’s night in Australia)

thanks so much for this! I couldn’t find a concise solution for this.

You’re welcome!