Regarding color shifting with left/right button…
I have no buttons, but I have Aqara Magic cubes. I’m not using below automation for Yeelight, but for some DIY by me bottles with WS2812B LED strip inside. You gave me great idea that I should deploy it for my Yeelight’s as well, cause it will work.
As said, I’m using it to shift LED colors with one of my cubes rotating left or right.
Rotate cube right:
if:
- condition: template
value_template: |
{{ state_attr("light.bottle_lights", "hs_color")[0]>344.00 }}
then:
- service: light.turn_on
data_template:
hs_color:
- '1'
- '{{ range(80,101)|random }}'
brightness: |
{{ state_attr('light.bottle_lights', 'brightness') }}
entity_id: light.bottle_lights
else:
- service: light.turn_on
data_template:
hs_color:
- '{{ (state_attr("light.bottle_lights", "hs_color")[0])+15 }}'
- '{{ range(80,101)|random }}'
brightness: |
{{ state_attr('light.bottle_lights', 'brightness') }}
entity_id: light.bottle_lights
Rotate cube left:
if:
- |
{{ state_attr("light.bottle_lights", "hs_color")[0]<16.00 }}
then:
- service: light.turn_on
data_template:
hs_color:
- '359'
- '{{ range(80,101)|random }}'
brightness: |
{{ state_attr('light.bottle_lights', 'brightness') }}
entity_id: light.bottle_lights
else:
- service: light.turn_on
data_template:
hs_color:
- '{{ (state_attr("light.bottle_lights", "hs_color")[0])-15 }}'
- '{{ range(80,101)|random }}'
brightness: |
{{ state_attr('light.bottle_lights', 'brightness') }}
entity_id: light.bottle_lights
I am pretty sure this will work out of box for you. Just copy/paste it to your automation, replace light.bottle_lights
everywhere with the name of your light entity and add appropriate trigger (idk what could be the name of trigger in automation when you are pressing these buttons).
TL;DR explanation for above process:
We are setting color here via hue and saturation. For people who don’t know, these are hue and saturation:
So basically, we would want saturation somewhere between 80 and 100, because everything below 80, most probably will look like “paled/washed”.
On the other hand, hue is actually the color and it could be between 1 and 360 (360 degrees of circle). I didn’t want to go deeper with color tone and I’m pretty happy with 24 tones from the picture above (if you are going around the circle), so 360 / 24 = 15 (degrees). On every cube rotate (button press in your case) I’m raising or lowering hue for 15 ( e.g. {{ (state_attr("light.bottle_lights", "hs_color")[0])-15 }}
). Of course, there is a problem if your hue is already low, below 15, and you want to lower it more and also if your hue is already high, above 345, and you want to raise it more. In these cases, you need to “re-start the circle” from beginning (or from the end) again. This is the reason for if-then-else acrobatics. Regarding saturation, You can put static value if you want, e.g. 100, but I liked to add little randomness in my case, so this is the reason for {{ range(80,101)|random }}
.