Hi everyone, I wanted to share an automation I’ve just built. I figured out how to get some of my Philips Hue lights to transition to a warmer temperature at night, with a smooth transition over a few hours. I did this using Node-RED and the visual-mapper plugin (Thanks to kuema for the tip!)
Here is my flow that you can import into Node-RED: Node-RED flow for color temperature transitions - Pastebin.com
Here’s how it works:
- The flow runs whenever the lights turn on. The
inject
node also triggers a new event every 1 minute.
-
"Hours since midnight"
is a JavaScript function that calculates the number of hours since midnight, with 4 decimal places. The hours are useful to see in the visual mapper, and the decimal places are required for smooth transitions.
- I use the visual mapper plugin to control the color temperature based on the time of day (i.e. hours since midnight)
In this configuration: The color starts at white (170) around 6am, then stays white until about 6pm. Then it slowly transitions to warm yellow (420) between 6pm - 8pm.
-
The switch checks to see if this flow was triggered by a light turning on, or by the 1 minute interval. If a light turned on, then we already know the ID, so we set the temperature for that light. This avoids a race condition where looking up the state would report “off”. It also means that we don’t have to wait up to 1 minute for the temperature to be set by the interval event.
-
If it was triggered by the 1 minute timer, then check both of the lights to see if they’re on. If so, update the temperature:
This was really fun to figure out, and I hope it helps show other people what you can do with Node-RED! I’m still learning a lot every time I try something new.