Button press with two buttons

Anyone know how I can achieve a “third” button out of two physical ones by pressing, double pressing or holding in the two at the same time? I have multiple Shelly’s around the house with two buttons and would love to have this feature. I have some aqara ZigBee switches that have this and it’s super neat.

Double click: Binary Sensor Component — ESPHome
Multi click: Binary Sensor Component — ESPHome

Probably best with a Template Binary Sensor — ESPHome

Thanks for you reply
Double click (all multiclicks both predefined and customized) I have working. Its the two buttons at the same time I’m after. As on the aqara switches there is both single press, double and hold with two buttons.
Playing around with templates might have some solution, although I was wondering if there was anyone out there with one already. But just to entertain the though on how it would be done.

  • I’m guessing I’d have to remove the logic on the existing buttons and create three virtual ones
    1. only left pressed
    2. only right pressed
    3. both pressed
  • From these virtual buttons it should now be possible to create all the functions I need with the use of the e.g. multipress
  • There may be some bugs with this approach as one button might be registered slightly before the other, specially on double press. This would have to be handled with some sort of filter or timer

I would just leave the “real” ones as they are and just add a third “virtual” (template) one which triggers when both a pressed

This way the actions of all three buttons “left”, “right” and “both” would all get triggered at the same time? Not really useful in that case.

Why would it?
Where do you need the action of the “third” button to be?
Does in need to run local on the ESP or is it a HA service?

Simultaneous needs to be defined a little better here. It would be a function of how consistently a human can do it, but then there’s also the delays of your local network and HA’s processing (the state engine). You could probably get this down to the same second on the receiver’s side, but one wil need to do some testing.

Or is this one device with two buttons? The reasoning above would still hold though, at least in part. I don’t know the Aqara switches, but if the buttons are indeed on the same device, then it’s probably a case of the simultaneous button presses being detected in hardware and a unique event for that emitted — no ambiguity in that case.

In other words, if say button 1 is pressed just slightly before button 2, then you also need to prevent whatever must happen when button 1 is pressed by itself. Secondly, you need to wait for button 2’s press. You could do this with an automation that triggers on either and then waits for the second.

I think you are correct on all accounts. The Shelly’s (esp hardware) I’m using have two physical buttons on one device running ESPHome, so no need to send this via api, everything can be done in the ESP itself. Even the single button press would need to get some delay added to their actions to give time for a possible second button to be pressed. I don’t think the templates would be too complex. I’ll post here if I come up with something. Was hoping though that this would already have been solved by someone either by some example code or that there was an integration in ESPHome that I’ve missed.

Does the actions need to happen in the ESP or can they run from HA?

They need to all run in HA. Mostly lights, some blinds, calling the robot vacuum to that room etc .

In that case it should be rather simple I think.

Each button is a binary sensor in HA.
Each button has a automation where you trigger on state on, for 0.5 seconds.

The both button press is an automation on state on and the condition is that the other button is also on.