Remote Raspberry Pi GPIO

Also, for those looking for remote host Pi setup instructions, here are some assuming you have a fresh Raspbian with ssh enabled.

This is what I did, step by step:

sudo -i
apt-get update && apt-get upgrade -y
apt-get install pigpio

rm /etc/systemd/system/pigpiod.service.d/public.conf
nano /etc/systemd/system/pigpiod.service

copy and paste everything below and save (ctrl-x):

[Unit]
Description=Pigpio daemon
After=network.target syslog.target
StartLimitIntervalSec=60
StartLimitBurst=5
StartLimitAction=reboot

[Service]
Type=simple
ExecStartPre=/sbin/sysctl -w net.ipv4.tcp_keepalive_time=300
ExecStartPre=/sbin/sysctl -w net.ipv4.tcp_keepalive_intvl=60
ExecStartPre=/sbin/sysctl -w net.ipv4.tcp_keepalive_probes=5
# Don't fork pigpiod
ExecStart=/usr/bin/pigpiod -g
ExecStop=
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

check everything works:

systemctl daemon-reload
systemctl status pigpiod.service
systemctl enable pigpiod.service
systemctl restart pigpiod.service
systemctl status pigpiod.service

if everything reads as active (running):

pigs t

If you get an id back, looks all good:

reboot

When it comes back, you should go restart HA.

UPDATE: I GOT EVERYTHING WORKING

Ok, so I finally got this to work (sort of, but effectively yes).

Followed all the steps in my last post ^^ but changed all my GPIO ports around.
It would seem (At least for me) that some GPIO ports have issues, unknown if this is software or hardware.

In particular, GPIO 2, 3 and 27 I am now avoiding.
Now I’m using GPIO 17, 18, 22, and 23 in my config and seems to work.

Sample of my sensor config:

- platform: remote_rpi_gpio
  host: 192.168.178.140
  ports:
    17: Pi Switch 1 (17)
    18: Pi Switch 2 (18)
    22: Pi Switch 3 (22)
    23: Pi Switch 4 (23)

And my switch config:

- platform: remote_rpi_gpio
  host: 192.168.178.140
  ports:
    17: Pi Switch 1 (17)
    18: Pi Switch 2 (18)
    22: Pi Switch 3 (22)
    23: Pi Switch 4 (23)

I setup a group:

  remote_gpio:
    view: no
    name: Remote GPIO
    control: hidden
    entities:
      - switch.pi_switch_1_17
      - switch.pi_switch_2_18
      - switch.pi_switch_3_22
      - switch.pi_switch_4_23
      - binary_sensor.pi_switch_1_17
      - binary_sensor.pi_switch_2_18
      - binary_sensor.pi_switch_3_22
      - binary_sensor.pi_switch_4_23

Now everything works!
No errors in log:
image

It is also worth noting that the GPIOs I’ve used here (17, 18, 22 and 23) are the most consistent across Pi revisions, so I might recommend those to others. :+1:

2 Likes