as the title says, i need some help to adjust a script that i found online. The following script is turns a light on and within 30 min it gradually increases the brightness but also is changing the temperature from warm light to natural light. This works as expected, however 1% of brightness with my bulb is too bright to fulfill it’s intention (sunrise wake up).
The idea is instead of using the temperature, to use rgb values which the bulb has significantly lower brightness output.
I assume that the Hue value is the problem. I don’t really understand the logic that was applied even with the temperature so i cannot figure it out…
Although the script runs correctly and there are no errors, the light turs Red (which is correct) but in the lovelace it appears as off and of course it doesn’t change color or brightness… I think i am out of the 360 degrees value for the hue…
thanks for still checking out on this. As i mentioned, i got the script online specifically from this site: Sunrise Alarm with Home Assistant - peddicord.xyz and i thought i could convert it to RGB at first.
The script is setting the variables in Mireds and it works as intended but now that we changed the variables we may need to change the hs_color calculation as well. It seemed logical to me to use HS (after your suggestion) because in reality hue is just one number (unlike RGB) and i thought that it can work. But i didn’t think it through correctly.
It seems fairly simple as the logic is: get the starting number 0 or 360 (this is the red colour) and turn it to 30 (orange colour) depending on the time in minutes. To simplify it we can set time to 30 min to do the transition and since we speak only for 30 value changes (from 0 to 30) it should change 1 degree per minute.
Unfortunately, i don’t have the programming knowledge to achieve that.
From the left the code comes when I click twice on a remote.
It checks the current state of the light and this node returns all the data you see in developer tools of this entity and passes that with the message.
The function node is the one with the programming.
In my case I also loop the saturation between 100 and 40%
If I would not have done that the “middle” section of the code could be removed.
var sat =100;
// below is to control the saturation
if (msg.dir == true){
if (msg.data.attributes.hs_color[1] > 70){
sat = msg.data.attributes.hs_color[1]+1;
}else{
sat = msg.data.attributes.hs_color[1]+2;
}
if (sat > 100) sat = 100;
msg.dir = true;
if (sat == 100) msg.dir = false;
}else{
if(msg.data.attributes.hs_color[1] > 70){
sat = msg.data.attributes.hs_color[1]-1;
}else{
sat = msg.data.attributes.hs_color[1]-2;
}
if (sat < 40) sat = 40;
msg.dir = false;
if (sat <= 40) msg.dir = true;
}
// to here...
msg.payload = { data: {
'entity_id': 'light.matildas_lampa',
'hs_color': [(msg.data.attributes.hs_color[0]+3)%360, sat] // here I say set the hue to current value + 3.
} };
return msg;
At the end it passes the new values in the message to the next node which does the service call.
A small delay and then check a variable if the loop should continue (if you change mode of the bulb or turn it off this variable is changed).
And then the code is back where it started.
Sorry for bringing up an old topic, but I wanted to do the same thing and got it working based off this script, so thought others might find it useful.
I’m very new to home assistant and scripting with yaml, so I’m sure there’s plenty of room for improvement, but it works for me.
I took a slightly different approach in that I wanted a start point and an end point and I wanted it to go start to end in a timeframe - pretty similar though.
I also used x/y colours for no particular reason.
Here’s the code - hope it helps.
Can someone please help on how to pass a defined variable into a loop? (Or what I’m doing wrong!)
The correct lamp turns on (variable works there), but the script fails when it hits the loop the variable light is unknown so has no data. (nb times reduced for testing)
Logger: homeassistant.components.script.sunrise_light
Source: helpers/script.py:410
Integration: Scripts (documentation, issues)
First occurred: 10:15:12 (2 occurrences)
Last logged: 10:15:12
Sunrise light: Repeat at step 4: Error executing script. Error for call_service at pos 1: Error rendering data template: UndefinedError: None has no element 0
Sunrise light: Error executing script. Error for repeat at pos 4: Error rendering data template: UndefinedError: None has no element 0