Physical On/Off button to GPIO relay output

Hi people,
I just started using Home Assistant with a Raspberry Pi 3 but I’m stuck. I am going to use this project for water gardening so I have connected a four relay board to the Pi pins, and I can turn them on and off from the GUI.
What I need and can’t seem to figure it out is how to connect a physical switch to the Pi and when it is pressed to ON it will send a signal to other Pi pins and power on some of the relays.
To understand better, this will be mounted in the garden and when I press the physical button two of the relays (water pomp and valve) will be put to ON and get water trough a pipe when needed. The rest of the relay will be managed trough Home Assistant software buttons to water the lawn and the garden. I still have to create the scheduler and everything but that’s another story for another time.

Any ideas will be welcome


Have you seen this page?

I know there were historically some issues with HA reading GPIO status:

Not sure if this is considered fixed or not. I found other ways to get what I needed so I never followed up.

The type of schematic this guy did I also taught about it. It is actually putting the relays in ON mode by touching ground with the necessary pins, but I wanted to do this through the Pi.

I search more and see what I can find.

This is pretty simple and straight using the gpio posted above you have a choice between a switch and a binary sensor.

A switch like a light switch with an off and on position. These usually have to be physically toggled on/off. Press once stays in on position until you press it again.

A binary sensor is a switch that activates for as long as you press the button. As soon as you lift your finger it goes to off. This can be used as a normal on/off switch like above you will need to configure it to do that. It’s not a big deal.

You could also consider using esphome instead. The micro controllers are cheap, $2-6 dollars and are well suited for this task. It’s well documented and has many outputs so it can control pumps, valves, temp/humidity, you name it. There are also numerous esphome garden projects to get ideas and diagrams. The wiring on a pi will be very similar.

1 Like

Thank you for your response. I saw a lot of videos where the ESP device is used, and I will use it once I get more comfortable using automations -since I just started-.
I guess I will use the article Tom send for the ON/OFF button since I cannot delay the irrigation, and buy another Pi just for learning.

Thanks guys for your help.