Best way to handle physical switch configuration? [Button->RPI->MQTT->HA)

Dear community

After using tablets and mobile phones to toggle lights, covers, szenes my wife pushes me to install the physical button switches in each room… (she was pretty patient for a long time)

I managed to send a message using nodered on RPI over MQTT to HA with the payload “B1_1” (button 1, 1 click), “B1_2” (button 1, 2 click), “B1_3” (button 1, 3 clicks), “B1_H” (button 1, hold), “B1_R” (button 1, release) for each button…- If easier, I can send an identifier of each button inside the payload together with the type of press or by using individual topics…

Now my problem/question:
What would be the best way to link the individual wanted actions to each of the buttons with the desired type of click? I know this could be done using the “Automation” module, but this would excessively fill the automation.yaml and make it pretty chaotic? Any way to catch all messages of a given MQTT topic and pass the parameter into a script?

Thanks a lot for your feedbacks in advance
Dave

I’m using node red exclusively for all automation now. For this use case you can use a switch node with different output per click type (single, double etc).

An example here:

Thank you for your fast answer hijinx :slight_smile:

So you recommend doing the configuration for each button press on nodered-side than inside HA? I thought it might be easier to get the configuration for all the buttons at the same place.

I already got the flow for my button press, but as they run on separate controller as the HA-server, I will have to start scenes over mqtt as well… lights I could directly toggle over my knx gateway…

But the main thing I wanted to achieve is to create some kind of mapping, where I could use perhaps a long click on the third button to enable something like a submenu and let it blink (works by sending “L1_B” over mqtt to the button) and then map another function to the button 1 single press until button 3 is long pressed again to quit that submenu…

Hope this wasn’t too confusing :wink: When I want to achieve this, the node-red config will become pretty complex too…

So maybe best would be some sort of middleware, a mysql-php based script to hold all those commands and actions… there is no module or other way to achieve this inside HA?

I only ever used the built in automations capability via yaml, and node red (via the hassio addon).
I much prefer nodered.