Scene script for automatic adjustment of the light color depending on the time of day

Please note - Uncorrected machine translation

This English version of the following text is currently 100% machine translated. In case of ambiguity, please refer to the German version (which in this case is the original written by hand).

For luminaires with cold white/warm white setting it can be desirable that the light color changes automatically depending on the time of day.

With the help of the Scene Script such Dynamic Scenes (i.e. those where something changes even after the call) can be easily created.

This works with all kinds of lights, be it DALI (grouped single dimmers or DT-8 CW/WW or color lights), hue (ambiance or color) at P44-DSB-DEH/D and P44-LC-DE, RGB and RGBW SmartLED chains, DMX lights and PWM outputs to P44-xx-X, and of course color or color temperature lights created as Custom Device.

The following example adjusts the light color in the period between dawn and dusk between warm (400 mired) to cool (100 mired) - the darker it is, the warmer the light. Of course, other gradients can be programmed, and the numbers adjusted as needed.

How to enter a scene script?

Detailed instructions on how to create a scene script on a P44-DSB or P44-LC device are available here.

The script

The following script can be copied 1:1 and entered into the "Script to execute..." field in the sceneedit dialog can be entered, but of course it can also be adjusted as needed.

var updatedelay = 0 // Make the first light color adjustment immediately when the scene is called.
// From here on the script should run endlessly in the background, but nevertheless
// the scene call should be completed. Therefore the running adjustment
// is moved to the background with `concurrent`.
concurrent {
  // Endless until another scene is called
  while (true) {
     // value of 0..1 for day run: 1: dusk or dawn, 0: middle of the day
     var dayarc = abs(maprange(timeofday(), dawn(), dusk(), -1, 1))
     // color temperature between 400 (at the beginning and end of the day) and 100 (middle of the day) mired
     var mired = maprange(dayarc,1,0.5,400,100)
     // Output to log for control (comment out if necessary)
     log("dayarc = %f, mired = %d", dayarc, mired)
     // Set color temperature channel to new value,
     // (slow transition except first time)'colortemp', mired, updatedelay)
     // apply channels to hardware
     // recalculate every 5 minutes from now on
     updatedelay = 0:05


More info