Rules for a dimmer


I have a dimmer and want to control from a remote control. My remote control allows trigger a rule for a long press and trigger another when the button is released.

So, I can create a rule to dim up/down continuously in a increment of 10. This rule will be trigger with a long press. And a second rule, triggered with the release, should send a “something” to the previously rule to stop the dimming action, up or down.

How can I interconnect both rules to obtain such behaviour? Let me know if this is not clear and will try to explain in a different way (if I can).

I’ll assume that you have the communication between the remote and openHAB figured out and know how to get the button down and button released events to trigger your rules.

There are numerous ways you to do this. Probably the simplest would be with a global boolean:

var buttonDown = false

rule "Long press"
    // long press trigger event
    buttonDown = true
        // increment or decrement dimmer by 10
        Thread::sleep(100) // experiment with the value to control dimming speed

rule "button released"
    // button released event
    buttonDown = false

So the button down rule starts a while loop that keeps running while the buttonDown boolean remains true. Once the button released event occurs the buttonDown is set to false and the while loop exits.

You probably want to add an && clause to the while loop to stop the loop when the lighting value gets to zero or 100% bright as well.