Remote Raspberry Pi GPIO

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.

Thanks @cinquemic but that’s not the case, I’ve tried several different relay boards and 12V relay driver boards, all with the same result. I’ve also measured the GPIO pin output with a scope and it sits at 3.3V when off and pulls straight to 0V when switched on. As I’ve mentioned in previous comments the GPIO pins of the RPi running Hassio work perfectly but on a remote RPi they are inverted. I opened an issue on the HA GitHub so hoping it will be resolved soon.

How good is this remote binary sensor? I recently purchased a nodecmu, and a doorbell press only changes my sensor for max 2 secs… But the change in HA is instant, so that’s good…

Is this also instant when using remote gpio on a PI? I read in other threads , that’s based on scan interval training… So I can miss my doorbell hits…

Can anyone confirm this?? I was t to buy a PI, but I want to make sure the binary sensors changes are also instant

Thnx

hmm, i follow your guide, copy pasted that whole text, rebooted PI 3+ (debian lite)
restarted HA, confirmed id with that “pigs t” command but still this error :

  File "/usr/local/lib/python3.7/site-packages/gpiozero/devices.py", line 453, in _default_pin_factory
    raise BadPinFactory('Unable to load any default pin factory!')
gpiozero.exc.BadPinFactory: Unable to load any default pin factory!

how can we resolve that ?

hmm, seems the error is documented here :

If you receive an error such as gpiozero.exc.BadPinFactory: Unable to load any default pin factory! try changing the pinfactory from pigpio to mock , this adresses a known issue.

but i have no idea how to change that to “mock” ?