GPIO state crazy?

Hello friends,

I installed at my Rasperry 3B+ a 8 chanel relay card.
Standard relay, not any SSR.
on the Relay card is a LED for each relay - state LED. I think you know that.

If the Pi is off, the relay is off. If I start the pi and Nodered starts, the Relay is activ (LED is on and Relay closed).but in my Nodered I can see there is a 0 (zero) as GPIO state.

If I press to activate the relay, the LED goes off.
This is revered.
I don´t know where is my failure.
Can somebody support me?
Installed node: node-red-node-pi-gpio

[{"id":"1bd00a5b.7e9796","type":"tab","label":"Säureumwälzung","disabled":false,"info":""},{"id":"277fac78.6b7214","type":"rpi-gpio out","z":"1bd00a5b.7e9796","name":"Relay8 GPIO21","pin":"40","set":true,"level":"0","freq":"","out":"out","x":1200,"y":480,"wires":[]},{"id":"a00e4f49.dadbc","type":"inject","z":"1bd00a5b.7e9796","name":"Säureumwälzung täglich um 16:30","repeat":"","crontab":"30 16 * * *","once":false,"onceDelay":"","topic":"","payload":"","payloadType":"date","x":220,"y":420,"wires":[["d0b4e949.15c288"]]},{"id":"6268a7aa.319078","type":"debug","z":"1bd00a5b.7e9796","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":210,"y":240,"wires":[]},{"id":"d0b4e949.15c288","type":"trigger","z":"1bd00a5b.7e9796","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"60","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":450,"y":420,"wires":[["277fac78.6b7214","271b334d.a7153c"]]},{"id":"662236a.76077c8","type":"switch","z":"1bd00a5b.7e9796","name":">15 A Ladestrom","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"15.000","vt":"num"},{"t":"lte","v":"14.999","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":120,"wires":[["17b86286.7d856d"],["5795c302.f1f80c"]]},{"id":"9a643899.cacf68","type":"switch","z":"1bd00a5b.7e9796","name":">30 A Ladestrom","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"30.000","vt":"num"},{"t":"lte","v":"29.999","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":280,"wires":[["2e1440dd.456e7"],["8b03b5e5.791228"]]},{"id":"3921b1fe.54d44e","type":"trigger","z":"1bd00a5b.7e9796","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"60","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":990,"y":120,"wires":[["49f9263a.578538","277fac78.6b7214","eb94fe9d.1b1d1","271b334d.a7153c"]]},{"id":"49f9263a.578538","type":"function","z":"1bd00a5b.7e9796","name":"","func":"if (msg.payload == \"off\")\n\tcontext.state = 0;\nif (msg.payload == \"on\")\n\tcontext.state = 1;\n\nif (context.state == 1)\n{\n\tif (msg.payload == 0)\n\t\treturn msg;\n\telse\n\t\treturn;\n}\nelse\n\treturn;","outputs":1,"noerr":0,"x":800,"y":180,"wires":[["e86f946a.a00ab8"]]},{"id":"94d2e1c8.7fca","type":"switch","z":"1bd00a5b.7e9796","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":750,"y":120,"wires":[["49f9263a.578538","3921b1fe.54d44e"],["49f9263a.578538"]]},{"id":"e86f946a.a00ab8","type":"delay","z":"1bd00a5b.7e9796","name":"Pause 1 h","pauseType":"delay","timeout":"1","timeoutUnits":"hours","rate":"1","nbRateUnits":"","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":940,"y":180,"wires":[["3921b1fe.54d44e","d82af571.a2f1f8"]]},{"id":"b1bebb9a.5621f8","type":"trigger","z":"1bd00a5b.7e9796","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"60","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":970,"y":280,"wires":[["4d881429.64a61c","277fac78.6b7214","73751a82.229be4","271b334d.a7153c"]]},{"id":"4d881429.64a61c","type":"function","z":"1bd00a5b.7e9796","name":"","func":"if (msg.payload == \"off\")\n\tcontext.state = 0;\nif (msg.payload == \"on\")\n\tcontext.state = 1;\n\nif (context.state == 1)\n{\n\tif (msg.payload == 0)\n\t\treturn msg;\n\telse\n\t\treturn;\n}\nelse\n\treturn;","outputs":1,"noerr":0,"x":800,"y":340,"wires":[["c1090c32.34531"]]},{"id":"947bdad1.059af8","type":"switch","z":"1bd00a5b.7e9796","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":750,"y":280,"wires":[["4d881429.64a61c","b1bebb9a.5621f8"],["4d881429.64a61c"]]},{"id":"c1090c32.34531","type":"delay","z":"1bd00a5b.7e9796","name":"Pause 40 min","pauseType":"delay","timeout":"40","timeoutUnits":"minutes","rate":"1","nbRateUnits":"","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":960,"y":340,"wires":[["b1bebb9a.5621f8","21798f15.2af11"]]},{"id":"17b86286.7d856d","type":"trigger","z":"1bd00a5b.7e9796","name":"on","op1":"on","op2":"0","op1type":"str","op2type":"str","duration":"10","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":610,"y":120,"wires":[["94d2e1c8.7fca"]]},{"id":"5795c302.f1f80c","type":"trigger","z":"1bd00a5b.7e9796","name":"off","op1":"off","op2":"0","op1type":"str","op2type":"str","duration":"10","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":610,"y":160,"wires":[["94d2e1c8.7fca"]]},{"id":"2e1440dd.456e7","type":"trigger","z":"1bd00a5b.7e9796","name":"on","op1":"on","op2":"0","op1type":"str","op2type":"str","duration":"10","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":610,"y":280,"wires":[["947bdad1.059af8"]]},{"id":"8b03b5e5.791228","type":"trigger","z":"1bd00a5b.7e9796","name":"off","op1":"off","op2":"0","op1type":"str","op2type":"str","duration":"10","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":610,"y":320,"wires":[["947bdad1.059af8"]]},{"id":"eb94fe9d.1b1d1","type":"debug","z":"1bd00a5b.7e9796","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1190,"y":120,"wires":[]},{"id":"d82af571.a2f1f8","type":"debug","z":"1bd00a5b.7e9796","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1170,"y":180,"wires":[]},{"id":"73751a82.229be4","type":"debug","z":"1bd00a5b.7e9796","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1170,"y":280,"wires":[]},{"id":"21798f15.2af11","type":"debug","z":"1bd00a5b.7e9796","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1170,"y":340,"wires":[]},{"id":"ea8f3e0c.fc4eb","type":"link in","z":"1bd00a5b.7e9796","name":"Batterie Ladestrom / Wert von BMV Batteriemonitor","links":["7c4b565d.138a28","f97f2293.0dd"],"x":175,"y":120,"wires":[["662236a.76077c8","9a643899.cacf68","6268a7aa.319078"]]},{"id":"4de663a2.78764c","type":"comment","z":"1bd00a5b.7e9796","name":"Batterie Ladestrom / Wert von BMV Batteriemonitor","info":"","x":230,"y":80,"wires":[]},{"id":"271b334d.a7153c","type":"ui_text","z":"1bd00a5b.7e9796","group":"6282d61a.28e958","order":0,"width":0,"height":0,"name":"","label":"Relais aktiv","format":"{{msg.payload}}","layout":"row-spread","x":1230,"y":580,"wires":[]},{"id":"34317b33.023024","type":"ui_button","z":"1bd00a5b.7e9796","name":"","group":"6282d61a.28e958","order":9,"width":0,"height":0,"passthru":false,"label":"Ralais 60 Sek an","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":770,"y":580,"wires":[["d0b4e949.15c288"]]},{"id":"6282d61a.28e958","type":"ui_group","name":"Pumpe","tab":"9cfaccc0.6acbf","order":2,"disp":true,"width":"6","collapse":false},{"id":"9cfaccc0.6acbf","type":"ui_tab","name":"PV","icon":"dashboard","disabled":false,"hidden":false}]

Thanks Herbert

It is common for relay boards to use the 0 output state to close the relay. That is because the GPIO pulls actively low, but floats up on a pullup resisto, so to energise the photo isolator on the relay card it is usual to use the pulldown to pull current through the opto isolator.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.