I am trying my hand at Home assistant for the first time. As my first project I want to create a night lamp for my little daughter.
Everything works fine expecting one thing. I want to integrate the double_click function to switch the NeoPixel between predefined colors. But I don’t know how. Have someone a good idea, what is the easiest (and maybe best) way?
I also already red the ESPHome documentation, but to be honest I still don’t know how to…
I have tried the lambda function to increase a global var, but then I am not sure how to check the value and choose the color.
Thank you leinich!
Your example don’t work, but was a good base
My solution looks like this and works fine:
light:
- platform: ...
bla bla bla
globals:
- id: color_global_int
type: int
restore_value: no
initial_value: '1'
binary_sensor:
- platform: gpio
pin: GPIO0
name: "Button"
# Single-click
on_click:
min_length: 50ms
max_length: 350ms
then:
- light.toggle: neo
# Long-click
on_multi_click:
- timing:
- ON for 0.5s to 1s
- OFF for at least 0.2s
then:
- lambda: |-
if (id(color_global_int) < 5){
id(color_global_int) += 1;
} else {
id(color_global_int) = 1;
}
- if:
condition:
lambda: 'return id(color_global_int) == 1;'
then:
- light.turn_on: # pink
id: neo
brightness: 40%
red: 45%
green: 0%
blue: 35%
- if:
and so on...
What I don’t understand is the click and double-click function. Every time when I double clicked the lamp goes off. But wenn I turned it on again the color was already changed. The lamp didn’t stay on… Do you know why?
This is why I’m using multi_click. And it works fine.