Hello all,
I have an issue with my script loop. I cannot get why it does not work.
Automatization for average temp save for last three days.
automation:
- alias: Historic Weather Data
trigger:
- platform: time
at: '06:00:00'
action:
- service: script.temperature_data
data_template:
loop_count: 4
script:
temperature_data:
sequence:
- service: input_number.set_value
data_template:
entity_id: >
input_number.temp_minus{{ loop_count }}
value: >
{% if loop_count | int == 0 %}
{{ states('sensor.temp_today') | float }}
{% else %}
{{ states('input_number.temp_minus' ~ (loop_count | int - 1) | string) }}
{% endif %}
#=== Stop when count is 0
- condition: template
value_template: >
{{ loop_count | int > 0 }}
#=== Stop the looping script...
- service: homeassistant.turn_off
entity_id: script.loop_temperature_data
#=== ...before looping
- service: script.loop_temperature_data
data_template:
loop_count: >
{{ loop_count }}
loop_temperature_data:
sequence:
#=== Stop the calling script...
- service: homeassistant.turn_off
entity_id: script.temperature_data
#=== ...then restart it
- service: script.temperature_data
data_template:
loop_count: >
{{ loop_count | int - 1 }}
The script should execute 4 times, and shift values:
input_number.temp_minus0 - temp of today;
input_number.temp_minus1 - temp of yesterday;
input_number.temp_minus2 - temp of second day after;
input_number.temp_minus3 - tamp of third day after.
After upgrade from 0.61 to last one the script execute loop one time and fill input_number.temp_minus0 with today temp, then copy input_number.temp_minus2 to input_number.temp_minus3 and that’s all.
Thanks in advance for help!