I saw a post doing something similar that was more complicated than this, so i thought I would share what I did. In my case, I have a Lutron RadioRa2 keypad button that I wanted to use for different functions, by using a single press, double press, etc.
Items:
Switch Special_Button_Flag { expire="3s,command=OFF" }
Number Special_Button
Rules:
var Number special_count = 0
rule "Special Button Press"
when
Item YourButtonItem changed to ON
then
Special_Button_Flag.sendCommand(ON)
special_count = special_count + 1
end
rule "Special Button End"
when
Item Special_Button_Flag changed to OFF
then
Special_Button.sendCommand(special_count)
special_count = 0
end
rule "Special Button Process"
when
Item Special_Button received command
then
AmazonController.sendCommand("You pressed the special button "+receivedCommand.toString+" times.")
end
You may need to play with the expire time to work for your example. The latency to get the button presses processed in my case needed the 3s time. Each time you press the button, it increments the count in a variable and turns on the “special button” item. So 3s after the last press happens, the “special button” item turns off and triggers sending the count to the Special_Button item. My sample rule here for testing just sent the count for Alexa to speak. The real rule would just use the number in receivedCommand to do the different functions.
I’m running OH 3.0.2 but I don’t think this depends on the version at all.