mwramos
(Marcelo W Ramos)
May 19, 2024, 8:38pm
1
How I save the index in a variable to use after “repeat”?
- repeat:
sequence:
- service: scene.turn_on
data: {}
target:
entity_id: scene.alarm_external
- delay:
seconds: 5
while:
- condition: template
value_template: >-
{{ is_state('switch.alarm_state', 'off') }}
- condition: template
value_template: "{{ repeat.index <= 5 }}"
- service: notify.alexa_media_echo_room
data:
message: The alarm was armed in {{ attempts_variable }} attempts.
data:
type: tts
tom_l
May 19, 2024, 11:23pm
2
Variables are local to the block in which they are used. To store the variable for use outside the loop you would have to use a helper, e.g. input_number.
See: https://www.home-assistant.io/docs/scripts#scope-of-variables
mwramos
(Marcelo W Ramos)
May 21, 2024, 12:19am
3
Thanks!
If there is more than one script running simultaneously, one helper per script will be needed… Is that right?
tom_l
May 21, 2024, 12:29am
4
Yeah and it obviously would not work if the script was run in parallel mode.
tom_l
May 21, 2024, 12:33am
5
If you have an MQTT broker you could also store it in an mqtt topic.
There was a post about storing stuff temporarily in template sensor attributes too but I can’t find it.
EDIT: Here, https://community.home-assistant.io/t/wth-cant-input-helpers-be-read-only-in-ui/467562/13?u=tom_l
1 Like
mwramos
(Marcelo W Ramos)
May 21, 2024, 12:37am
6
Great! Thank you very much.