Remote Raspberry Pi GPIO

I was getting this error if the remote RPi was started after my Hassio RPi, if you make any changes or restart the remote RPi you have to restart HA for it to reconnect, hope that helps.

1 Like

I’m also having an issue where switch output pins are high when off and the invert_logic option makes no difference.

This works in the rpi_gpio component on Hassio with invert_logic set to false (default) or true but is inverted in remote_rpi_gpio and setting the option either way doesn’t help.

Any help on this would be appreciated.

Thanks for the tip, I confirm that it is visible now on HA. Summary of what I did:

  1. Enabled Remote Access on te remote pi.
  2. Set the pigpio to run at start with command line: sudo systemctl enable pigpiod
    (see gumby2 post above)
  3. Restart the Remote Pi
  4. Add the Rpi to Configuration.Yaml
    5.Restart HA
    You should be good to go
1 Like

Is this integration really so unfinished that I have to restart HA after the RPi restarts?
I have 3 RPi’s that, due to software memory leak problems, need to restart a few times a day (which isn’t too uncommon in the RPi world).
I need to access GPIO on these as switches.
Is there no way to make HA re-discover them after a restart?

1 Like

I’m having serious problems with this extension.
I’m running latest hass.io and v0.95.4.

I’ve had local GPIO configured, and changed these to remote_gpio now hooked up to another Pi.

It didn’t work at all, at first.
After much messing around following the instructions, I’ve now got 2 out of 4 to work.

As it is now, 2 of my remote GPIOs work, the other 2 generate this error:

2019-06-29 xx:xx:xx ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.1841103216] 'NoneType' object has no attribute 'on'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 121, in handle_call_service
    connection.context(msg))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1150, in async_call
    self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1172, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 194, in handle_service
    required_features
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 316, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 337, in _handle_service_platform_call
    await getattr(entity, func)(**data)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/remote_rpi_gpio/switch.py", line 82, in turn_on
    0 if self._invert_logic else 1)
  File "/usr/src/homeassistant/homeassistant/components/remote_rpi_gpio/__init__.py", line 56, in write_output
    switch.on()
AttributeError: 'NoneType' object has no attribute 'on'

Also, for the record, this is the error if you do not restart you Pi after restarting remote GPIO Pi:

2019-06-29 xx:xx:xx ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.1841103216] [Errno 104] Connection reset by peer
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 121, in handle_call_service
    connection.context(msg))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1150, in async_call
    self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1172, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 194, in handle_service
    required_features
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 316, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 337, in _handle_service_platform_call
    await getattr(entity, func)(**data)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/remote_rpi_gpio/switch.py", line 82, in turn_on
    0 if self._invert_logic else 1)
  File "/usr/src/homeassistant/homeassistant/components/remote_rpi_gpio/__init__.py", line 56, in write_output
    switch.on()
  File "/usr/local/lib/python3.7/site-packages/gpiozero/output_devices.py", line 159, in on
    self._write(True)
  File "/usr/local/lib/python3.7/site-packages/gpiozero/output_devices.py", line 60, in _write
    self.pin.state = self._value_to_state(value)
  File "/usr/local/lib/python3.7/site-packages/gpiozero/pins/__init__.py", line 247, in <lambda>
    lambda self, value: self._set_state(value),
  File "/usr/local/lib/python3.7/site-packages/gpiozero/pins/pigpio.py", line 219, in _set_state
    elif self.function == 'input':
  File "/usr/local/lib/python3.7/site-packages/gpiozero/pins/__init__.py", line 225, in <lambda>
    lambda self: self._get_function(),
  File "/usr/local/lib/python3.7/site-packages/gpiozero/pins/pigpio.py", line 192, in _get_function
    return self.GPIO_FUNCTION_NAMES[self.factory.connection.get_mode(self.number)]
  File "/usr/local/lib/python3.7/site-packages/pigpio.py", line 1317, in get_mode
    return _u2i(_pigpio_command(self.sl, _PI_CMD_MODEG, gpio, 0))
  File "/usr/local/lib/python3.7/site-packages/pigpio.py", line 978, in _pigpio_command
    dummy, res = struct.unpack('12sI', sl.s.recv(16))
