I have the set of entities below, each assigned an initial value as shown. These can be individually adjusted by a slider - for each entity - on the front end. All this works currently.
Now…
I would like to allow the user to increment or decrement all of these by a value -2 to +2. So i setup an input_number input_number.adjuster range -2 to +2 and put this on the front end. I created an automation that runs when the adjuster value is changed.
But,
How do I run an action that increments all the entities below by the value in adjuster in a loop or do I have to do this for each entity / hard-code? I’d prefer a maintenance free option that allows me to add or remove entities and this “adjuster code” self adjusts so that I dont have to edit the solution all the time .
To put another way I need to go through all the entities above and increment them all by the same amount or decrement them.all by the same amount … Where the amount is the value of the adjuster
Let’s say that all the values started at the listed initial values. Then someone came and set the adjuster to +2. So now input_number.t_minus_5 is -3. Five minutes later they come back and set the adjuster to -2…
If the reference is its current value, then input_number.t_minus_5 should return to -5.
If the reference is always the initial value, it should become -7.
Thankyou for explaining that
So option 1, the reference is always the current value, for all of them. the values in the dict are the startup / initial values
If you need the initial values for some other action within the same script/automation and you need further help, please post the full thing so we can give informed advise.
EDIT: Updated for_each to use template as described below.
Mmmm. That’s what I felt was the “not ideal case”. Grateful but, not ideal because the solution needs to be accounted for whenever I add or.romove sensors
…some.intelligent algorithm.that can handle.such changes and maintenance free ,would be better but I am.gratefful.
Could.it.be changed to do a for-each or loop, through the already defined dict of sensors?
Yes, the for_each will accept templates. You will need to decide how you want to indicate which input_number entities should be included in the list. This could be essentially any entity property, or combination of properties, that is available to templating such as specific search strings in the entity ID or names, labels, areas, groups, etc.
An example that would work with the entity IDs you have shown would be:
{# List the entity ID of all entities with IDs that start "input_number.t_" #}
{{ states.input_number | selectattr('object_id', 'search', '^t_')
| map(attribute='entity_id') | list }}
Personally, I would use Labels instead. Since an entity can only have one entity ID but multiple labels, they can be more flexibly added and removed depending on need.
If you only ever use the label for these input numbers you can just use:
{# List the entity ID of all entities with the "Adjuster Numbers" label #}
{{ label_entities('adjuster_numbers') }}
If you decide to use the label on non-input_number entities, you can get just the input_numbers with the following:
{# List the entity ID of all Input Numbers with the "Adjuster Numbers" label #}
{{ label_entities('adjuster_numbers') | select('match', 'input_number.') | list }}