Automations - reporting open sensors?

Hopefully in the right place - first time on the forum.

I’d like to create an automation that responds to a telelgram trigger with all the open zones in an alarm - for the life of me I can’t find anything similiar trying to google it - is it possible?

The trigger part is simple - the action then returns a message with all sensors where the State is ON/Open/etc?

You’re looking for a for loop.

I remember seeing someone using it to list all lights that were on, or doors open etc.

Unfortunately not finding anything with loops.

This guy is using a loop to identify all devices with low battery.

1 Like

try to modify this script

A quick modification to hard code ‘on’, try it in the dev templates page

    {%- for state in states.switch -%}
      {%- if state.state == 'on' -%}
        {%- if loop.first %}The {% elif loop.last %} and the {% else %}, the {% endif -%}
          {{ state.name }} status is {{ state.state }} {{- state.attributes.unit_of_measurement}}
      {%- endif -%}
    {%- else -%}
      Sorry, I can't find anything in state of on
    {%- endfor -%}
    {%- for state in states.binary_sensor -%}
      {%- if state.state == 'on' -%}
      {%- if loop.first %}The {% elif loop.last %} and the {% else %}, the {% endif -%}
        {{ state.name }} status is {{ state.state }} {{- state.attributes.unit_of_measurement}}
      {%- endif -%}
    {%- else -%}
      Sorry, I can't find anything in state of on
    {%- endfor -%}
1 Like