ConnectionResetError: [Errno 104] Connection reset by peer

Also, I have 2 of these errors in my home-assistant.log at startup:

2019-06-29 xx:xx:xx ERROR (MainThread) [homeassistant.components.binary_sensor] remote_rpi_gpio: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 261, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 377, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/remote_rpi_gpio/binary_sensor.py", line 104, in update
    self._state = remote_rpi_gpio.read_input(self._button)
  File "/usr/src/homeassistant/homeassistant/components/remote_rpi_gpio/__init__.py", line 63, in read_input
    return button.is_pressed
AttributeError: 'NoneType' object has no attribute 'is_pressed'

@plonka2000 Are you using switch and binary sensor components on your remote rpi’s that are working?

Wondering if your switch output pins are ‘high’ when off which is the issue I’m having?

Hi, I’m using both the binary_sensor and switch configurations.

Sample of my sensor config:

- platform: remote_rpi_gpio
  host: 192.168.178.140
  ports:
    2: Pi Switch 1 (2) # not working, produces error
    3: Pi Switch 2 (3) # not working, produces error
    4: Pi Switch 3 (4) # works here
    17: Pi Switch 4 (17) # works here

And my switch config:

- platform: remote_rpi_gpio
  host: 192.168.178.140
  ports:
    2: Pi Switch 1 (2) # not working, produces error
    3: Pi Switch 2 (3) # not working, produces error
    4: Pi Switch 3 (4) # works here
    17: Pi Switch 4 (17) # works here

Both the GPIO 2 and 3 refuse to work, but GPIO 4 and 17 work fine.

This working/not working effect is effective on both binary_sensor and switch.

I’ve tested everything, changed the relay, wires, reinstalled remote Pi.

Seems like a software issue with the HA Pi.

Does anyone know how I can wipe the integration completely off my system, and try again?

I tried to locate device registrations, but there are none.

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

Wow, I have no idea how you figured any of that out, given the complete lack of documentation.
I gave up a while ago. While I appreciate all of the great work everyone involved in Home Assistant has done, as a non-programmer (but seasoned IT pro) this particular feature needs a lot of work before I ever consider trying again.

@plonka2000 Great that it’s all working for you now!
Can you please confirm that your switch outputs are ‘LOW’ when off and go ‘HIGH’ once turned on?
I have everything else working but switch output pins are still inverted, ie. Active LOW and nothing I’ve tried changes that.

Is there a way to power up/down the remote pi from HA?

yes, use ssh in a commandline switch.

I’m looking for a way to turn on/off my OctoPrint Pi, but for some reason I don’t have ssh access.

According to the octoprint web page OctoPrint.org - Download & Setup OctoPrint ssh is installed out of the box.

@BradAU sounds like you have a wiring problem.

If I’m understanding correctly, the “on” is “off” for you.

On your relay, you need to move the wires to the other connection ports. There are 3, so the middle and the other vacant port.

Alternatively, you can invert_logic to your config like:

- platform: remote_rpi_gpio
  host: 192.168.178.140
  invert_logic: true # <- this here
  ports:
    17: Pi Switch 1 (17)
    18: Pi Switch 2 (18)
    22: Pi Switch 3 (22)
    23: Pi Switch 4 (23)

@The_Penguin It’s not rocket science, dude.
If you’re a “seasoned IT pro”, this really shouldn’t be much of a challenge for you. I used google.

@plonka2000 The wiring isn’t the problem, the gpio pins on the remote RPi are high when the switch is off, also the invert_logic option doesn’t work. There appears to be an issue with the integration, have raised an issue on HA Gihub.

Ok, but I had the same problem with my relays, and switched the wires, as I said above.

No problems after that.

I also tested the invert_logic function before I switched wires, and it does work.

maybe you have a different issue. ¯\_(ツ)_/¯

Maybe it’s because you use a 5v relay board. Try to connect the power of the relay on the 3.3V of the raspberry.
The board switch on the relay because the photocoupled component notice a different voltage from 3.3v of the gpio and the 5v of the power.