Hi yalls,
I am trying to streamline a script for a quite simple use case.
Since sensors/actuators sometimes do not respond to commands, I want to ensure that a script is fully and reliably executed on all sensors/actuators by means of a while-loop.
The following is an example for a single thermostat:
- repeat:
while:
- condition: not
conditions:
- condition: state
entity_id: climate.room_climate_badezimmer
attribute: temperature
state: 18
The sequence to be executed with this is the following:
- repeat:
count: "{{ wohnung | count }}"
sequence:
- service: climate.set_temperature
data:
temperature: 18
hvac_mode: heat
target:
area_id: "{{ wohnung[repeat.index -1] }}"
Now in the while loop, I need to replace a static variable value (entitiy_id: climate.room_climate_badezimmer
) with a variable one like so:
climate.room_climate_[wohnung[repeat.index - 1]]
while:
- condition: not
conditions:
- condition: state
entity_id: climate.room_climate_&"{{ wohnung[repeat.index - 1] }}" # Syntax knowingly wrong
attribute: temperature
state: 18
So my first question is: How do I concatenate variable value strings correctly for this use case?
And my second question is: How do I deal with repeat count in case of nested repeats? Auxiliary variable?
And the 3rd question: Is the complete code below correct and can my low programming experience be streamlined out of it?
The whole code should look something like this:
alias: Lüften 5 Minuten
variables:
wohnung:
- bad
- arbeitszimmer
- wohnzimmer
- schlafzimmer
sequence:
- repeat: # loop 1
count: "{{ wohnung | count }}"
sequence:
- repeat: # nested loop 2
while:
- condition: NOT
conditions:
- condition: state
entity_id: climate.room_climate_[wohnung[repeat.index - 1]] # but the repeat.index must be from the superordinate repeat loop 1 !!!
attribute: temperature
state: 18
- condition: state
entity_id: climate.room_climate_[wohnung[repeat.index - 1]] # but the repeat.index must be from the superordinate repeat loop !!!
attribute: hvac_mode
state: heat
- sequence:
- service: climate.set_temperature
data:
temperature: 18
hvac_mode: heat
target:
area_id: climate.room_climate_[wohnung[repeat.index - 1]] # but the repeat.index must be from the superordinate repeat loop !!!
I know that at least the last part of my complete code is wrong - as mentioned above, I need suggestions as to how to concatenate correctly the variable names and how to deal with nested loops and their respective repeat.counts.