I have 3 sensors
I want to trigger an action whenever one of them gets above a fixed value.
I have used the following blueprint but it only triggers when all three are above the set value:
One thing to note is that the automation will not fire when you set it up just because the humidity is above 50. The numeric state trigger needs the value to change from below 50 to above 50.
Then remove the ‘above: 50’ in the trigger and add a condition template that checks that any of them are above 50.
This will cause it to trigger on any change of temp on any of the sensors, but will only run the automation if one or more of them are above 50.
There are ways to template it. Multiples are presented as a list. you can look in the list for any that meet your criteria.
I don’t generally write code for people, but there are lots of examples out there to iterate over a list and select things that match, count them, and if the count >0 send true.
Are you trying to create a Blueprint or a one-off Automation, because your template doesn’t really make sense for a Blueprint.
In your original post the list of humidity sensor’s would already be known and stored in the humidity_sensor input variable, there’s no need to search through every sensor entity. Assign the value from the input variable to a script variable, using either the trigger_variables or variables key. Then the list can be use in templates.
As shown above you don’t need to use a for loop to get the desired information. But, in cases where a loop is necessary, you need to use a namespace to extract the variable value that is set inside the loop after the loop is complete. Since the purpose of the template is just to see if any of them are above the desired value you can also make it a bit more efficient by pre-filtering with an inline if and breaking out of the loop after the first run.
{% set sensors = states.sensor | selectattr('entity_id', 'search', 'sensor.lumi_humidity') %}
{% set ns = namespace(condition_was_set = false) -%}
{%- for sensor in sensors if int(sensor.state) > 50 -%}
{%- set ns.condition_was_set = true %}{% break %}
{%- endfor -%}
{{ ns.condition_was_set }}