Dimming Rule Function

Hey all,
I have some modules that are a pain and don’t do soft dimming when turned on (they do off for some reason). Has anyone got a dimming rule that you can pass a duration to that’s working well for them? I think the dimmers do per 100ms, is that possible in a rule due to latency? I’m after something that appears to work exactly like the hardware soft dim, without seeing stepping.

But if anyone is using a rule that I can pass that duration too, then I can reuse it for much longer durations (like for morning sunrise effect etc) as well as just general soft up/down. It appears you can only do this with Lambda and that has to be per rule file which isn’t ideal, but at least I can specify a set of functions at the top and re-use them per rule.


Rules don’t work like that, yet (see below). You don’t pass values to them. They are triggered based on an event and any data they get will have to be from Items or built in actions.

This is true for the OH1 rules engine. One of the things Kai is working for OH2 is the ability to have modular and reusable rules. Perhaps when that happens you will be able to pass values to a rule.

You can’t pass arguments to scripts either so, as you identified, you can only achieve this using lambda.

Yes I kind of got that, I was hoping that people might have tested out a few rules in OH1 and might share one they’ve settled on. Hoping that it’d be lambda so I could re-use it without having to just copy the code a load of times.

So what’s the state of OH2 rules? I’ve been tracking the zwave binding, but the rules seems to be in a state of discussion at the minute. Or have I missed something?


I’ve not seen too many discussion of it on this or the old google forums. I did post the following rule to this thread but this isn’t really what you are looking for. But it might give you inspiration.

rule "Go to sleep"
    Item SwGotoSleep changed
    var percent = 100
    while(percent > 0) {
        sendCommand(Dimmer, new Integer(percent).toString + "%")
        percent = percent - 5
        Thread::sleep(60000) // one minute

The big thing you would need to add to this is the little bit of math to calculate the sleep time so it drops from 100 to 0 in the desired amount of time. Something like:

val incrementTime = totalTime / 20 // 20 increments to get from 100% to 0% in 5% increments

By default OH2 will use the OH1 rules engine but Kai will have the new rules engine implemented by the time OH2 comes out. He is actively developing it but I don’t know the state. I think the move to Apache Karaf is a higher priority right now. I’ve not been following the OH2 development discussions that closely so I’m mainly going on comments he has made when he pops up in threads I’ve been involved in.

Thanks for the rule, I did see that thread, it’s very useful, I’ll have a go over the weekend.
I have been looking at HomeAssistant recently and they have a really nice way of doing rules that is based on YAML to describe it, obviously there’s more going on under the hood.

But in terms of general rules, having something you can quickly just piece together like that seems like a really nice idea, of course if you need to do more you should have the ability to properly code your own rule set.

Here’s an example:

    - name: Livingroom dim
           state: on
           transition: 2
           brightness: 75
           xy_color: [ 0.5926, 0.3814 ]
           state: on
           transition: 2
           brightness: 145
           xy_color: [ 0.5529, 0.4107 ]

With the transition being 2 seconds of dimming.
Kind seems like a nice way of doing it, describing what you want to happen rather than how.

I have big hopes for OH2, at the minute OH1 is running fine and I’m enjoying using it, but there are a few hurdles I’ve hit that I don’t think are going to be solved until OH2 is available. It’s a wonderful contribution to the world by the devs and very much appreciated!