Count pressed buttons


I’m looking for a way to show the number of pressed buttons in Home Assistant.
As an example, I would like to check whether all 4 keys have been hung up. How can I do this with ESP Home?
Ideally, I’d like to see the number of keys hanging.

Thanks for your help and/ or hints.

There is a lot of information missing for us to understand what you are asking for and for us to help you.

Which informations do you need?

I have a running Homeassistant OS on my raspberry Pi4. ESPhome is running with two esp32 cams etc.
I built a board that activates buttons for each key which is hung up. Now i want to know a way to show an entitiy in HA which shows the number of pressed buttons. I don’t want to know if key 1, 2 and 4 is on the Board. I just want to know “3 keys are hung up”.
I’ve done this with an ESP32 which shows me the value on a HTML-Page. But i want this integrated in my HA. My programming was quick’n’dirty so I have to restart this project anyway, but I don’t have any experience with ESPHome other than using existing sensors etc.

So keys and buttons has some relation?
Where does the camera come in?
This is really confusing. Just start over and explain what you have

I only mentioned the cameras to show that the integration is already running.

yes there is a relation but it’s not important.
Hook 1 = key 1 = GPIO_X of ESP, Hook 2 = key 2 = GPIO_Y of ESP.
There are currently 4 hooks. But I’m not interested in knowing which Hook/ button is pressed.
I only need the count of pressed buttons as entity value

Nobody has an idea or a tip?

You need an automation and a input_number. The triggers would be your 4 switchs. The action would be input_number.increment when a switch goes to on. Then input_number.decrement when a switch goes off.

1 Like

I’m guessing your buttons are mapped to binary_sensors and show as such in HA.

Create an input_number in HA with an initial value of 0.


Trigger: state change on any of the 4 binary sensors
Action: with condition 1 - increments the input_number by 1
Action: with condition trigger.from 1 - decrements the input_number by 1

Viola !

1 Like

That’s perfect. I had forgotten that there is the possibility to only use the “state change” and not the state itself