I am using a Sonoff SV to control LED lighting in our Catio. I have a button I can single click to turn the light on and off and right now I’ve set it up so double click changes color/effects. I am just wondering if I’ve made my code more complex than it has to be. Is there a smarter way of doing it than what I’ve done below?
globals:
- id: my_global_int
type: int
restore_value: no
initial_value: '0'
switch:
- platform: gpio
pin: GPIO12
id: relay
name: "Catio Light"
binary_sensor:
- platform: gpio
pin:
number: GPIO14
mode: INPUT_PULLUP
inverted: True
id: catiobutton
on_multi_click:
- timing:
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
- OFF for at least 0.2s
then:
- logger.log: "Double Clicked"
- if:
condition:
and:
- lambda: 'return id(my_global_int)==0;'
- switch.is_on: relay
then:
- light.turn_on:
id: FastLED_WS2812_Light
transition_length: 0.5s
red: 1.0
green: 1.0
blue: 1.0
- if:
condition:
and:
- lambda: 'return id(my_global_int)==1;'
- switch.is_on: relay
then:
- light.turn_on:
id: FastLED_WS2812_Light
transition_length: 0.5s
red: 1.0
green: 0.0
blue: 0.0
- if:
condition:
and:
- lambda: 'return id(my_global_int)==2;'
- switch.is_on: relay
then:
- light.turn_on:
id: FastLED_WS2812_Light
transition_length: 0.5s
red: 0.0
green: 1.0
blue: 0.0
- if:
condition:
and:
- lambda: 'return id(my_global_int)==3;'
- switch.is_on: relay
then:
- light.turn_on:
id: FastLED_WS2812_Light
transition_length: 0.5s
red: 0.0
green: 0.0
blue: 1.0
- if:
condition:
and:
- lambda: 'return id(my_global_int)==4;'
- switch.is_on: relay
then:
- light.turn_on:
id: FastLED_WS2812_Light
effect: 'Rainbow'
- if:
condition:
and:
- lambda: 'return id(my_global_int)==5;'
- switch.is_on: relay
then:
- light.turn_on:
id: FastLED_WS2812_Light
effect: 'None'
- lambda: |-
if (id(my_global_int) < 5) {
id(my_global_int) += 1;
} else {
id(my_global_int) = 0;
}
- timing:
- ON for 1s to 2s
- OFF for at least 0.5s
then:
- logger.log: "Single Long Clicked"
- timing:
- ON for at most 1s
- OFF for at least 0.5s
then:
- logger.log: "Single Short Clicked"
- switch.toggle: relay
light:
- platform: fastled_clockless
chipset: WS2812
pin: GPIO05
num_leds: 150
rgb_order: GRB
name: FastLED WS2812 Light
id: FastLED_WS2812_Light
effects:
- addressable_color_wipe:
- addressable_color_wipe:
name: Color Wipe Effect With Custom Values
colors:
- red: 100%
green: 100%
blue: 100%
num_leds: 1
- red: 0%
green: 0%
blue: 0%
num_leds: 1
add_led_interval: 100ms
reverse: False
- random:
name: Random Effect With Custom Values
transition_length: 5s
update_interval: 7s
- flicker:
name: Flicker Effect With Custom Values
alpha: 95%
intensity: 1.5%
- addressable_rainbow:
- addressable_rainbow:
name: Rainbow Effect With Custom Values
speed: 10
width: 50
- addressable_scan:
- addressable_scan:
name: Scan Effect With Custom Values
move_interval: 100ms
- addressable_random_twinkle:
- addressable_fireworks:
name: Fireworks Effect With Custom Values
update_interval: 32ms
spark_probability: 10%
use_random_color: false
fade_out_rate: 120