Looking for a relay switch function

Hello

I am looking for a function so the flow of messages will only be allowed when a mqtt status is
revived,but been able to have control independently of one

example
input - mqtt - cmd heater on
input - mqtt - cmd pump on

input to alow traffic of heater to be sent and is always checking
input - stat pump power on

in an electrical system it is called a relay
the coil would be the stat msg

Thank you
chris

1 Like

If you feed your control messages to flow variables, then you can read the value of those flow values in a switch node and route you messages as required

image

sorry i cant see how this works i am tired to be honest so probably not the best time to be looking at it
so i need the status of the pump to be on, to allow the command of the heater power on when it is called for but also turning the heater off is the pump stops running this is controlling my hot tub

i have a manual fail safe built in on the circuits but i would like the logical one to be primary in case either fail

I was just showing how to implement the relay bit - not how to do everything sorry

The change node in the example sends its payload to a flow context called "flow.heater." For example, if the mqtt topic you are subscribing to gets a message of "on" you'd have flow.heater="on" in your flow context store, which is accessible to any nodes in this flow.

The switch node is set to evaluate the flow context "flow.heater" that you set with the change node. If flow.heater=on your payload being sent to the switch is sent out the top output. If it's anything else at all, it's sent out the bottom. (It's basically set up as an if/else.)

Since you put it in EE terms, you can think of the switch node as acting as your relay, with the flow.heater context in the example being whether you are applying your trigger voltage or not.

Also, 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.

hi been looking at this all day without luck can u do a quick example so i can see

are you able to show please i haven't go a clue lol

Play with this flow until it makes sense.

[{"id":"ea278027.db323","type":"switch","z":"fd401019.9d69d","name":"","property":"relayOn","propertyType":"flow","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":730,"y":380,"wires":[["2bc818cc.e4eee"],["3c79f8df.236648"]]},{"id":"5937761d.c49ce8","type":"inject","z":"fd401019.9d69d","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":200,"wires":[["970fbcde.71d9d"]]},{"id":"d52ee9ef.e2282","type":"inject","z":"fd401019.9d69d","name":"","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":240,"wires":[["970fbcde.71d9d"]]},{"id":"970fbcde.71d9d","type":"change","z":"fd401019.9d69d","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"relayOn","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":220,"wires":[[]]},{"id":"830e7a54.bfa478","type":"inject","z":"fd401019.9d69d","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":340,"wires":[["ea278027.db323"]]},{"id":"cc839177.1610c8","type":"inject","z":"fd401019.9d69d","name":"","topic":"","payload":"Test message 1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":380,"wires":[["ea278027.db323"]]},{"id":"a8c67ad0.9d5ee","type":"inject","z":"fd401019.9d69d","name":"","topic":"","payload":"Another test message","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":420,"wires":[["ea278027.db323"]]},{"id":"59dc60e2.65226","type":"comment","z":"fd401019.9d69d","name":"This sets flow.relayOn","info":"","x":250,"y":160,"wires":[]},{"id":"ee876a11.61fac","type":"comment","z":"fd401019.9d69d","name":"This evaluates for flow.relayOn true/false","info":"","x":700,"y":340,"wires":[]},{"id":"2bc818cc.e4eee","type":"debug","z":"fd401019.9d69d","name":"if flow.relayOn is true, message comes out here","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1040,"y":360,"wires":[]},{"id":"3c79f8df.236648","type":"debug","z":"fd401019.9d69d","name":"if flow.relayOn is false, message comes out here","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1040,"y":400,"wires":[]}]

nothing in message ialso need this for a automatic dimming on dusk dawn for zwave lighting too

go it mate thankyou ill have a look

Check again. I updated.

I recommend looking over the example until you fully understand what's going on before adding complexity. Ask questions as you go if anything is stumping you.

i get how its changing but i dont understand how it alows the other mqtt topic to turn on
topic heater
topic pump?

The flow i gave isn't doing anything with mqtt yet. The cluster of nodes at top set the gate for the switch node. The switch node simply routes traffic to either the top or bottom output. That traffic can either be passed elsewhere, or used to trigger other events.

still havent got the relay tho :tired_face:

How do the flows/ideas submitted by Simon and Jay not provide you a solution?

i cant see it sorry for not getting it is the 2 message payloads been put unto one message? cant see how 2 different message payloads are been controlled or stopped

how does it know what state the flow relay is ? when the message is heater nothing in message contains relay on or off or false true but and also the message will be at different times never at same time?

hope you can make me see sense :frowning:

Thank you
chris

https://nodered.org/docs/user-guide/context

In summary, each tab has its own store of variables referred to as its "context." Say you want there to be a variable called "heater": if you set flow.heater to a value (let's say we set it to "true" fow now) then node-red stores a value called flow.heater as "true." Any node that evaluates for "flow.heater" looks at the value currently stored in that space and acts accordingly. Those two strings of nodes don't need to be connected. One sets the variable in the flow context. The other looks at the value in the flow context to decide where to route traffic.

ok could u do a flow showing me please, when you get chance
I sort of understand

The one i posted 3 days ago includes this. What version are you runnng? 0.19 adds some features that make this much easier to wrap your head around if it hasn't clicked yet.