Trigger based on last button pressed on keypad?

Is it possible to create a rule that tracks the last button pressed on a keypad so that I can create a trigger which will run based on the button that was pushed?

I have a few Lutron keypads that have raise/lower buttons (similar to the Picos), and what I'm trying to do is if I press 'Lamp-1' last on the keypad, pressing the Raise/Lower buttons will trigger this last button pressed (Lamp-1) to raise/lower dimming. If the last button pressed was 'Shade', then similar behavior to raise/lower.

This is built into RadioRa2 keypads, but they lock the buttons to either 3rd party system (sonos) or lighting. No way to have both work at the same time, which is where Hubitat comes in.

I have everything work individually well for light dimming (and also Sonos Volume with these buttons), but trying to figure out how I can get Hubitat to 'remember' the last button pressed.

Thanks for any ideas!

on button press of shades and light set a global variable. then in the rule for the dimmer check the global variable for which device to control..

1 Like

Thanks for pointing me in the right direction. Newbie to writing variables.

Would it go something like this...?

Global Variable
KeypadLastButtonPressed

Rule 1
If Lamp button pressed, set Variable to button number of lamp
Rule 2
If Shade button pressed, set Variable to button number of shade

Rule 3
If Raise Pressed, start raising dim level of variable KeypadLastButtonPressed

This may help you.

The following variables are predefined and will contain the last event: %device%, %value%. %device% will contain the device name that triggered the event and %value% will contain the value, for a button that should be the button number.

2 Likes

Well, the "last" button pressed would be "raised" or "lowered", wouldn't it? Do you mean the previous button pressed?

The issue you're going to run into here is that you are going to have to limit which buttons you track via a global variable in this manner.

That you can't do. Global Variables cannot be devices. Have you seen an option to pick a variable anywhere in any of the device drop-downs in rule machine? There aren't any.

The only way this would work, is if you set the variable to a string and then control the devices like this:

Button Raise Pushed:
    ACTION:  
    IF (device = lamp) THEN
         Begiin Brightening the Lamp
    Else if ( device = shades) then
        Begin raising the Shades
    END-IF

And you would have to do the same for the lowering button. The night part is, on the release event, you can just stop moving both of them since it won't affect the device that isn't changing.

1 Like

Thanks so much for all the help. Was able to get this working using your guidance.

Here's what I setup:
-Global Variable
LastButtonPressed = string value

-Rule 1 (Set global variable)
SetLastButtonPressedVariable
If Button 1 is pressed, or button 2, etc
Set value to %value%

-Rule 2 (On Lower button press)
When Keypad button 18 is pressed

IF Sonos is playing, then lower volume
ELSE
IF LastButtonPressed=1
Then starting lower living room lamp
ELSE
IF LastButtonPressed=2
Then start lower living room shade

-Rule 3 (Raise)
Repeat above but for button 19 but instead start raising instead of lowering

-Rule 4 (Stop)
When button is released, stop raising/lowering dim/shades

So now if I have Sonos playing in the room, the raise/lower buttons control the volume. Otherwise, it controls raising/lowering the lights/shades of the button last pressed on the keypad.

Unfortunately the slight caveat is if you want to adjust Sonos volume, you have to keep pressing the up/down buttons, since there is no "Start Raising" option like there is with Dimmers. But maybe I can put together something that repeats keypress until the button is released to get around it.

Thank you again!

I see one immediate problem with your rules...you will not be able to adjust your lights or shades when sonos is playing. That isn't a problem for you?

There is a way to do this that is quite easy as long as the button supports the release event. I just tried it with my Google Nest Hub and it actually works.

image

I removed the other buttons to avoid confusion. I didn't know that you could stop the action of another button inside of a button device rule. Obviously this would not work within another rule as the stop has to be in the same rule but this works perfectly.

That's ok for me for now at least. I figure if the lights are already on and set, then more convenient to be able walk up and adjust the volume if music is playing. If this changes in the future, I should be able to just set the button for Sonos (toggles on/off) to also populate the global variable and use that for an action.

Will check out your repeat option below, thanks for that!

Tried this with a new blank rule, unfortunately the repeat is not kicking in. You have to keep pressing the button. I even removed the action on release to see if it would just keep repeating but it doesn't. Perhaps it might be a limitation within the sonos integration.

image

That is not the way you do a repeat. Please look at the rule I already posted on how to do a proper repeat.

This is how I do it and working fine with Sonos.

All this should work as I have similar set up. Couple of questions though, your lutron keypads are they one device with multiple buttons? Ie could all this be done in one rule using a button device as the trigger?

If so you would be better of A using local variables and B as you have just 2 devices you want to control from the raise and lower you could use a Boolean which would simplify it. Or if more than 2 a number variable.

rule idea
Button 1 pressed

Set "device" (local variable) to true or 1
Turn on the device X

Button 2 pressed 

Set "device" to false or 2
Turn on the device SONOS

Button 3 held

IF (Device is true) THEN
Brighten X
ELSE
Repeat action every 1 second (stoppable)
Raise volume on Sonos
END REP
END IF

Button 3 released

Stop changing device X
Stop repeating actions

Button 4 held

IF (Device is true) THEN
Dim light  X
ELSE
Repeat action every 1 second (stoppable)
Lower volume on Sonos
END REP
END IF

Button 4 released

Stop changing device X
Stop repeating actions

Button 5 and 6 would be the same as 1 and 2 for the off.

How did to do an adjust by percentage? I have this option for dimmers, but not if I select Music Player.

Tried the below to better match your example:

image

1 Like

Thanks @BorrisTheCat for this idea. The Lutron keypad is a single device with multiple buttons. There's really only a maximum of 6 buttons (or devices to control) per keypad, and they treat buttons 18/19 as the raise/lower buttons. The buttons all show up when using button device as the trigger. Right now I'm using %value% on the variable and it's assigning numbers 1-6 depending on the button that was pressed. Unfortunately for these keypads, they only support pressed/released.

So how do you do raise and lower? Or is the held a press? If so this will still work.

You have it right. You begin the repeat raising when the button is pressed and then stop it when it is released. That is the same functionality as the "Fast Pico" driver. HE worked in a HELD function for the pico via software. The pico only reports pressed and released, but if the device isn't released before the held time elapses, then the held event is sent by the driver.

The same could be done for the RadioRA buttons as well.

How much do you have the "lower volume" command lower the volume by? You'll want to keep that small enough that you can get the granularity you want but not so small that it takes you forever to raise/.lower the volume.

The standard when I was testing it the other day on SONOS was 5 % so it worked quite well. I was going to have it repeat every 0.5 s but once I realised it was doing in 5 steps the 1s seemed to work better.

The only option listed under music player is Lower Volume. Is there a setting somewhere I am missing to adjust the percentage?

image

This is correct for Sonos, I think @Ryan780 is using a speech synthesis device? If so it would be slightly different command options, but the rule would still work just have the lower repeating like I do.

Wonder if I'm having a timing issue because the speakers are WiFi connected. I have the rule below, if I hold the button down sometimes it might lower the volume a notch after 3 seconds. Other times it does nothing. I tried setting it to 2 seconds, but no change.

For these keypads, it's just pushed/released. However, this is working fine and smooth for dimming devices like the lights and shades.

image