rnilssoncx / homebridge-pico

Expose Lutron Pico Remotes in Homebridge: https://github.com/nfarina/homebridge
MIT License
63 stars 6 forks source link

Is it possible to create a continuous long press action? #38

Closed rfiorentino1 closed 2 years ago

rfiorentino1 commented 2 years ago

Thank you so much for creating this plug-in, I currently use it to allow pico audio remotes to control Sonos with additional functionality instead of the default integration. However, it would be great to somehow make a continuous long press, for things like volume etc. I really don’t know if/how this would work, but it was just a thought I had and wanted to put it out there. Maybe if a long press is detected for more than a certain amount of milliseconds, keep sending whatever the initial long press command/action was until the button is let go? Open to thoughts/suggestions or helping you test things etc. I devil in scripting a little bit, but haven’t looked at the actual code in this plug-in enough to know if this is a possibility or not. Thank you again for creating this, it’s been awesome

rnilssoncx commented 2 years ago

I believe this is possible. Combined with shortcuts in the Home app this could be a nice option. I'll see about adding it in the next update.

rfiorentino1 commented 2 years ago

Awesome, thank you so much!

rnilssoncx commented 2 years ago

Just finished implementing this feature. I'll be curious to see how well it works combined with shortcuts.

You can set the repeat time - right now 500ms - and which buttons on witch switches will have the capability.

Look for the release in a couple hours.

rfiorentino1 commented 2 years ago

Thank you so much! This looks awesome. However, I can't figure out how to enable it; do I need to manually edit the config file to enable repeat for certain remotes? I tried to do it from within the UI and it doesn't look like I can, but maybe I'm missing something? :)

rnilssoncx commented 2 years ago

You have to manually edit the config. I put it in the example.

I'll update the gui config in the next release, but I didn't have time to get that setup.

rfiorentino1 commented 2 years ago

Ok perfect, thanks so much.

rfiorentino1 commented 2 years ago

Can I add each button and repeat parameter to existing configurations, or do I need to change type to custom and configure that way? I’m a little afraid to play with it manually, because if I mess something up I don’t want all the devices to re-appear as new ones in HomeKit and disassociate all of their current automation. I have about 50+ scenes/automations that I would need to redo if that happened. 😂

rnilssoncx commented 2 years ago

The repeat won't impact your devices. Just add it per the sample on the Pico remote in the config. If you get the button IDS wrong it just won't enable repeat, but it won't impact the overall config.

If you want to share your config I'd be glad to check it over.

rfiorentino1 commented 2 years ago

Ok cool, thank you! Does this look right?

    {
        "buslog": "off",
        "servers": [
            {
                "switches": [
                    {
                        "pico": [
                            3
                        ],
                        "name": "Kitchen Pico",
                        "type": "PJ2-3BRL",
                        "repeat": [1,2,4,5]
                    },
                    {
                        "pico": [
                            4
                        ],
                        "name": "Living Room Pico",
                        "type": "PJ2-3BRL",
                        "repeat": [1,2,4,5]
                    },
                    {
                        "pico": [
                            5
                        ],
                        "name": "Back Porch Pico",
                        "type": "PJ2-3BRL",
                        "repeat": [1,2,4,5]
                    },
                    {
                        "pico": [
                            6
                        ],
                        "name": "Master Bedroom Pico",
                        "type": "PJ2-3BRL",
                        "repeat": [1,2,4,5]
                    }
                ],
                "host": "192.168.1.124",
                "port": 23
            }
        ],
        "longname": false,
        "platform": "Pico"
    },
rnilssoncx commented 2 years ago

The format is right, but the Pico you have doesn't have a "1" button. The buttons on the remote are ['2', '5', '3', '6', '4'].

What is the use case for repeating all but one button? Just curious how this is being used.

rfiorentino1 commented 2 years ago

Awesome, got it! This works beautifully, thank you!!

