So basically, I have this light setup in home assistant, and it’s a chinese RGB LED light, I tried flashing it with tasmota, but it ultimately failed, so I’m forced to using it with the Tuya integration, but back on topic.
I want it so that when I trigger the automation/script that it slowly cycles (loops) through the Hue of the color spectrum at full brightness, and transitions slowly from each color value to the next one, and then the script/automation it stops when the automations/script is stopped. I did a bit of research and found that to do an RGB color loop in python, the following code would work:
def each_color():
for r in range(0, 256):
for g in range(0, 256):
for b in range(0, 256):
print(r, g, b)
each_color()
Which prints out to the console all 16 million color combinations line by line:
0 0 0
0 0 1
0 0 2
0 0 3
....etc
0 0 254
0 0 255
0 1 0
0 1 1
0 1 2
0 1 3
..etc
And it stops when all r
, g
, and b
reach 255.
The only issue with this is that, it just goes from black, to bright red, and so on. It doesn’t actually loop the hue values at full brightness, and I don’t want to go from black to a hue value, I want it to be on a hue value when the automation/script starts, if you get what I mean. (Should I be looking at Hue instead of RGB values?)
The reason for this script is so that I can put the RGB values it produces into the service data attribute rgb_color
for the light.turn_on
service in another automation/script (To be able to reuse this code).
I was thinking about using the Repeat Until syntax of the script action, for the place of a Python for loop: https://www.home-assistant.io/docs/scripts/#repeat-until, but then again, would that even work?
I’m at my wits’ end here.
Am I overcomplicating this? Is there an easier way of doing this? I’d love to know.
I’d very much appreciate any input to my conundrum.
Cheers.