Setting GPIO output from NodeRed is broken?

Hi,

Does anyone have experience with controlling GPIOs of a Raspberry Pi from Node-Red?

UPDATE: I meant: “from the Node-red plugin in Hass.io

This should be simple and easy, but in my configuration it does not seem to work.

The configuration is
Home Assistant 0.97.2 on Hassio (I guess that is the dedicated OS) on a Raspberry Pi. In this configuration, HA runs in a container and the Node-Red comes as a plugin. HA and NR are on the latest versions (as of 20190815)

The Goal:
Simple: controlling a relay (on/of) that is connected to the GPIO on the RPI. It works if I use automations in the configuration.yaml file (or an included file). But I can’t get it to work from Node-Red

What works:
setting up a flow to control a relay that is connected to a GPIO pin using a “call service” node. I set the Domain to “switch” and the Service to “turn_on”. The node calls the turn_on service and the relay turns on as expected. Downside here is that I need a second “call service” node to turn off the relay. Not really intuitive, but it works.

What does not work: (this is the issue)
controlling a relay that is connected to a GPIO pin using a “RPI-GPIO out” node. The flow seems to work. When I change the state of the “Inject Node”, it passes a “0” or “1” to the RPI_GPIO node and the output state of the RPI-GPIO node changes from 0 to 1 (and back). Cool… but I see no event on the event-bus of Home-Assistant

It seems like Node-Red cannot command the GPIO system of the Raspberry Pi (however if I go via “call_service” and “switch”, as described above, then it works)

I have enabled:

logger:
  default: debug

Any tips on

  • how to enable additional debug logging,
  • or sharing of experience are greatly appreciated

thanks so much
chris

Same problem here on Rpi4 32 bit, new Hass.io installation

thanks for confirming Jeroen

Anyone any tips on how to troubleshoot this ?

I monitored /config/home-assistant.log but I did not see any errors. I can also not find any log files under /config/node-red

thanks,
chris

Because node red isn’t going to show anything there.

The proper way to do this is connect the gpio pins up to home assistant and use node red to call service on home assistant.

As it stands, all devices are passed through to home assistant and not node red. Node red doesn’t even know it’s running on a pi, and can’t see the gpio pins. Home assistant can and you should be using home assistant

@flamingm0e Thank you that makes sense

Would you have any tips on how to do that?
Pardon my ignorance, I’m pretty new to this
thanks,
chris

you said, however, in the OP, that:

That means it’s already connected to Home Assistant?

If so, you literally have a switch in Home Assistant that you can use in Node Red. It’s another entity just like every other entity in Home Assistant. The same as a sensor, switch, device_tracker, person, etc…You simply select that entity in a node in node-red.

@flamingm0e
Thank you for your advice
I think that that is what I have.
I was hoping for a cleaner solution

So, I defined binary_sensors like this:

  ports:
    20: gpio20  #_38
    21: gpio21  #_40

and switches like this:

  invert_logic: true
  ports:
    #00: gpio00  #_27  Reserved for ID_SD DO NOT USE
    01: gpio01  # pin_28
    02: gpio02  # pin_03
    03: gpio03  # pin_05

And as a trigger in Node-RED, I use the node: “events: state node” with an Entity ID of “binay_sensor.gpionn” (where nn is the GPIO number)
That works
It is just annoying that the GPIO nodes that are available in Node-RED don’t work on Hassio
chrid

GPIO Nodes only come “installed” because it’s the image for the pi. It actually has nothing to do with Hassio. Ignore the GPIO nodes.

I bet the problem mentioned in this post is confusing a lot of people, to solve it, I added an issue to Node Red Addon here: