Multi / long press transformation profile for rocker switch


Transform button presses on a rocker switch to a detailed String.
Handle multi press, or long press.

See sample actions and resulting commands :

  • “button1” press and immediately release —> “button1.1”
  • “button1” press and release three times in rapid succession —> “button1.3”
  • “button2” press and release four times in rapid succession → “button2.4”
  • etc…
  • Press “button1” during two seconds, then release → “button1.0” + “button1.0” + “button1.0” + “button1.0” (one command with “0” suffix, every 500 milliseconds)|


Version 0.1

  • initial release for openHAB 3.3.0


I didn’t really succeed in using the profile. After installing I can only select the standard profiles for all channels of my switches
Maybe I’m missing some necessary conditions? Is it only applicable for a certain kind of binding (e.g. EnOcean) or a certain channel like a rawToggle or a rawButton? Unfortunately all my light switches (where I wanted to use it) only provide a state channel by the binding. Could you please give me a hint?

Yes indeed, it is applicable to a rocker switch only. I use it for my EnOcean switch, I don’t know if any other manufacturer has a “RawRocker” channel on their device.
Basically, the profile needs two events sent by the device : a “press” and a “release” events.
If there is other devices who provide this kind of events (even with a different name), I could probably add it ?
But I don’t think a “basic” light switches send these kind of commands. (Sometimes they directly send Increase/Decrease command when long pressed, but no details on the press and release timestamp)

Anyway, what is your use case ? Multi press, long press, both ?

(I edited the open post to mention that a documentation is available with the source code)

My use case would be to get double or triple clicks from a remote control (it controls shutters and some lights).
Your profile would be much more elegant than handling that with a rule
You’re right that it doesn’t transfer a release event, only ON and OFF.

Would love to see this expanded to a more generic translation to be used on switch, contact, or button items.

My use case would be returning a long-press status from keypads to handle dimming - this could be accomplished by a while-loop in rules that changed dim % up or down as long as a button was being pressed.

Great idea!! Hope to one day use it at my house!

I could, maybe, expand this transformation profile for all kind of buttons, but ONLY for the multi press functionnality.

The long press requires the hardware to send a “press” and a “release” event, and if I’m not mistaken, it’s not very common. There is no simple way to know if a button is currently pressed otherwise.

Oh sorry, I let this message pass through without responding !
I will try to implement this. I have to do a new version anyhow, for the next major openHAB release (4.0)

Hey! Just saw your reply!

Thankfully in my case the keypads do sent press/release. Theres a flag on the item to control this behavior.

Looking forward to trying this out! Thank you again for contributing to the OH project <3

Possibly a stupid question, but how can I make a rule that is triggered by a LongPress, but not by a short one?

Not a stupid question : I think I didn’t explain it very well, so I understand that it is not easy to get.

Suppose I link the trigger channel of my rocker switch to a String item named “Item1”, with “lumiere” as a configuration value for the parameter Button1.

A long press will send several update events to Item1 with value “lumiere.0” (one every 500 milliseconds)
A single short press will send a single update event “lumiere.1” to Item1.
Two short presses will send a single update event “lumiere.2” to Item1.

So in your rule, if you only want to react to a long press, you just have to use a rule trigger like this (Rule DSL example, but other JSR rule has the same possibility):

Item Item1 received update lumiere.0

(EDIT : As I don’t use DSL, I don’t remember if we have to use “lumiere.0” or just lumiere.0.)

Note : If you don’t want during the long press to get several events “lumiere.0”, you can set the parameter “Maximum repetition” to 1. You will get just one “lumiere.0”, no matter how long you press the button, provided that of course it is a long press of at least 500 ms.

Remember, I only create this transformation profile with a rocker switch in mind.
I plan to release soon a new version with more support for other thing types (but no miracle, the long press functionnality will still require that the thing can send some kind of release event)