I’ve been working on a pool light that you set the color by turning the light off/on a certain number of times. I’ve got a button for each color that when you press the button it sets an index_number entity to the corresponding number of off/on loops.
Then i have an automation that gets triggered when this number changes and runs the following code:
action:
- service: switch.turn_on
entity_id: switch.pool_light
- delay: '00:00:03'
- condition: template
value_template: '{{ trigger.to_state.state | int > 0 }}'
- service: switch.turn_off
entity_id: switch.pool_light
- delay: '00:00:02'
- service: switch.turn_on
entity_id: switch.pool_light
- delay: '00:00:02'
- condition: template
value_template: '{{ trigger.to_state.state | int > 1 }}'
- service: switch.turn_off
entity_id: switch.pool_light
- delay: '00:00:02'
....
...
..
Saw this from another poster how they did it - i’m sure there is a better way with loops, etc. but this works nicely enough.
What I can’t for the life of me figure out is how to set the corresponding input_text field with the color name that goes along with the input_number. I’m going to use that color name in the label to tell me what the current color is.
In a perfect world i’d have some sort of array with numbers and the matching text and just set that when i press my button. So i can set the input-text field when i press the button, when the automation gets triggered, or something else.
Any ideas how to accomplish this? I’m still learning how the templates work and when to use {{ and when to use {$%- is still a bit of a mystery to me…