Rpi_gpio alternatives

Hi, do you know any alternatives to rpi_gpio with host GPIO support?
Unfortunately rpi_gpio is no longer being developed and is missing several components.

p.s. I’m using Home Assistant OS

it will not work on Home Assistant OS?

It will work on a pi with GPIO connected, but no HA OS does not allow extra software to be run unless in an addon.

Necromancer here.

As the Thread is called “Rpi_gpio alternatives” I’ll hijack it to ask, if there are any good alternatives with REMOTE support.
Everybody keeps telling that “rpi_gpio” is the replacement for “remote_rpi_gpio” - but it’s completey lacking the remote part. So it was never a replacement.

Anyway… need to control the GPIOs on remote RPis.
I know how to do it in Python, but I’m seaching for something, that integrates nicely into HA.

Thanks.

The link I posted above will do that via mqtt:

WAAAAAAY too complicated.
Not that I’m not able to do it.
But I don’t want to configure this on all my 12 remote/satellite RPis. INDIVIDUALLY!

The gpiod is running on all of them.
So a central configuration and controlling from my central Pi with HA is the thing I want.
I mean, remote_rpi_gpio was exactly that!

  1. IP
  2. #GPIO: “Name”
  3. profit!

Why did they let such an easy and useful little helper die?! :cry:

if you run HomeAssistant on the satellite RPi, then you can make its entities available through: remote homeassistant

I learned about that yesterday, yes.
But since the remotes are only Pi Zeros and are already running Rhasspy, they don’t have enough resources left.
They’re already swapping, which isn’t good… but with only 512 MB RAM it’s nearly impossible to avoid that…

Thanks for the idea anyways, appreciate it.


Unrelated to the topic, but related to my post:
Perhaps I can free up RAM if I can get rid of the docker container for rhasspy with the patch or the forked repo from this:

in that case you can set up a simple server on the satellite and query it via RESTful Command

1 Like

Yeah, also already thought a bit about that.
A little server running on the satellites, np with python.
That would be a possibility, yes.
Thanks for the input.

I was about to set up a generic shell script, that gets some parameters and feeds it to an python script (which is doing all the work).
But I found “pyscript” in HACS. With this extention I can have a single python-script that gets some parameters and is callable as a service in HA.
At the moment that sounds very pleasent to me.
I already startet setting it up - but the next few days I won’t be able to continue on this.

I will come back here.
And if it works, I will happily provide the script(s) and related code snippets.
We will see.

I finally found the time to play around with this.

The approach with pyscript (or my imagined shell-scrip approach) have one problem:
They won’t “stay on” continuesly.
They’re more of a “one-shot” fire and forget thingy.
But for my current projects, that is enough for me:

  • fire it up
  • it switches on a relay
  • sleeps for a couple of seconds
  • script ends, everything goes out-of-scope and the relay switches off again

For a more complex setup in which you actively want to trigger the relays on and off or get the states of them and so on, this won’t be enough.
The approach with a long (always) running script with p. e. an REST-server on top to trigger the functions is the better one - but for now I don’t need it.
But I surely will do sooner or later.


So for now:

Examples:
Generic (I started with than and know it doesn’t make sense all along, just for demonstration purposes):

from gpiozero import OutputDevice
from gpiozero.pins.pigpio import PiGPIOFactory

@service
def remote_gpio(host=None, pin=0, action=None):
  factory = PiGPIOFactory(host=host)
  device = OutputDevice(pin, active_high=True, initial_value=False, pin_factory=factory)

  if action == "on":
    device.on()
  else:
    device.off()

  task.sleep(5)

I can run it in HA like this:

action: pyscript.remote_gpio
data:
  host: "rpi0-2W-1"
  pin: 17
  action: "on"

And another example I’m really gonna use (based on the first generic example):

from gpiozero import OutputDevice
from gpiozero.pins.pigpio import PiGPIOFactory

@service
def turn_on_light_for_interval(host=None, pin=0, time_in_sec=300):
  factory = PiGPIOFactory(host=host)
  light = OutputDevice(pin, active_high=True, initial_value=False, pin_factory=factory)

  light.on()
  task.sleep(time_in_sec)
  light.off()

And the service in HA:

action: pyscript.turn_on_light_for_interval
data:
  host: "rpi0-2W-1"
  pin: 17
  time_in_sec: 300

It’s not complicated stuff by any means, but for now I’m good.

pyscript has many more features:

  • you can use HAs information als variables in the scripts
  • scripts can be triggered by events, states and time
  • scripts can be active only for certain timespans

And perhaps it even has something to have a long-running service or entity than can be controlled.
I haven’t read the whole docs yet, so I don’t know what is possible and what not.

OK, as I said, I’m good for now.
Hope, my little input can be of help for somebody.


Even further: I forgot, that I wanted to have and use a neat little script in HA so that I can configure it with ease.

Again - no big deal in fact, but perhaps anyone will find it useful.

The configuration can than be done via UI, whenever the script is used:

Code:

sequence:
  - action: pyscript.turn_on_light_for_interval
    data:
      host: "{{ host }}"
      pin: "{{ pin }}"
      time_in_sec: "{{ time_in_sec }}"
fields:
  host:
    selector:
      text: null
    name: Host
    required: true
  pin:
    selector:
      number:
        min: 1
        max: 100
    name: Pin
    required: true
  time_in_sec:
    selector:
      number:
        min: 1
        max: 100
    name: Zeit in Sekunden
    default: 300
    required: false
alias: "[Lights] Remote GPIO-Licht eine bestimmte Zeit lang einschalten"
description: ""

You got me there… I was RESTless after your suggestion… :wink:
Sooo… my previous solution didn’t last very long (it works, but is limited… and I wanted MORE!).

I couldn’t hold my feet still, so I implemented the whole thing, just because I can :laughing:
https://community.home-assistant.io/t/restful-server-for-remote-gpio-control-and-ha-integration-examples