How do I check the state of a GPIO pin on startup?

I have a pin connection on the Pi 4 (ground to pin 35 in node-red-node-pi-gpio) that will be driven by a relay, so when the relay closes media playback starts, and when it opens, playback stops. The problem is on startup. I want it to start playback if the relay is closed on startup, but not if the relay is open. How can I check for that pin being open? There is no "through" on that node, so I can fire an "On startup" request to it.

Are you sure that it does not send an initial message on restart?

Didn't seem like it, because I restarted the Pi with a jumper cable on, and playback didn't start.

Sounds like you need a pull up/pull down resistor in your circuit. If the relay is open the pin is grounded or if relay is closed then pin is high or vice-versa. Then check pin status on startup.

But the pin is up and down as it should be. It's the startup detection I don't know how to do. Sort of like "if pin 35 = 0 --> start playback". The question was that I don't know how to check if it's up or not.

Make sure that in the GPIO node you have selected this option
image
That tells the node to send you a message on startup.

Thank you! That was it! :slight_smile: One slight problem, it seems like on startup this happens before the media program is ready. Is there a way to delay until the process mediacenter26 is running?

Since you only want to delay the first message, you could use node-red-contrib-queue-gate, set it to startup in the Queueing state. and when you know that the media program is ready then send an Open message to the gate to allow the initial message through.

Thanks, I'll look into that!