Relay switch via dashboard led

Hey people, I am trying to config a switch that can run an on/off python relay script and display a light on dashboard to show if on or off. I have tried several nodes but admitting defeat and need some guidance

Current flow is just 2 buttons running 2 pythonshell nodes and that has been the only way i could get the relay to switch on/off. python,pi and node red, all very new to me.

I keep reading their is an easier way to achieve this using mqtt or execute but i haven't been able to figure it out.

What make/model of relay switch is it, is it a retail item or something that you have built?
(there may be an easier way to control it).
Oh, and welcome to the forum @duffmans!

Thanks for the welcome @Paul-Reed

The relay I bought and its a 5v 4 channel with optocoupler, I wanted the option to control some pc fans independent of each other (or all together) for a pc workbench. Im sure their are controllers out their but i had a pi that the kids showed no interest in and had plenty of time on my hands so built a little enclosure for it all so i am keen on the completing this final hurdle.

It is all built and i can remotely control 3 fans from a node red dashboard. But i can't figure out how to display the status of the pythonshell node on dashboard. I have seen and played with some other flows but couldn't implement them into my own.

So are you hard wiring the optocoupler's to the pins of a Raspberry Pi?
Your mention of mqtt suggested that your relay board was wifi connected.

I am yes,pi4 with wifi and powering via a 5v pin direct from pi. I haven't been able to figure the mqtt function out to be honest.

Hi @duffmans.

I think you may need to step back a bit at this point with what you are wanting to do.

Couple of things of slight concern to me:
The RasPie puts out 3.3v.
Be careful not to try and source too much from the pins either.

Can you draw a basic circuit with which you are driving the relays/opto couplers?
(At a pinch use a print program to draw what you have)

Basically you are activating a GPIO pin and that will turn the fan on or off.

Before you start with MQTT and all that, it may be a good idea to get the relays working manually from the machine.

To do this you will (probably) need the raspigpio node.
node-red-node-pi-gpio

That will allow you to control the GPIO pins.
Be it via direct control or MQTT.
Install that node and make a little flow to control the fans from a flow on that machine and work up from there.

It may save you a lot of headaches.

Because once you have done that and see it working, it is very easy to simply add a MQTT in node and control it from a remote machine.

Basic idea for circuit:
The + is +5v. - is 0v. You may want to add fly-back diodes around the relay and its contacts.
The resistor is needed to limit current through the LED and not burn out the RasPie's GPIO pin.

But as said: This is a basic idea of how to do it.

GPIO-FAN-idea

1 Like

@Trying_to_learn he says " It is all built and i can remotely control 3 fans from a node red dashboard. But i can't figure out how to display the status of the pythonshell node on dashboard. ". From that I take it that the basic electronics is working.

1 Like

Sorry. My bad.

To use mqtt, you would need some wifi connected hardware, such as a shelly relay or even adding a wifi equipped module to your existing relays.
The advantage of using mqtt is that you would not need to physically connect the pi to the relay, so no wires. Your pi would send instructions to the relay via wifi instead.

But back to your current project, can you paste your current flow, so that we can see what you have so far. - How to share code or flow json

1 Like

Sorry been a busy few days, I honestly did not know about the wifi relays and would of probably been the better route to take for me. I would still really like to finish what i started tho.I have managed to get the fans working and an led status for on/off on the dashboard. But my plan all along was for a switch so i want a switch :grinning:

my current flow using 2 buttons instead

[{"id":"a5e2be61.e18a2","type":"pythonshell in","z":"a5a4c878.efcb48","name":"relay 1 on","pyfile":"/home/pi/relay1on.py","virtualenv":"","continuous":false,"stdInData":false,"x":360,"y":220,"wires":[[]]},{"id":"18a18085.1dcfff","type":"ui_button","z":"a5a4c878.efcb48","name":"","group":"42ec51ce.866f6","order":3,"width":1,"height":1,"passthru":false,"label":"on","tooltip":"","color":"black","bgcolor":"green","icon":"","payload":"0","payloadType":"num","topic":"","x":180,"y":220,"wires":[["a5e2be61.e18a2","4ae8f6a9.072b38"]]},{"id":"4c3bce45.5a496","type":"ui_button","z":"a5a4c878.efcb48","name":"","group":"42ec51ce.866f6","order":5,"width":1,"height":1,"passthru":false,"label":"off","tooltip":"","color":"black","bgcolor":"red","icon":"","payload":"1","payloadType":"num","topic":"","x":190,"y":340,"wires":[["46eceef8.f5205","4ae8f6a9.072b38"]]},{"id":"46eceef8.f5205","type":"pythonshell in","z":"a5a4c878.efcb48","name":"relay 1 off","pyfile":"/home/pi/relay1off.py","virtualenv":"","continuous":false,"stdInData":false,"x":360,"y":340,"wires":[[]]},{"id":"4ae8f6a9.072b38","type":"ui_led","z":"a5a4c878.efcb48","group":"42ec51ce.866f6","order":4,"width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"red","value":"1","valueType":"num"},{"color":"green","value":"0","valueType":"num"}],"allowColorForValueInMessage":false,"name":"","x":430,"y":280,"wires":[]},{"id":"42ec51ce.866f6","type":"ui_group","z":"","name":"main","tab":"61e0a8ed.2916f8","order":1,"disp":true,"width":8,"collapse":false},{"id":"61e0a8ed.2916f8","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

Something like this?

switch

[{"id":"28d53a94.df1696","type":"ui_led","z":"c9c4eeb8.bad8e","group":"cb6df7f2.076ee8","order":4,"width":1,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"red","value":"1","valueType":"num"},{"color":"green","value":"0","valueType":"num"}],"allowColorForValueInMessage":false,"name":"","x":370,"y":2360,"wires":[]},{"id":"ef7cf5b3.be7b78","type":"pythonshell in","z":"c9c4eeb8.bad8e","name":"relay 1 on","pyfile":"/home/pi/relay1on.py","virtualenv":"","continuous":false,"stdInData":false,"x":540,"y":2340,"wires":[[]]},{"id":"f9666944.150c38","type":"pythonshell in","z":"c9c4eeb8.bad8e","name":"relay 1 off","pyfile":"/home/pi/relay1off.py","virtualenv":"","continuous":false,"stdInData":false,"x":540,"y":2300,"wires":[[]]},{"id":"d9b795c4.968428","type":"ui_switch","z":"c9c4eeb8.bad8e","name":"","label":"switch","tooltip":"","group":"cb6df7f2.076ee8","order":0,"width":"2","height":"1","passthru":false,"decouple":"false","topic":"","style":"","onvalue":"1","onvalueType":"num","onicon":"","oncolor":"","offvalue":"0","offvalueType":"num","officon":"","offcolor":"","x":230,"y":2320,"wires":[["d530109c.6f6c6","28d53a94.df1696"]]},{"id":"d530109c.6f6c6","type":"switch","z":"c9c4eeb8.bad8e","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":370,"y":2320,"wires":[["f9666944.150c38"],["ef7cf5b3.be7b78"]]},{"id":"cb6df7f2.076ee8","type":"ui_group","z":"","name":"camAlerte","tab":"49bc4576.14e3fc","order":10,"disp":true,"width":6,"collapse":true},{"id":"49bc4576.14e3fc","type":"ui_tab","z":"","name":"Dashboard","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
1 Like

Perfect, thank you. I changed the 1/0 around to work for me.

1 Like

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