GPIO output with node-red

Hi to all,

I am using node-red with a switch output on GPIO on my Raspberry Pi 3B+.

Connection to the websocket is fine. Connection with the GPIOD server on the other side is also fine. In between I have captured the slots.state from the msg object and transformed the off/on to a number value 0/1.

But I’m still a noob with node-red. Why am I stuck? I’ve tried to change msg.slots.state to msg.payload but I still get errors…

Try using a single change node set up with three rules inbetween the websocket and the gpio node instead of two:
1st rule

2nd rule

3rd rule

Thanks @JGKK, this made it!

I had tried the other way i.e. set msg.slots.state to msg.payload, which seemed more logical to me.

I still have an error in debug from Test GPIOD which claims “errors.invalidinput : NaN” but the physical switch behind it works.

Did you change it to use only one change node like i suggested because when you use two like above in your image one for off and one for on each msg will be send twice to the gpio node and the one from the opposite change node that doesn’t apply will trigger that error.

You have to read the rules in a change or switch node like a sentence. So set a to the value of b etc.

That’s perfect now.

I have a question to be clear: how are the sentences read? One after the other, I suppose like in a code with several “if”. Then at the end the logic should be “set a from the value of b”.

Because “from” is not an option, my logic was to reverse the sentence in “set b to the value of a”. But apparently my logic is wrong.

Exactly like it is stated in the ui.
Set msg.payload to the value of msg.slots.value.

So think of the change node as beeing used to change or replace values and the switch mode is more like a classic if condition.
I really recommend you watch the youtube series on basic concepts by Nick who is one of the main maintainers:

Also have a look at the cookbook part of the documentation:

1 Like

Hi @JGKK, can you help me further on the same flow?

I am trying to analyse intents with a switch node after receiving the json from my ws://localhost:12101/api/events/intent connection

The property of my switch node is:
and for the time being I just have 2 possibilities in my switch:
1/ == string.SwitchState
2/ otherwise

I have linked 1/ to my previous change node linked to the GPIO output and 2/ to a template linked to an http request node, so that I hear the message “unknown command” if this is the case.

Problem is I can hear the message even if is SwitchState. And if I change string.SwitchState for msg.SwitchState I get an Invalid input in the debug pane but no vocal message if is not SwitchName

I don’t know what to do

The switch node has an option to stop after the first match. Choosing that option should work for what you want to do.

1 Like

Thank you @moqart I had tested that also without success.
But you helped another way: I had and I changed for as in your example and this made it.
It makes fun!