Progressive Dimmer Rules

Here’s a sample dimmer rule, using a Zwave dimmer, Astro events, and a cron rule. It turns the dimmer light ON and dim (starts either at 0 or at the current value), when it starts getting dark outside. It then slowly raises the dimmer value up to full brightness (2% per minute, adjust as necessary to make it faster/slower).

I used the civilDusk event, which fires earlier than other sunset events since it gets darker quicker inside:

Items file:

Switch Light_FF_Living_Sconces_Dim	"Sconce Dimmer"				(Configuration)
Dimmer Light_FF_Living_Sconces 		"Sconces [%d %%]"		(FF_Living, Lights) [ "Lighting" ]					{channel="zwave:device:xxxxxxxxxx:nodey:switch_dimmer"}


var Number Light_FF_Living_Sconces_Value = 0

rule "Sunset Indoor Functions"
	Channel 'astro:sun:local:civilDusk#event' triggered START
	/*Start Living Room Sconces*/
	sendCommand(Light_FF_Living_Sconces_Dim, ON)
	logInfo("Lights", "Living Sconces Dim Sequence Start")

rule "Minute Functions"
	Time cron "0 * * * * ?"
	/*Bring up sconces progressively from dim to bright*/
	if (Light_FF_Living_Sconces_Value < 100)
		if (Light_FF_Living_Sconces.state > 0)
			Light_FF_Living_Sconces_Value = Light_FF_Living_Sconces.state as PercentType
			Light_FF_Living_Sconces_Value = 0

		if (Light_FF_Living_Sconces_Dim.state == ON)
			Light_FF_Living_Sconces_Value = Light_FF_Living_Sconces_Value + 2
			sendCommand(Light_FF_Living_Sconces, new PercentType(Light_FF_Living_Sconces_Value.toString))
			logInfo("Lights", "Sconces at " + Light_FF_Living_Sconces_Value.intValue)
		if (Light_FF_Living_Sconces_Dim.state != OFF)
			sendCommand(Light_FF_Living_Sconces_Dim, OFF)


your cron seem to be every second. not 5 min.
isn’t that should be : "0 0/5 * * * ?"
This could be done also with a recursive lambda and a timer.

I try to limit cron with every second execution.

Actually, the cron fires every 1 minute (per the logs). What I meant is that this rule will ramp up the dimmer brightness by 5% every 1 minute.

When I start OpenHAB, with this rule enabled, I get the following message:

2016-01-28 14:23:15.029 [ERROR] [.o.m.r.i.engine.ExecuteRuleJob] - Error during the execution of rule Minute Functions
java.lang.ClassCastException: Cannot cast org.openhab.core.library.types.PercentType to void


I have HABmin 1.7 installed if that matters.

is Light_FF_Living_Sconces link to a real dimmer?
the binding in the exemple poll the dimmer every 60 seconds. if you remove that, the dimmer initial value is undefined and the rules will not work.

try moving the dimmer in the Web app before firing up the rule. if that work. then that’s your problem.

Revisited this rule, cleaned up the code a bit and used code fences for better readability.

@sam2b, it may be much simpler but it is really bad practice.
Your rule is holding on one of the 5 threads available

You should do that with a timer:
Much safer

val int timeoutMills = 3 * 600 // 60000 divided by 100 dim levels
var int dimLevel = 1
var Timer timer = null

rule "Slowly Dim Up"
    Item Outlet2_Switch changed to ON
    if (timer === null) {
        timer = createTimer(now.plusSeconds(0), [ |   //Starts immediately
            if (dimLevel == 100) {
                timer = null // cancel timer
            } else {
                dimLevel = dimLevel + 1
                timer.reschedule(now.plusMillis(timeoutMills)) // reschedule timer is 3 * 600 mills

Hi, @vzorglub. Thanks very much for your help on this. (by the way, the code above needs a curly brace after time.reschedule() ).
Originally, I tried using a timer, but I went about it the wrong way. I just used your code and works just a smoothly. This was a good lesson. :slight_smile:

Corrected, thank you