Soft dimming between colours? (Hue)

339 views
Skip to first unread message

Thomas Brettinger

unread,
Dec 19, 2014, 9:46:13 AM12/19/14
to ope...@googlegroups.com
Hi,

has anyone done something like a script that softly fades one colour into antother?

ideally, the colors could should be Color items, selected by Colorpicker. My idea is the script reads the "from" and "to" colours, calculates the difference(s) and
then softly fades between them over a (also configurable) time.

I experimented with that idea for a while but I don't seem to get anything to work as soon as I try to access the variables. The typecasting drives me mad...

So, any idea from anyone how to approach this?

Regards
Thomas

Thomas Brettinger

unread,
Dec 21, 2014, 1:13:21 PM12/21/14
to ope...@googlegroups.com

I tried a lot of things and solved one problem - only to run into other issues.

First of
 all, I have a working approach as a rule:

rule "WulTest"
when
   
Item WuLTest received command ON
then
   
// "From" Color
   
var hF = ((WuL_Child_N_Hue_FF_Child_Col.state as HSBType).hue as DecimalType).floatValue
   
var sF = (WuL_Child_N_Hue_FF_Child_Col.state as HSBType).saturation
   
var bF = (WuL_Child_N_Hue_FF_Child_Col.state as HSBType).value
   
// "To" Color
   
var hT = ((WuL_Child_D_Hue_FF_Child_Col.state as HSBType).hue as DecimalType).floatValue
   
var sT = (WuL_Child_D_Hue_FF_Child_Col.state as HSBType).saturation
   
var bT = (WuL_Child_D_Hue_FF_Child_Col.state as HSBType).value
   
var tD = (WuL_Child_DimTime.state as DecimalType).intValue
   
var steps = tD * 60
   
var sD = (sT - sF) / steps
   
var bD = (bT - bF) / steps
   
//
   
// Make sure to always fade clockwise (e.g. from blue to yellow via red not via green)
   
//
   
var float hD
   
if (hT < hF) {
        hD
= (hT + 360 - hF) / steps
   
} else {
        hD
= (hT - hF) / steps
   
}
   
var hue = hF
   
var sat = sF
   
var brt = bF
   
var i = 0
   
while (i<=steps) {
        sendCommand
(Hue_GF_WZ_Ceiling_Col, hue + "," + sat + "," + brt)
        hue
= hue + hD
       
if (hue > 360) { hue = hue - 360 }
        sat
= sat + sD
        brt
= brt + bD
        i
= i + 1
       
Thread::sleep(100)
   
}
end

But what I actually want to do is to put this in a script, which gets triggered by an alarm (as a Wake up light).

The typecasting I need to do when going from rule to script has left me totally confused...

Mr. Google led me to some examples where others have had similar problems with other datatypes in scripts, but it seems that whatever I try, I just get a different sort of error message ;)

Can anyone point me to some info how this could work? 

I need to do something like in this (not working) example:
    
var hF = ((WuL_Child_N_Hue_FF_Child_Col.state as HSBType).hue as DecimalType).floatValue
var sF = (WuL_Child_N_Hue_FF_Child_Col.state as HSBType).saturation
var bF = (WuL_Child_N_Hue_FF_Child_Col.state as HSBType).value

Regards,
Thomas

Thomas Brettinger

unread,
Dec 21, 2014, 5:08:06 PM12/21/14
to ope...@googlegroups.com
Found something that works:

var Number hF = (WuL_Child_N_Hue_FF_Child_Col.state as org.openhab.core.library.types.HSBType).hue

var Number sF = (WuL_Child_N_Hue_FF_Child_Col.state as org.openhab.core.library.types.HSBType).saturation

var Number bF = (WuL_Child_N_Hue_FF_Child_Col.state as org.openhab.core.library.types.HSBType).brightness


var Number hT = (WuL_Child_D_Hue_FF_Child_Col.state as org.openhab.core.library.types.HSBType).hue

var Number sT = (WuL_Child_D_Hue_FF_Child_Col.state as org.openhab.core.library.types.HSBType).saturation

var Number bT = (WuL_Child_D_Hue_FF_Child_Col.state as org.openhab.core.library.types.HSBType).brightness


Not what I'd call "pretty" but at least it works :)

Message has been deleted

.

unread,
Dec 21, 2014, 10:54:25 PM12/21/14
to ope...@googlegroups.com
Here's my crude mood generator for a group of Philips Hue's, which uses random colors loops for a while...  Needs a considerable amount of work yet, just a rough example for reference!  :)

Item (group which includes all hue's throughout the house):
Group:Switch:OR(ON,OFF) LightsLava "Lava Lamps" <hue> (All)


Sitemap (nested in a frame):
Selection item=Scene_Lighting label="Scene" mappings=[0=AllOff, 1=AllOn, 2=Lava, 3=Energize, 4=Relax, 5=Party, 6=Nightlight, 7=Bedtime, 8=LoveShack]


Rule:
rule "Lighting Scene - LightsLava Switch On"
when
 
Item LightsLava received command ON
then
   
var Number fadeCounter
 
//RAPIDLY CHANGE HSB FOR ALL LIGHTS ON
 fadeCounter
=0
 
while(fadeCounter<100 && Scene_Lighting.state == 2 && LightsLava.state == ON) {
        fadeCounter
=fadeCounter+1
     
Lights?.members.forEach(light|
 sendCommand
(light, (((Math::random * 255).intValue)) + "," + (((Math::random * 100).intValue)) + "," + (((Math::random * 100).intValue)))
   
)  
     
Thread::sleep(2000)
 
}


 
//Switch OFF and return to relaxing colors
 postUpdate
(LightsLava, OFF)
end

Reply all
Reply to author
Forward
0 new messages