Automate switch cycling to get selected light color

I’m looking for an elegant way to create a drop down (helper)(or cluster of buttons) in HA GUI that i can select from a list of 17 programs for my pool lights. The lights themselves have built in logic that allows the user, via turning the power off and on quickly, to cycle through the different color patterns/programs. I would like to use a drop down or perhaps a card with all the programs listed as a button the user could select.

The tricky part is the system would have to keep track of what program # the lights are currently on then flick the off/on X amount of times to get to the next selected program.

Alt: I can have each button/dropdown line linked to an automation that would turn the light off for 5 seconds so it resets to program 1 then cycle power the appropriate amount of times to get to the selected program.

I’m fairly new to HA (about 2 months now) and have zero javascript knowledge. So any elegant solutions you can think of would require some detail for me to understand.

Running
RPi 4
HassOS 3.13
HA 109.6

How fast do you have to switch the light on/off/on?
Does the light show a state in HA, or is it simply a switch?

It provides zero feedback. Just a dumb switch I fitted with a Sonoff mini.
I think it had to be cycled off then back on within 5 seconds otherwise at 5 seconds the light resets back to program 1.

I was messing around with the helper drop down but I’m really struggling with the automation part behind the scenes. Thanks for the link. Confirmed how I guessed the helper worked.

Some might shake their heads :upside_down_face:, quick and dirty.

input_number


automation

automation:
  - alias: pool_lights_program
    trigger:
      - platform: state
        entity_id: input_select.justnumbers
    action:
      # reset program (6 seconds off)
      - service: switch.turn_off
        entity_id: switch.test_switch
      - delay: '00:00:06'
      - condition: template
        value_template: "{{ trigger.to_state.state | int > 0 }}"
      - service: switch.turn_on
        entity_id: switch.test_switch
      # block for number 1
      - condition: template
        value_template: "{{ trigger.to_state.state | int > 1 }}"
      - delay: '00:00:01'
      - service: switch.turn_off
        entity_id: switch.test_switch
      - delay: '00:00:01'
      - service: switch.turn_on
        entity_id: switch.test_switch
      # block for number 2
      - condition: template
        value_template: "{{ trigger.to_state.state | int > 2 }}"
      - delay: '00:00:01'
      - service: switch.turn_off
        entity_id: switch.test_switch
      - delay: '00:00:01'
      - service: switch.turn_on
        entity_id: switch.test_switch
      # block for number 3
      - condition: template
        value_template: "{{ trigger.to_state.state | int > 3 }}"
      - delay: '00:00:01'
      - service: switch.turn_off
        entity_id: switch.test_switch
      - delay: '00:00:01'
      - service: switch.turn_on
        entity_id: switch.test_switch
      # block for number 4
      - condition: template
        value_template: "{{ trigger.to_state.state | int > 4 }}"
      - delay: '00:00:01'
      - service: switch.turn_off
        entity_id: switch.test_switch
      - delay: '00:00:01'
      - service: switch.turn_on
        entity_id: switch.test_switch
      # block for number 5
      - ...

switch_loop

1 Like

@VDRainer
That’s great. thanks for the code behind your solution. Do you know of a way that the GUI could display the actual color text rather than the value? i.e.dispay “gold” return value “2” to the automation.

I guess i could create another helper and automation that assigns a number based on color text the users selects.

You can do something like this
Auswahl_329
and edit the value_templates in the conditions.

value_template: "{{ trigger.to_state.state.split(':')[0] | int > 0 }}"
1 Like

Damn your good! thanks

I’m getting some config error with the automation file. Would you be able to decipher the error and let me know what is wrong with the code?
Error message:
Invalid config for [automation]: expected str for dictionary value @ data[‘id’]. Got None
extra keys not allowed @ data[‘trigger’][0][‘action’]. Got None
required key not provided @ data[‘action’]. Got None. (See ?, line ?).

- id: 11111111111
  alias: pool_lights_program
#  Description: cycles light to appropriate program number based on user selection
  trigger:
  - platform: state
    entity_id: input_select.pool_light_color
    action:
    - service: switch.turn_off
      entity_id: switch.sonoff_pool_light
    - delay: 00:00:06
    - condition: template
      value_template: "{{ trigger.to_state.state.split(':')[0] | int > 0 }}"
    - service: switch.turn_on
      entity_id: switch.sonoff_pool_light
    - condition: template
      value_template: "{{ trigger.to_state.state.split(':')[0] | int > 1 }}"
    - delay: 00:00:01
    - service: switch.turn_off
      entity_id: switch.sonoff_pool_light
    - delay: 00:00:01
    - service: switch.turn_on
      entity_id: switch.sonoff_pool_light
    - condition: template
      value_template: "{{ trigger.to_state.state.split(':')[0] | int > 2 }}"

Look at the indentation of the trigger and action part in my automation.
This is very important in yaml.