Check the status of a list of sensors

Hi I was hoping someone could help me: I have a batch of door and window sensors and I would like to write a script that checks that they are all closed. If one or more are open, I want to receive a notification listing the open doors/windows.
I have tried various options in Scripts like “choose” but that will only find the first one. I have also tried a template with “if else” statements but I can’t get it to execute the notification service.
I would be grateful if anyone has any suggestions?

Create a group with all your door and window sensors in it. Lets call it group.all_doors_and_windows.

Include a condition that checks if the group is on (i.e. any member of the group is on):

  condition: state
  entity_id: group.all_doors_and_windows
  state: 'on'

In your script sequence or automation actions send this message with your preferred notification service:

data:
  message: >
    The following doors and windows are open: {{ expand('group.all_doors_and_windows') | selectattr('state','eq','on') | map(attribute='name') | list | join(', ') }}
2 Likes

Brilliant! Thanks so much. That works excellently.

1 Like