Looking for a relay switch function

Hi Chris,
how are you trying to switch relay? You can probably use a raspberry pi and use its GPIO to contol whatever appliance you need. Moreover you will be able to have a better logic and control by using your desired python script for the same.

Its ok i need it through logic, also im running an nuc now no longer pi took too long boot and made me feel uneasy when im going to be running all the house

and i still haven't go it im missing something simple (maybe my brain )

What have you managed to put together so far?

Can you export your flow and paste in onto here? (remember to add 3 backticks ``` before and after your paste )

this is my basic in and out

[{"id":"23637a3b.afc076","type":"mqtt out","z":"a73eaf10.d07ed","name":"","topic":"cmnd/myhome/garden/hottub/4ch/POWER1","qos":"2","retain":"","broker":"90054376.7c2c3","x":1190,"y":500,"wires":[]},{"id":"6d5aa4bb.0f0cfc","type":"mqtt out","z":"a73eaf10.d07ed","name":"","topic":"cmnd/myhome/garden/hottub/heater/POWER","qos":"2","retain":"","broker":"90054376.7c2c3","x":1170,"y":320,"wires":[]},{"id":"e063eafe.2b7b48","type":"change","z":"a73eaf10.d07ed","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"ON","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":500,"wires":[["baefd0f.5cca23"]],"inputLabels":["1"],"outputLabels":["1"]},{"id":"2f17f064.f9505","type":"change","z":"a73eaf10.d07ed","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"ON","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":320,"wires":[["55645375.4320ac"]],"inputLabels":["1"],"outputLabels":["1"]},{"id":"bdd3179d.122868","type":"switch","z":"a73eaf10.d07ed","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"","vt":"msg"},{"t":"eq","v":"","vt":"msg"}],"checkall":"true","repair":false,"outputs":2,"x":870,"y":320,"wires":[[],[]]},{"id":"4af199e2.9388f8","type":"inject","z":"a73eaf10.d07ed","name":"","topic":"","payload":"true","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":360,"wires":[["2f17f064.f9505"]]},{"id":"a5631fcd.7922f","type":"inject","z":"a73eaf10.d07ed","name":"","topic":"","payload":"false","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":280,"wires":[["2f17f064.f9505"]]},{"id":"55645375.4320ac","type":"ui_switch","z":"a73eaf10.d07ed","name":"","label":"Hot Tub Heater","group":"95b24434.e48748","order":3,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"ON","onvalueType":"str","onicon":"","oncolor":"","offvalue":"OFF","offvalueType":"str","officon":"","offcolor":"","x":640,"y":320,"wires":[["6d5aa4bb.0f0cfc"]],"inputLabels":["1"],"outputLabels":["1"]},{"id":"baefd0f.5cca23","type":"ui_switch","z":"a73eaf10.d07ed","name":"","label":"Hot Tub Pump","group":"5d2c7689.7790b8","order":1,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"ON","onvalueType":"str","onicon":"","oncolor":"","offvalue":"OFF","offvalueType":"str","officon":"","offcolor":"","x":640,"y":500,"wires":[["23637a3b.afc076"]],"inputLabels":["1"],"outputLabels":["1"]},{"id":"b6da3d32.c3a47","type":"mqtt in","z":"a73eaf10.d07ed","name":"","topic":"HA/Hottub/Heater/Switch","qos":"2","broker":"90054376.7c2c3","x":190,"y":400,"wires":[["55645375.4320ac","baefd0f.5cca23"]]},{"id":"e333ce3.3ea0e3","type":"alexa-home","z":"a73eaf10.d07ed","conf":"44e67155.2b4ca","device":"30057","acknoledge":true,"name":"Hot Tub Pump","topic":"Hot Tub","x":150,"y":500,"wires":[["e063eafe.2b7b48"]]},{"id":"332aa61d.a5b14a","type":"alexa-home","z":"a73eaf10.d07ed","conf":"44e67155.2b4ca","device":"29580","acknoledge":true,"name":"Hot Tub Heater","topic":"Hot Tub","x":120,"y":320,"wires":[["2f17f064.f9505"]]},{"id":"90054376.7c2c3","type":"mqtt-broker","z":"","name":"Local","broker":"127.0.0.1","port":"1883","tls":"","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"95b24434.e48748","type":"ui_group","z":"","name":"Hot Tub","tab":"d8c44daf.a12ea","order":2,"disp":true,"width":"6","collapse":false},{"id":"5d2c7689.7790b8","type":"ui_group","z":"","name":"Hot Tub - Filtration","tab":"d8c44daf.a12ea","order":3,"disp":true,"width":"6","collapse":false},{"id":"44e67155.2b4ca","type":"alexa-home-conf","z":"","username":"homemedia20"},{"id":"d8c44daf.a12ea","type":"ui_tab","z":"","name":"Garden","icon":"dashboard","order":2}]

Well i had the same query when i was building my customized home automation system. For the same i had used an mqtt client synchronized with AWS lambda function. Now when any device has to be switched on/off, message was received in node red and a simple python script was executed (Although you can directly control the GPIO state with nodes). - An brief idea.

I haven't worked in NUC hence i am not sure how can you achieve the same function in it. You can try ESP8266 wifi module directly coupled with relay to turn on/off the target device.

i have a relay in place for a safety but also wonted to know how to do it logically for different things

Hi
1st off - if this was me - I'd have debugging nodes all over the place so I could see what messages were going where

2nd - your injecting true or false and converting them immediately to ON or OFF

You don't need to do that - you can just have the inject nodes sending ON or OFF directly

Then if you check with what I suggested back with my 1st reply - you'll see that the control signals are in one flow that is separate from the one with the switch in it.

So you end up with one flow that sets flow. variables to various values

And another flow with a switch in it that uses the flow, variable values from the 1st flow to block/pass your main messages

Also the flow that @JayDickson posted looks very informative and well commented

I'm starting to think I may need to toss together a video lesson to go along with the flow. This is literally the one concept that took me the longest to get but once I did it opened up tons of doors.

3 Likes

i think so too i have tried to figure oth that flow but i just get msg payload undefined
also i found this and been playing with this too

[{"id":"d4ba01bd.7c3ef","type":"inject","z":"225b7dfe.c31132","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":1550,"y":240,"wires":[["98cc66aa.1d8138"]]},{"id":"98cc66aa.1d8138","type":"switch","z":"225b7dfe.c31132","name":"gate","property":"gate","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":1730,"y":240,"wires":[["15468079.2a413"]]},{"id":"69461594.af2fec","type":"inject","z":"225b7dfe.c31132","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1530,"y":120,"wires":[["225fc3e9.c333ac"]]},{"id":"44292af6.2fdc44","type":"inject","z":"225b7dfe.c31132","name":"","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1530,"y":160,"wires":[["225fc3e9.c333ac"]]},{"id":"15468079.2a413","type":"debug","z":"225b7dfe.c31132","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","x":1920,"y":240,"wires":[]},{"id":"225fc3e9.c333ac","type":"change","z":"225b7dfe.c31132","name":"","rules":[{"t":"set","p":"gate","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1690,"y":140,"wires":[["e66d3f57.f0441"]]},{"id":"7b83431d.90186c","type":"inject","z":"225b7dfe.c31132","name":"","topic":"cat","payload":"purr","payloadType":"str","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":1540,"y":760,"wires":[["12aba8b7.dcfae7"]]},{"id":"53df45e4.c6ec4c","type":"inject","z":"225b7dfe.c31132","name":"","topic":"dog","payload":"bark","payloadType":"str","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":1550,"y":800,"wires":[["12aba8b7.dcfae7"]]},{"id":"7a51b53.e6b784c","type":"inject","z":"225b7dfe.c31132","name":"","topic":"brocoli","payload":"eat","payloadType":"str","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":1550,"y":840,"wires":[["12aba8b7.dcfae7"]]},{"id":"12aba8b7.dcfae7","type":"switch","z":"225b7dfe.c31132","name":"topicGate","property":"$flowContext('topicGate') ~> $lookup(topic)","propertyType":"jsonata","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":1760,"y":820,"wires":[["35d3013d.e2396e"]]},{"id":"fe361a21.bd1208","type":"inject","z":"225b7dfe.c31132","name":"","topic":"cat","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1530,"y":420,"wires":[["94d28c19.7cebf"]]},{"id":"c28b2e5c.c0176","type":"inject","z":"225b7dfe.c31132","name":"","topic":"dog","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1540,"y":560,"wires":[["94d28c19.7cebf"]]},{"id":"e78306b0.4dad48","type":"inject","z":"225b7dfe.c31132","name":"","topic":"brocoli","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1550,"y":620,"wires":[["94d28c19.7cebf"]]},{"id":"b746351b.aafa28","type":"inject","z":"225b7dfe.c31132","name":"","topic":"cat","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1540,"y":460,"wires":[["94d28c19.7cebf"]]},{"id":"58cef8d4.62aac8","type":"inject","z":"225b7dfe.c31132","name":"","topic":"dog","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1540,"y":520,"wires":[["94d28c19.7cebf"]]},{"id":"fde51eba.caa68","type":"inject","z":"225b7dfe.c31132","name":"","topic":"brocoli","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1550,"y":660,"wires":[["94d28c19.7cebf"]]},{"id":"94d28c19.7cebf","type":"change","z":"225b7dfe.c31132","name":"","rules":[{"t":"set","p":"topicGate","pt":"flow","to":"$merge([$flowContext('topicGate'), {topic: payload}])","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1754,"y":522,"wires":[["be871f76.b5677"]]},{"id":"35d3013d.e2396e","type":"debug","z":"225b7dfe.c31132","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1930,"y":820,"wires":[]},{"id":"445b67c2.7be0b8","type":"comment","z":"225b7dfe.c31132","name":"Simple gate using a flow variable","info":"","x":1590,"y":60,"wires":[]},{"id":"efd5d638.30e378","type":"comment","z":"225b7dfe.c31132","name":"Per topic gate using a flow variable","info":"","x":1600,"y":360,"wires":[]},{"id":"be871f76.b5677","type":"debug","z":"225b7dfe.c31132","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":2000,"y":520,"wires":[]},{"id":"e66d3f57.f0441","type":"debug","z":"225b7dfe.c31132","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1930,"y":140,"wires":[]}]

still no luck tho i just cant see it to get it

winding me up now i get how it ment to work, but just cant seem to figure it out and how to add the topics either

https://youtu.be/cVly3DMC79g

Here's some of what I tried to describe being built in motion. If I'm still confusing or you have additional questions let me know (and please be gentle, I went unscripted and haven't taught a class in anything in over 8 years :stuck_out_tongue: )

THANKYOU
i will have a look later its my bday today have the kids driving me mad lol

Hello..if you want to genericize this, each tab gets its own flow context and flows can't see each others contexts but there is also a global context that is shared among all flows. Subflows are treated as basically being their own tab, so if you want to do a lot of copy-pasted or referenced logic it's a good idea to wrap it in sub flows so you don't have to re-declare variables all over the place.

complete pcb

your video was brilliant

i have it sorted now, thank you

since then i have been messing around with other things, do you use any wemos in your setup or artnet

[{"id":"9ea308f7.0cbca8","type":"inject","z":"d63dbd49.6380c","name":"","topic":"","payload":"ON","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":240,"wires":[["2b5f6f7c.48a98"]]},{"id":"21212a39.9909f6","type":"inject","z":"d63dbd49.6380c","name":"","topic":"","payload":"OFF","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":280,"wires":[["2b5f6f7c.48a98"]]},{"id":"50257594.247b8c","type":"inject","z":"d63dbd49.6380c","name":"","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":100,"wires":[["c1785f2e.7b9e3"]]},{"id":"58243797.d4f3a8","type":"inject","z":"d63dbd49.6380c","name":"","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":140,"wires":[["c1785f2e.7b9e3"]]},{"id":"c1785f2e.7b9e3","type":"change","z":"d63dbd49.6380c","name":"Coil","rules":[{"t":"move","p":"payload","pt":"msg","to":"switch_state","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":120,"wires":[[]]},{"id":"2b5f6f7c.48a98","type":"switch","z":"d63dbd49.6380c","name":"","property":"switch_state","propertyType":"flow","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":470,"y":260,"wires":[["ef5f1505.a49be8"],["9d23ec87.85afd"],["93f9d44d.e4da08"]]},{"id":"ef5f1505.a49be8","type":"debug","z":"d63dbd49.6380c","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","x":680,"y":220,"wires":[]},{"id":"9d23ec87.85afd","type":"debug","z":"d63dbd49.6380c","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","x":680,"y":260,"wires":[]},{"id":"93f9d44d.e4da08","type":"debug","z":"d63dbd49.6380c","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","x":680,"y":300,"wires":[]}]

for anyone else who is struggling electrical concept

many of us use wemos's but if you have a question abut them and NR why not open a new thread so others can find it in the future.

mine keep freezing up tried power and re-flashed them with several easy mega versions
im lost now tbh