Actually, it's funny, because when I thought about this feature, I assumed it would be a global toggle for repeated actions or not, either for each remote, or all remotes. But I actually like this a lot better, because the more I think about it, I would much rather it be an individual setting for each button. For example, the favorites button is used to cycle through favorites on each single press, like normal. But a double press or long press of the button triggers specific Sonos groups to turn on/off, so if I made that continuous long press, it would keep switching those speakers on/off etc. This is perfect.

Out of curiosity, what is the custom type for? What's different about that than specifying a specific pico remote?

Also, I'm assuming that the repeattime|| 500 in the index file is where you change the default time for repeated actions? Thanks again

rnilssoncx commented 2 years ago

Glad you're working!

Custom is there to cover cases where Lutron releases a new pico device that isn't in the code. You could just push the buttons, watch the log, and add it as a custom. Saves people from waiting for me...

repeattime is how fast it will repeat. Basically, a timer that will fire every "x" milliseconds until the button is released.

rfiorentino1 commented 2 years ago

Right, but where you change the value for that time is in the index. Js file?

rnilssoncx commented 2 years ago

That's a setting for the platform. I added it your example config above.

    {
        "buslog": "off",
        "servers": [
            {
                "switches": [
                    {
                        "pico": [
                            3
                        ],
                        "name": "Kitchen Pico",
                        "type": "PJ2-3BRL",
                        "repeat": [1,2,4,5]
                    },
                    {
                        "pico": [
                            4
                        ],
                        "name": "Living Room Pico",
                        "type": "PJ2-3BRL",
                        "repeat": [1,2,4,5]
                    },
                    {
                        "pico": [
                            5
                        ],
                        "name": "Back Porch Pico",
                        "type": "PJ2-3BRL",
                        "repeat": [1,2,4,5]
                    },
                    {
                        "pico": [
                            6
                        ],
                        "name": "Master Bedroom Pico",
                        "type": "PJ2-3BRL",
                        "repeat": [1,2,4,5]
                    }
                ],
                "host": "192.168.1.124",
                "port": 23
            }
        ],
        "longname": false,
        "platform": "Pico",
        "repeattime": 500
    },
rfiorentino1 commented 2 years ago

Awesome, thank you. Works perfectly

rfiorentino1 commented 2 years ago

Hi Robert, something interesting has started happening now. Suddenly the pico plugin is constantly looping an action, and won't stop until I restart Homebridge. I did a long press on the off button for about 6 seconds or so, turning the volume down on Sonos, and let go. But the volume continued to go down long after I let go of the button, and none of the other buttons would respond after that. The Homebridge log was completely taken up by pico long press events, in a loop until I restart Homebridge. After restarting, it will work normally for a few times, then resume the loop. I did change the repeat time to 100, but not sure if that matters? Attaching a log here for reference. Seems to be slightly better if I set repeat time to 400, but very delayed in stopping the action once I let go of the button. I think 100 is probably the longest I'd go for a volume action like the one I'm performing for this, but wondering if that's too fast for the plugin to catch up?

homebridge log.txt

rnilssoncx commented 2 years ago

You're likely overwhelming the system with the 100ms repeat. HomeKit isn't exactly fast, and NodeJS is not truly multi-threaded.

My guess is that your Homebridge is so busy processing the events at 100ms it isn't keeping up with the rest of its work and misses the release message.

I will put in a repeat cap later today that by default stops at 10. That will resolve the issue you're seeing, but you still may have other problems with other Homebridge plugins while it's repeating when you set such a low value.

rfiorentino1 commented 2 years ago

I need to do more testing to confirm this, but it seems like it’s only those top and bottom buttons that are doing it, if I assign the same actions to different buttons it’s totally fine.

rnilssoncx commented 2 years ago

It's possible that a long press on a bottom button won't send the release command after a period of time. A long press on it puts it into config mode.

Regardless, the repeat cap will fix it.

rnilssoncx commented 2 years ago

The plugin is updated to with a repeatmax setting. Default is 10, and it can be set per pico remote. If you have any further issues, please open up a new issue.

Thanks!