FOR Statement, see example here

Hello!

I have multiple temperature sensors at home and also devices that I track.
I have a condition in my automation, for example, any temperature below 65, I get a notification.
Also, for devices, if home for 30 minutes, I get notification. Right now I had to do it for EACH device. I believe this can be accomplished by a simple FOR statement, does anyone have any idea?? I would appreciate any assistance on how to accomplish this.

Thanks!

No for statement needed. Create an automation with multiple triggers, one for each sensor. Then in the action you can use the trigger object to find out which sensor triggered the automation.

Show an example of one of these automations please.

1 Like

Hi @Burningstone I figured it out using the for statement. I created a group for these sensors and used FOR statement.

{% for state in
    states|selectattr('entity_id','in',state_attr('group.leaksensors','entity_id'))|selectattr('state','eq','on')|list
    -%}{{state.name'}}{%-
    endfor %}

This template does the same thing but with fewer steps:

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

The final filter (join) places a comma and space between each name. Your example overlooks to put any spacing between the names.

1 Like

This works too! I like how simple the code is! Very nice, thanks @123

1 Like