Switching to node-red on Raspberry pi 3B from a Python 3 script

I now have Node Red v3.1.0 up and running on my Raspberry Pi running 64bit Bookworm

I had a script running in Python that would turn three sets of lights on and off continuously when and if the Alarm in the house went off, and would shut off when the Alarm was disabled.

In node-red I have the rpi-gpio in node, in my Flow connected to 6 Delays to turn the lights on and off 2 seconds apart.

When the alarm is on it turns the lights on in sequential order only once then again after the alarm is off.

I can't seem to figure out which node to use to keep the flow running continuously until the alarm is shut off.

Tried the "function" node with code inserted, but probably the wrong code that did not work.

Any help would be greatly appreciated.

Thank you
Richard

Hello @richard8901 , welcome to the forum.

Consider a flow like this which will send "ON" then "OFF" 2 seconds apart until it's reset.
It uses 2 trigger nodes - one to repeat the alarm signal every 4 seconds and one to send ON, wait and send OFF.

[{"id":"6a5630552e28e546","type":"inject","z":"f25b549c8bc73a59","name":"ALARM!","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":120,"y":60,"wires":[["2bc95c352e116d1e"]]},{"id":"ce3e7f2b328b5653","type":"inject","z":"f25b549c8bc73a59","name":"Reset","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":110,"y":100,"wires":[["480412d8c1e5da5b"]]},{"id":"2bc95c352e116d1e","type":"trigger","z":"f25b549c8bc73a59","name":"","op1":"ON","op2":"0","op1type":"str","op2type":"str","duration":"-4","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":460,"y":60,"wires":[["1af1544504f997b4"]]},{"id":"480412d8c1e5da5b","type":"change","z":"f25b549c8bc73a59","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":100,"wires":[["2bc95c352e116d1e"]]},{"id":"1af1544504f997b4","type":"trigger","z":"f25b549c8bc73a59","name":"On then Off","op1":"ON","op2":"OFF","op1type":"str","op2type":"str","duration":"2","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":510,"y":100,"wires":[["25adab300b9d6fb7"]]},{"id":"25adab300b9d6fb7","type":"debug","z":"f25b549c8bc73a59","name":"debug 458","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":100,"wires":[]}]

Are you saying that it was working previously but not after you upgraded?

That seem to work great.
I'll have to tweak a few thinks to hook it up to my input rpi-gpio in.
Will let you know.
Thanks for the help.

No, this is a new install on my Raspberry pi, never had Node - Red installed before.

You see that it does not matter what the inject nodes send?
Any message arriving at the "Resend" node will start the ON/OFF cycle.
Any message arriving at the "set msg.reset" node will stop the cycle repeating.

If the input is a GPIO true/false, a switch node can divert true to Resend and false to reset.

I tried the switch with True/False as shown.

When the alarm is on, it runs through the sequence only 2 times then quits.

When the alarm is shut off it runs through the sequence again another 2 times then quits.

I may have the switch programmed incorrectly.

Here is how I've programmed it.

image

Your switch node setup is hopelessly wrong. You clearly don't grasp the difference between such notations as msg.payload and flow.payload, boolean true and msg.true.

I recommend watching this playlist: Node-RED Essentials. In particular the chapters on working with messages and working with context.

After that, put a debug node on the output of your GPIO node. Set it to display the whole message object.
Does the message contain msg.true and msg.false?
What datatype is msg.payload?

Thanks jbudd for your advice.
Just got back to working on it.
Watched the video's, very informative, guess I missed those first time around.
I have the Alarm on working great, still working on the Alarm off.

1 Like

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