Remote Raspberry Pi GPIO Switch

Does anyone have any tips on how to set up a remote raspberry pi GPIO switch? Its fairly obvious how to do it on the primary pi, but id like to make a sensor that uses the switch in another room with a secondary pi.

Just the sensor on the secondary pi, not run HA

Has anyone done this?

Ive been looking into doing this. Common route seems to be setup the pi and sensors / buttons / etc. and then have python pass the info to your HA instance through MQTT.

HA has MQTT built in and there are sensors/switches/etc. in existing components that can use the MQTT input. However, I haven’t found a good set of instruction on how to set it all up.

1 Like

You can setup a local website with a php file that calls the GPIO. The php script for activating the GPIO 6 is below, save it as switchon.php and put it in your /var/www directory. In your HA configuration, add a command line switch with the on url as

command_on: ‘curl -k “http://ipaddressofpi/switchon.php”’

but replace ipaddressofpi with your raspberry pi address.

<?php
 system ( "gpio -g mode 6 out" );
 system ( "gpio -g write 6 0" );
?>

Use Eventsteam component.
Publish from second pi
Receive on main pi
Setup switch on second pi and main can switch it’s state using evenstream

You can try setting up a slave on the RPi and the switches should appear in the master’s interface. I did manage to do this with an rpi_rf but haven’t tried it with gpio.

I used the instructions on this page:

I used this https://github.com/flyte/pi-mqtt-gpio/tree/develop

I use that and it works really well.