Dim lights with Zigbee remote control - zigbee2mqtt

My system is openHAB 2.5.10-1 running on a Raspberry Pi 4B Rev 1.2. Here I have succesfully setup an MQTT broker with the addon MQTT Binding 2.5.10.

I’m running zigbee2mqtt with a CC2531 as coordinator and at the moment I have mainly connected lights and light controls to the system. All bindings are fine and I’ve set it up with attribute_and_json output.

Everything in openHAB is setup with Paper UI.

I’ll give one example of a light thing I’ve added, it’s the same for all other lights:
I added a generic MQTT thing and called it Livingroom light. It has two channels:

Channel type: Percentage Value
State topic: zigbee2mqtt/Livingroom_Light/brightness
Command topic: zigbee2mqtt/Livingroom_Light/set/brightness
Absolute minimum: 0
Absolute maximum: 254
Is command

Channel type: On/Off Switch
State topic: zigbee2mqtt/Livingroom_Light/state
Command topic: zigbee2mqtt/Livingroom_Light/set
Is command

These are linked to items:

These items work like the should, either in control in the Paper UI or when added to a HABPanel or when I use a widget on my phone.

I have a remote control with 4 groups that I have bound and added as a Thing with 6 channels:
Channel type: Number Value
State topic: zigbee2mqtt/0xccccccfffe6459c8/battery
Is command

Channel type: Number Value
State topic: zigbee2mqtt/0xccccccfffe6459c8/linkquality
Is command

Channel type: String (text)
State topic: zigbee2mqtt/0xccccccfffe6459c8/action
Is command

Channel type: Number Value
State topic: zigbee2mqtt/0xccccccfffe6459c8/action_group
Is command

Channel type: String (text)
State topic: zigbee2mqtt/0xccccccfffe6459c8/click
Is command

Channel type: Number Value
State topic: zigbee2mqtt/0xccccccfffe6459c8/action_rate
Is command

All linked to their own items, where I can see the correct values coming through. I want to use the action item to trigger some rules. This item is Robb1_Action.
On and Off is very simple (this will display as on_1/off_1 for group 1, on_2/off_2 for group 2 etc.).

I’m struggling with setting a rule for the dimmer. When I keep the on button for group 1 pressed, it will give the action “brightness_move_up_1” and when I release it will say “brightness_stop_1”. For the off button it is “brightness_move_down_1” and also “brightness_stop_1”.

How can I set a rule that will slowly dim the light (for example -1% every 200 ms) as long as the command is “brightness_move_down_1” until it gets the command “brightness_stop_1”, and of course the same for move up.

I’ve looked around on this forum and tried several examples, but it won’t work like I want to. I did get it working that a long press would dim it one step, but not that it would keep dimming until I released this button.

Could anyone help me to setup this rule?

Set up a rule that triggers when the button is pressed. Within the rule setup a timer, which runs every 200ms. When the timer executes, check if button is still pressed. If yes, reduce the brightness by 1%.AAfter thatrretrigger the timer to execute again in 200ms. Done

On this way you have one rule and within a timer, that executes itself again as long as you press the remote’s button

1 Like

Thanks for the advice! This helped me to create a working rule!

var Timer timer = null

rule "Dimmer"
    Item Robb1_Action_Trigger received command
    if (timer!==null) {
	if(receivedCommand == INCREASE) {
           timer = createTimer(now.plusMillis(100)) [|
	if(receivedCommand == DECREASE) {
           timer = createTimer(now.plusMillis(100)) [|