Help modifying a script!

A long time ago i found a script to simulate a sunrise, which i use with my rgbw bulbs. They start in low brightness red, then fade to bright yellow. My issue is that i’d like them to go to full brightness and to full white light, instead of a dim yellow, since i have rgbw bulbs.

Im no programmer, and im having a difficult time trying to understand exactly how this script works. If anyone can help me modify the saturation and brightness to 100% id appreciate very much it.

Here’s the script

var Integer Dimmer
var Integer DimmerCheck
var Integer HueVal
var Integer SatVal
var DecimalType hue = new DecimalType(0) // 0-360; 0=red, 120=green, 240=blue, 360=red(again)
var PercentType sat = new PercentType(100) // 0-100
var PercentType bright = new PercentType(0)
var HSBType light

Dimmer = 3
HueVal = 2
SatVal = 99

while(Dimmer<=90) // End up at 90% brightness
   if (Dimmer==DimmerCheck)
      bright = new PercentType(Dimmer)
      hue = new DecimalType(HueVal)
      sat = new PercentType(SatVal)
      light = new HSBType(hue,sat,bright)
      Dimmer = Dimmer + 3
      HueVal = HueVal + 2 // Increment from 0 to 60 over half an hour
      SatVal = SatVal - 1 // Decrement from 100 saturation to 70% over half an hour
        DimmerCheck = Dimmer

And as a pastebin


This script is similar to mine, i just created a lambda.

A short explanation:

  • This script loops around the brightness, start is at 3% (Dimmer = 3) and over 90% (while(Dimmer<=90)) it ends.
  • Each loop step, the brightness is increased by 3 (Dimmer = Dimmer + 3).
  • This gives you about 30 steps with a delay of 1 minute each (Thread::sleep(60000)).
  • In each step, the Saturation is decreased by 1 (SatVal = SatVal - 1). So, with its start at 99 (SatVal = 99) and the 30 loop steps you end at about 70%.
  • In order to end with lesser saturation, you may decrease the start saturation of 99 or in decrease faster. Maybe substract 2 instead of 1.

I use a similar algorithm since some time ago and built a lambda from it. My variation stops at 99% brightness, so the saturation is a bit lower as well. I like the bright light at the end.
All the basic elements I described above are still there and it’s really bright sunlight in the end.
I am using innr RB185C bulbs for reference.

val Functions$Function3<ColorItem, SwitchItem, Integer, Boolean> sunrise = [
	ColorItem bulb,
	SwitchItem onoff,
	Integer delay |

	var String[] oldlight
	var String newlight
	var Integer hue // 0=rot,60=gelb,120=grün,180=türkis,240=blau,300=lila
	var Integer sat // 0-100
	var Integer bright=3 // 0-100

	bulb.sendCommand("0,99,3") // start with saturated, dimmed red

	while(bright <= 99 && onoff.state.toString == "ON")  // loop until canceled or bright light
		Thread::sleep(delay) // delay
		oldlight = bulb.state.toString.split(",") // get the old light state
		hue = Integer::parseInt(oldlight.get(0))+2 // get the new hue value
		sat = Integer::parseInt(oldlight.get(1))-1 // get the new saturation value
		bright = Integer::parseInt(oldlight.get(2))+3 // get the new brightness value
		newlight = String::format("%d,%d,%d",hue,sat,bright) // create the new light state
		bulb.sendCommand(newlight) // send light state to bulb



You call the lambda with a rule like this, replace the elements in <> with your items. You need a ColorItem and a Switch. If you want to speed up, use a delay of 1000 (=1s) instead of 60000. Lambda and rule has to be in the same *.rules file.

rule "sunrise"
	Item <YOURONOFFSWITCH> changed to ON
	createTimer(now.plusSeconds(10)) [| sunrise.apply(Milight_desklamp_1_Color,<YOURONOFFSWITCH>,60000) ]
	createTimer(now.plusSeconds(10)) [| sunrise.apply(Milight_desklamp_2_Color,<YOURONOFFSWITCH>,60000) ]
	createTimer(now.plusSeconds(10)) [| sunrise.apply(Milight_floorlamp_Color,<YOURONOFFSWITCH>,60000) ]
	createTimer(now.plusSeconds(10)) [| sunrise.apply(Oliver_Underbordlys_RGB,<YOURONOFFSWITCH>,60000) ]
1 Like