Scene script for continuous color change
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).
With the following scenescripts a persistent scene of a color luminaire can be made a dynamic scene, so that after calling the scene the color changes continuously.
This works with all types of color lights, be it DALI (grouped RGB(W) single dimmers or DT-8 color lights), hue 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 lights created as Custom Device.
The first example makes the color move through the color wheel by rotating the "hue" channel 15 degrees every 10 seconds (360 degrees = full color wheel, so one rotation in 360/15*10 = 240 seconds = 4 min).
The second example makes the color oscillate between two hue values.
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.
Example 1: Whole colorwheel.
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.
// Slow color change through the whole hue color circle (0..360 degrees)
var d = 10 // Number of seconds for a 15 degree step
// Adjust current color value to an integer multiple of 15
// (Not absolutely necessary, but recommended depending on the luminaire if the
// pure red, green, blue color points should be achieved)
output.channel('hue',round(output.channel('hue'),15));
// From here on the script should run endlessly in the background, but nevertheless
// the scene call should be completed. Therefore the running color change
// is moved to the background with `concurrent`.
concurrent {
// Endless until another scene is called
while(true) {
// increase hue (angle in color circle) by 15 degrees (goes back to 0 at 360)
// With fade time = d (see above)
output.dimchannel('hue',15, d)
// Apply channels to hardware
output.applychannels()
// Wait for fade time until the next 15 degree step is made
delay(d)
}
}
Example 2: Switching colors back and forth between two values.
In this variant, two hue color values can be specified in the variables from and to, between which the color will then slowly change back and forth. With the variables steps and d the number of intermediate steps and the step duration (not too short, see notes) are determined.
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.
// Slow color change between hue=from and hur=to
var from = 30 // orange
var to = 140 // green
var steps = 6 // number of steps
var d = 5 // number of seconds per step - 8-ung, do not set too short (>1 sec)
// From here on the script should run endlessly in the background, but nevertheless
// the scene call should be finished. Therefore the running color change
// is moved to the background with `concurrent`.
concurrent {
var hue = from
var step = (to-from)/steps
// Endless, until another scene is called
while(true) {
var i = 0
// Forward from->to
while (i<steps) {
output.channel('hue',from+i*step, d) // Set new hue value with fade time
output.applychannels() // Apply channels to hardware
delay(d) // Wait for fade time
i = i+1
}
// backwards to->from
while (i>0) {
output.channel('hue',from+i*step, d) // Set new hue value with crossfade time
output.applychannels() // Apply channels to hardware
delay(d) // Wait for fade time
i = i-1
}
}
}
Notes
- The
concurrent
is important for dynamic scenes whose scene script runs all the time. A scene call is strictly speaking not complete until the scene script has been executed. Therefore, an endlessly running scene script might block further scene calls (as of firmware 2.6.5 this no longer happens, but stillconcurrent
should be used). Withconcurrent
the endless running color change loop is moved into the background (into a separate thread), so that the main scene script can finish running, but the color change continues anyway. - The hue value is increased in rough increments - but to make the transition appear continuous,
output.channel()
uses the third argument to set a slow transition. - Not every color light can display every color equally well. In particular, colored "hue color" lights do not have very intense green and blue.
-
For luminaires with their own intelligence like DALI and hue, the luminaire itself is responsible to calculate the (many small) intermediate steps of a transition. Now the fact is that a color transition is not unique, but depends on the color space in which it is calculated.
With hue luminaires, for example, it is the case that although they know the hue/saturation color space (the classic color wheel), they nevertheless calculate all color transitions (incorrectly, to be precise) in the CieX/Y color space (the "color shoe sole"). DALI DT-8 luminaires may only know the RGB or the CieX/Y color space at all, accordingly the transitions are not exact hue transitions there either. Different are the P44 internal luminaire types like SmartLEDs, DMX and PWMs, there the P44 firmware calculates the colors and does this for a "hue" transition also in the corresponding hue/saturation color space.
In practice, however, this is only noticeable if you let the luminaire itself make large sections of the transition. That's why the examples take only relatively small hue steps, which also look similar in CieX/Y as in hue/saturation or RGB color space.
If you want it more precise, you can make the steps smaller, but with hue and DALI you have to keep in mind that these technologies do not tolerate very short intervals between commands. Faster than a command every second is unrealistic, and you have to take into account that in the same hue or DALI system probably other activities should run at the same time (scene calls, dimming). In practice, fast color changes are useful at most for demo purposes - beautiful moods are more likely to result from almost imperceptibly slow color changes.
The red arrows in the following picture show a real hue transition over a distance of 100° from green to blue in hue/saturation (right) and a transition between the same colors calculated in CieX/Y (left). In the hue/saturation color space the path goes over green-blue and light blue, but in CieX/Y it goes through the majority white center of the "color shoe sole".
More info
- Tutorials - more step-by-step application examples
- Example scene script for automatic adjustment of color temperature depending on time of day
- Functions (among others) for use in scene scripts
- General information about scripts and script contexts
- For questions and exchange: the plan44 community forum