upsert / lutron-caseta-pro

Custom Home Assistant Component for Lutron Caseta Smart Bridge PRO / RA2 Select

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request: Pico - Double & Long Press Actions

raddacle opened this issue · comments

Would it be possible to bring the double & long press functions that the Homebridge plugin has?

Homebridge Pico Plugin:
https://github.com/rnilssoncx/homebridge-pico

FWIW I used node red to accomplish multiple clicks on HA. Native would obviously be great but let me know if you are using node red and I can send how i did it.

I also implemented this manually -- first button press sets a custom variable, second one looks for the variable and behaves differently if the variable has been set.

No plans to add features for double or long press. There is no native support for it by Lutron and this component does not keep track of state history for each button. It is best left to the Home Assistant Core which has more flexibility to track this information.

There are some threads here and here and a previous discussion on #25.

I provided a long press approach in the thread here, and it could be modified to support a double press with some changes and maybe even trigger a more general event via parameters from an automation.

So you create your own automation (or even blueprint) that points to a generic python script and passes the us of the Pico whose button was pressed as an arg for the trigger.

The python script can then easily read& Wright state to the attributes of the Pico entity to know if a button was pressed multiple times in a specified time span (eg 2 seconds) and then trigger a new binary state change which you can add your own automations that bind to that virtual binary state s change the python script triggers.

I guess the main problem is that any automation ties to the single press would trigger twice, unless the script handled both single and double presses...but one thing python script isn’t good at doing is waiting. And you’d loose the responsiveness of the single press if it waited for 2 seconds to see if another press would come; I fear 500ms would be too fast for reliability of far away from the hub.

So there are some real issues to work out there... I suppose an AppDaemon script could work best because it supports async waits but is much more complex to develop.

FWIW I used node red to accomplish multiple clicks on HA. Native would obviously be great but let me know if you are using node red and I can send how i did it.

I also implemented this manually -- first button press sets a custom variable, second one looks for the variable and behaves differently if the variable has been set.

I provided a long press approach in the thread here, and it could be modified to support a double press with some changes and maybe even trigger a more general event via parameters from an automation.

So you create your own automation (or even blueprint) that points to a generic python script and passes the us of the Pico whose button was pressed as an arg for the trigger.

The python script can then easily read& Wright state to the attributes of the Pico entity to know if a button was pressed multiple times in a specified time span (eg 2 seconds) and then trigger a new binary state change which you can add your own automations that bind to that virtual binary state s change the python script triggers.

I guess the main problem is that any automation ties to the single press would trigger twice, unless the script handled both single and double presses...but one thing python script isn’t good at doing is waiting. And you’d loose the responsiveness of the single press if it waited for 2 seconds to see if another press would come; I fear 500ms would be too fast for reliability of far away from the hub.

So there are some real issues to work out there... I suppose an AppDaemon script could work best because it supports async waits but is much more complex to develop.

I've just begun transitioning to Node Red as it seems a bit more flexible. Is this possible to do with the regular Lutron hub, or do I need the Pro? I'm aware that some integrations have been possible with the regular hub using the lutron hub's certificates.

@raddacle

I believe that only the custom component (which requires the Pro hub and telnet interface) supports Pico remotes... and I don’t think this has changed.

As of the 2021.2 release of HA, the stock Lutron Caseta integration supports Pico remotes as events if you have the Pro/Ra2 Select bridge with Telnet enabled. It uses a new library that works in parallel to the HTTPS interface: https://github.com/bdraco/aiolip

Nice so Telnet was implemented similarly to the custom component...interesting! Will stay tuned on reliability and things before I migrate over...the custom component has been rock solid for years!

I forked the project and added long and double press support: https://github.com/coldfire0200/lutron-caseta-pro
The issue is that since these (long and double) are not natively supported by the device, the double press could be more problematic, the interval of two press read by python code could be longer than your actual time. I found 0.8s to be working pretty reliable. With 0.4s you likely get two single press for most of the buttons (only works for the fav button). Long press works just fine.

Basically in sensor.py I added a ButtonProcessor class that has a simple state machine to track the button press.

Configurable parameters:
enable_long_and_double: enable the ButtonProcessor. if disabled everything will behave as the original code
long_press_time: threshold time for long press
double_press_time: threshold time for double press

Rules:
timer start at first press
single press: first release is shorter than long_press_time, no second press detected within double_press_time
long press: first release is longer than long_press_time
double press: second press is detected within double_press_time

Button value:
double press will be the original value + 64 (0x40)
long press will be the original value + 128 (0x80)