Dimmer when physical button is pushed via multi State Button

Continuing the discussion from Rule for dimmer when physical button is pushed:

I´m also a newbie in openHAB :slight_smile:
I have a push button that can send for an exampel a other state wehen the Button is presst and holden.

Normal push = State 1
Double push = State 2
Triple push = State 3
Heldpush = State 4
Heldpush release = State 5

so is there any way that the Dimmer is switching between dim up/down wehen the State 4 is sending? and hold an save the dimmlevel wehen the State 5 is sendeing?

Thank you for your respons.

Best Regards


What button are you using and what are your items. I assume this is for openhab 3

Hey James,

thank you for your fast replay :slight_smile:
I´m useing a normals button. But i use an extention via CAN Bus and then via Nodered and so on…
So at last i got the signal via MQTT.

My Extention send the kommand via MQTT when the button is holden or like this.

Yes my system woorks on OH3 and a Raspbery PI :slight_smile:
My Items are also CAN Bus extentions. for exampel 24V PWM Moduls.

Grettings from Germany

And then what happens? You update the state of some Item in openHAB, or generate a trigger event?

You’ve got your dimmer devices linked to openHAB Dimmer type Items? Do they implement INCREASE/DECREASE commands?

Hi Rossko,

No, in the moment it works via a Rule. But it can only switch the Lamp on/off : I want that the lights can dimmed when i hold the button.

rule "Taster_1"


  Item Taster_1 received update


  if ((Taster_1.state as DecimalType) == 1){



  else if ((Taster_1.state as DecimalType) == 2){



  else if ((Taster_1.state as DecimalType) == 3){





Yes. see below. I hope this will help :slight_smile:

Type dimmer : Ausgang1 [stateTopic="anlox/2/state/201", commandTopic="anlox/2/command/201", min=0, max=65535, step=1, on="65535", off="0"]

When i press the button i will get the deccimal number:
Normal push = 1
Double push = 2
Triple push = 3
Heldpush = 4
Heldpush release = 5

Type number : MIO3_0 [stateTopic="anlox/3/state/30", commandTopic="anlox/3/command/30", min=0, max=65535, step=1, on="65535", off="0"]

Thank you for your help. Sorry for so much Newbie stuff :slight_smile:

Alright. I’m guessing here that

is somehow related to

which should be enough info to look at your original question

which sadly makes little sense to me.
Maybe you want the dimmer to start ramping up when you get 4, until it gets to max, then ramp down,until it gets to zero, then ramp up,etc.?
And stop where it is when you get 5?

// globals to go at top of your rule file, before any rules
var dimDir = "up"
var dimTimer = null

rule "Taster_1"
// added to you rule
  }  else if ((Taster_1.state as Number) == 4) {
      if (dimTimer == null) {
         dimTimer = createTimer(now, [ |  // make a looping timer to do steps
               // first check to see if direction needs to change
            if ((yourItem.state as Number) == 100 ) {  // max
               dimDir = "down"
            } else if ((yourItem.state as Number) == 0 ) {  // min
               dimDir = "up"
               // now do dimming step
            if (dimDir == "up" ) {
            } else {
               // loop for next step in one second
         ] )

  }  else if ((Taster_1.state as Number) == 5){
      dimTimer?.cancel    // stop looping
      dimTimer = null