Yet another WakeUp Light Rule

You need a Switch item WakeUp. Set it to ON when the WakeUp light process should start. The following rule starts at lights off (0%) and it dims it up to 100%.

var Timer wakeUpTimer = null
var Number dimmer = 0
var Number dimmer_step = 1

rule "Wake-Up Light"
when Item WakeUp changed from OFF to ON
then
	logInfo("WakeUp", "WakeUp started")
	dimmer = 0
	wakeUpTimer = createTimer(now.plusSeconds(1), [|
        	if(Lights_Bedroom_1_Level.state==100) {
			logInfo("WakeUp", "WakeUp ended")
			dimmer = 0
			dimmer_step = 1
			wakeUpTimer = null
			sendCommand(WakeUp,OFF)	
        	} else {
			if(Lights_Bedroom_1_Level.state==10) {
				dimmer_step = 10
				sendCommand(Rollershutter_Bedroom, 96)
			}
			dimmer += dimmer_step
			if(dimmer > 100) { dimmer = 100 }
        		sendCommand(Lights_Bedroom_1_Level, dimmer)
                	wakeUpTimer.reschedule(now.plusSeconds(60))
        	}
        ])

end

What does it do?

  • Minute 1 - 10: increase the lights from 0% to 10% (+1% every minute)
  • Minute 10: open rollershutter
  • Minute 10-19: increase the lights from 10% to 100% (+10% every minute)

So, after 10 minutes, the rollershutter opens, after 19 minutes, the lights are at 100%.

I also added the following to my switch so I can abort the WakeUp light process if I want:

rule "Switch_Bed_1_PressShort"
when
    Item Switch_Bed_1_PressShort changed from OFF to ON
then
  if(wakeUpTimer !== null) {
	logInfo("WakeUp", "WakeUp aborted") 
	wakeUpTimer.cancel
	wakeUpTimer = null
	sendCommand(WakeUp,OFF)
  }
//... (here the normal things that the switch should do)
4 Likes

Thanks for sharing. The only things i can recommend is you might look at Design Pattern: Expire Binding Based Timers which could simplify the logic a little.

And you should use the method instead of the action for send command. See https://docs.openhab.org/configuration/rules-dsl.html#sendcommand-method-vs-action

2 Likes

@yoshi

Thanks for sharing this rule.

Just a question … I got the following error message in vsCode - the rule works fine though:

Type mismatch: cannot convert from BigDecimal to Number

It refers to this line:

dimmer += dimmer_step

I think this is just a wrong warning in Visual Studio Code.

If you want you can change it to dimmer = dimmer + dimmer_step Then the warning disappears.

1 Like

Hmm, does it make sense to open the rollershutter AND turn on the light? :smiley:
If it´s dayligght outside, rollershutter would do. If it´s still dark outside, no need to open the rollershutter.

I know there can be speciel preferences, but at first read through your rule, I simply had the thought… But why! :slight_smile:

Good point. I thought, it would be too fast too bright, when only the rollershutter opens. The wake up light + rollershutter increases the light step by step, brighter and brighter.

1 Like