RGBW Led - Double click to cycle through set colours?

I have a RGBW light strip as below and have managed to figure out how to use the physical button to turn the strip on/off.

My next challenge is trying to figure out how to get a double click of the physical button to cycle through 5 or 6 predefined colours/brighnesses.

I’ve seen one or two old topics but they relate to neopixel stuff so hence I thought maybe a fresh topic was called for :slight_smile: Any help would be much appreciated.

light:
  - platform: rgbw
    id: light_rgbw
    name: "${friendly_name} Light"
    red: output_red
    green: output_green
    blue: output_blue
    white: output_cold

binary_sensor:
  - platform: gpio
    pin:
      number: P1
      mode: INPUT_PULLUP
      inverted: true
    name: "${friendly_name} Button"
    internal: true
    on_press:
      then:
        - light.toggle: light_rgbw

This is not the solution but just a record of my progress…
In my testing I had issues differentiating between a press and a double click, so for now I have been testing out a short press and longer press like this…
It works well and the long press sets the colour to bright red…
Next task is to figure out how to make it cycle through various presets on each long press.

light:
  - platform: rgbw
    id: light_rgbw
    name: "${friendly_name} Light"
    red: output_red
    green: output_green
    blue: output_blue
    white: output_cold

binary_sensor:
  - platform: gpio
    pin:
      number: P1
      mode: INPUT_PULLUP
      inverted: true
    name: "${friendly_name} Button"
    internal: true
    on_click:
    - min_length: 50ms
      max_length: 500ms
      then:
        - logger.log: "Short Press"
        - light.toggle: light_rgbw
    - min_length: 1000ms
      max_length: 3000ms
      then:
        - logger.log: "Medium Press"
        - light.turn_on:
            id: light_rgbw
            brightness: 100%
            color_brightness: 100%
            white: 0%
            red: 100%
            green: 0%
            blue: 0%

I’m using this for router watchdog but maybe you could try implement in your code.
Might need some more editing on your side

globals:
  - id: counter
    type: int
    restore_value: False
    initial_value: "0"

#test
binary_sensor:
  - platform: gpio
    pin:
      number: P1
      mode: INPUT_PULLUP
      inverted: true
    name: "${friendly_name} Button"
    internal: true
    on_click:
    - min_length: 50ms
      max_length: 500ms
      then:
        - lambda: id(counter) += 1;
        - logger.log: "Short Press"
        - if:
            condition:
              lambda: return (id(counter) =1);
            then:
              - light.turn_on:
                  id: light_rgbw
                  brightness: 100%
                  color_brightness: 100%
                  white: 0%
                  red: 100%
                  green: 0%
                  blue: 0%
        - if:
            condition:
              lambda: return (id(counter) =2);
            then:
              - light.turn_on:
                  id: light_rgbw
                  brightness: 50%
                  color_brightness: 50%
                  white: 0%
                  red: 50%
                  green: 0%
                  blue: 0%
        - if:
            condition:
              lambda: return (id(counter) >=3); 
            then:
              - globals.set: #reset the counter back to 0 on the 3rd press
                  id: counter
                  value: "0"
              - light.turn_on:
                  id: light_rgbw
                  brightness: 30%
                  color_brightness: 30%
                  white: 0%
                  red: 30%
                  green: 0%
                  blue: 0%

Awesome thanks! I had a crack and it uploads okay but the log shows me that when I medium press to change colour it actually qualifies all the If condition and sets the colour to the last one GREEN.
Any thoughts or maybe even some tips on how to log the click_counter so I can see if it’s being increased?

light:
  - platform: rgbw
    id: light_rgbw
    name: "${friendly_name} Light"
    red: output_red
    green: output_green
    blue: output_blue
    white: output_cold

globals:
  - id: click_counter
    type: int
    restore_value: yes
    initial_value: '0'

binary_sensor:
  - platform: gpio
    pin:
      number: P1
      mode: INPUT_PULLUP
      inverted: true
    name: "${friendly_name} Button"
    internal: true
    on_click:
    - min_length: 50ms
      max_length: 500ms
      then:
        - logger.log: "Short Press for Toggle"
        - light.toggle: light_rgbw      
    - min_length: 1000ms
      max_length: 3000ms
      then:
        - lambda: id(click_counter) += 1;
        - logger.log: "Medium Press for Colour"
        - if:
            condition:
              lambda: return (id(click_counter) =1);
            then:
              - light.turn_on:
                  id: light_rgbw
                  brightness: 100%
                  color_brightness: 100%
                  white: 0%
                  red: 100%
                  green: 0%
                  blue: 0%
        - if:
            condition:
              lambda: return (id(click_counter) =2);
            then:
              - light.turn_on:
                  id: light_rgbw
                  brightness: 100%
                  color_brightness: 100%
                  white: 0%
                  red: 0%
                  green: 100%
                  blue: 0%

This is what is getting logged and you can see it passing both if conditions… Also not sure what the message at the end means?

[00:01:37][D][binary_sensor:036]: ‘Mirabella RGBW 06 Button’: Sending state ON
[00:01:39][D][binary_sensor:036]: ‘Mirabella RGBW 06 Button’: Sending state OFF
[00:01:39][D][main:122]: Medium Press for Colour
[00:01:39][D][light:036]: ‘Mirabella RGBW 06 Light’ Setting:
[00:01:39][D][light:051]: Brightness: 100%
[00:01:39][D][light:055]: Color brightness: 100%
[00:01:39][D][light:058]: Red: 100%, Green: 0%, Blue: 0%
[00:01:39][D][light:063]: White: 0%
[00:01:39][D][light:085]: Transition length: 1.0s
[00:01:39][D][light:036]: ‘Mirabella RGBW 06 Light’ Setting:
[00:01:39][D][light:051]: Brightness: 100%
[00:01:39][D][light:055]: Color brightness: 100%
[00:01:39][D][light:058]: Red: 0%, Green: 100%, Blue: 0%
[00:01:39][D][light:063]: White: 0%
[00:01:39][D][light:085]: Transition length: 1.0s
[00:01:39][W][component:214]: Component gpio.binary_sensor took a long time for an operation (0.06 s).
[00:01:39][W][component:215]: Components should block for at most 20-30ms.

Unfortunately i’m facing the same problem here.
If I use input boolean with true/false that does work but that limits you to 2 options only.
Might need someone else to have a look on this.
Here’s the code that I was using as reference

So this should work

# double click to change          
      - timing:
          - ON for at most 1s
          - OFF for at most 1s
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - lambda: |- 
              auto call = id(internal_light).turn_on();

              if (id(counter) == 0) {
                call.set_cold_white(1);
                call.set_brightness(1.0);
              }

              if (id(counter) == 1) {
                call.set_rgb(0.1, 1, 0.1); //Green color 
                call.set_brightness(0.5);
              }

              if (id(counter) == 2) { 
                call.set_rgb(1, 0.1, 0.1); //Red color
                call.set_brightness(1);
              }

              if (id(counter) < 2) { 
                id(counter) += 1;
              } else {
                id(counter) = 0;
              }

              call.perform();