# Enable a flow help

**URL:** <https://discourse.nodered.org/t/enable-a-flow-help/43639>\
**Category:** General\
**Created:** [4 April 2021 10:35 UTC](https://discourse.nodered.org/t/enable-a-flow-help/43639 "2021-04-04T10:35:55Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![biros](https://avatars.discourse-cdn.com/v4/letter/b/e47c2d/32.png) [@biros](https://discourse.nodered.org/u/biros)\
**Post date:** [4 April 2021 10:35 UTC](https://discourse.nodered.org/t/enable-a-flow-help/43639/1 "2021-04-04T10:35:55Z")

</div>

Hello, new user here and pretty much 0 experience with javascript.  
Weirdly i managed to install rpi os strecth, mqtt and nr to a pi zero w and flashed tasmota to one of my smart switches without any issue. Even did a few simple flows on it.  
As a plc programmer nodered seemed a very easy approach to experiment with iot, until it wasn't.  
I don't understand what is the problem here, could anyone help me out please?  
I am trying to enable and disable on demand with a ui switch the automatic on/off at sunrise/set on the relay output (of the iot switch). Thanks in advance.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/4/c42381007a7a853110bc3cb91ced0fdc968427c4.png)

In this state, the flow variable is still true, why?  
Is my application doable in this sturcture?  
I tried to experiment with the boolean libraries also but no success (kind of ironic).  
Can you point me to some documentation with the "topic" thing? I thought "topics" are mqtt specific things, but i see them as a parameter in many nodes.  
Thanks in advance and have a nice day.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 April 2021 11:05 UTC](https://discourse.nodered.org/t/enable-a-flow-help/43639/2 "2021-04-04T11:05:56Z")

</div>

As the payload is 1 and you are comparing with double equal == then 1 is == to true.

This is a feature/quirk of JavaScript.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 April 2021 11:09 UTC](https://discourse.nodered.org/t/enable-a-flow-help/43639/3 "2021-04-04T11:09:03Z")

</div>

> [@biros](#):
>
> Can you point me to some documentation with the "topic" thing? I thought "topics" are mqtt specific things, but i see them as a parameter in many nodes

In non MQTT areas, it is very useful for 'tagging' a Payload. For example, if you send 2 payloads of 'true' down the same wire, which one is from your garage switch and which one came from a dashboard button? The topic provides context. It's not required that you use msg.topic (it could be msg.myTag) but it provides a familiar feeling of "description" to use msg.topic.

---

<div class="post-metadata">

**Author:** ![biros](https://avatars.discourse-cdn.com/v4/letter/b/e47c2d/32.png) [@biros](https://discourse.nodered.org/u/biros)\
**Post date:** [4 April 2021 11:14 UTC](https://discourse.nodered.org/t/enable-a-flow-help/43639/4 "2021-04-04T11:14:29Z")

</div>

Hello,  
thanks for both answers. The ui switch is turned off, shouldn't that reset the state of the flow variable to "false"?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 April 2021 11:27 UTC](https://discourse.nodered.org/t/enable-a-flow-help/43639/5 "2021-04-04T11:27:18Z")

</div>

> [@biros](#):
>
> The ui switch is turned off, shouldn't that reset the state of the flow variable to "false"?

Yes, but I cant see how have things configured from a screenshot.

Select the nodes of interest and export them ctrl+e

Be sure to always paste code snippets / flow exports between backticks  
`````  
`like this`  
`````  
otherwise it will not be importable

* * *

also, what value is your flow variable (look in the side-bar under "context data")

---

<div class="post-metadata">

**Author:** ![biros](https://avatars.discourse-cdn.com/v4/letter/b/e47c2d/32.png) [@biros](https://discourse.nodered.org/u/biros)\
**Post date:** [4 April 2021 11:45 UTC](https://discourse.nodered.org/t/enable-a-flow-help/43639/7 "2021-04-04T11:45:56Z")

</div>

```auto
[{"id":"f3ab7248.bc71d","type":"ui_switch","z":"ae6391de.2859e","name":"","label":"Switch","tooltip":"","group":"6c7c8e8a.63dc8","order":3,"width":"0","height":"0","passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"x":130,"y":220,"wires":[["d0c88e92.b9309"]]},{"id":"d0c88e92.b9309","type":"Tasmota Switch","z":"ae6391de.2859e","broker":"a36e2f8a.1c6a6","device":"Meteo","name":"Meteo","outputs":1,"uidisabler":false,"fullTopic":"","cmndPrefix":"","statPrefix":"","telePrefix":"","x":830,"y":220,"wires":[[]]},{"id":"f6ca4949.1b5c08","type":"sunrise","z":"ae6391de.2859e","name":"","lat":"46.7212","lon":"25.5855","start":"sunrise","end":"sunsetStart","soff":0,"eoff":0,"x":210,"y":700,"wires":[["78f9ccca.80c4f4","afef7f25.85ea8"],[]]},{"id":"d7b26b1.6c62098","type":"ui_switch","z":"ae6391de.2859e","name":"","label":"Enable Sunrise","tooltip":"","group":"6c7c8e8a.63dc8","order":4,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"payload","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"x":100,"y":360,"wires":[["ca6a4694.9aa9f8","6bd72a92.80d0b4","c0d8e45a.b9f3e8"]]},{"id":"ba405204.4c60a","type":"debug","z":"ae6391de.2859e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":690,"y":420,"wires":[]},{"id":"fc51004c.ba5fd","type":"debug","z":"ae6391de.2859e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":670,"y":700,"wires":[]},{"id":"78f9ccca.80c4f4","type":"switch","z":"ae6391de.2859e","name":"","property":"Enable","propertyType":"flow","rules":[{"t":"eq","v":"payload","vt":"msg"}],"checkall":"true","repair":false,"outputs":1,"x":390,"y":700,"wires":[["fc51004c.ba5fd","d0c88e92.b9309"]]},{"id":"ca6a4694.9aa9f8","type":"change","z":"ae6391de.2859e","name":"","rules":[{"t":"set","p":"Enable","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":420,"wires":[["ba405204.4c60a"]]},{"id":"afef7f25.85ea8","type":"debug","z":"ae6391de.2859e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":670,"y":640,"wires":[]},{"id":"6bd72a92.80d0b4","type":"debug","z":"ae6391de.2859e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":690,"y":360,"wires":[]},{"id":"17b2cb83.3725b4","type":"debug","z":"ae6391de.2859e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":690,"y":480,"wires":[]},{"id":"10079b84.5312b4","type":"change","z":"ae6391de.2859e","name":"","rules":[{"t":"set","p":"Enable","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":480,"wires":[["17b2cb83.3725b4"]]},{"id":"c0d8e45a.b9f3e8","type":"Invert","z":"ae6391de.2859e","name":"Invert","x":290,"y":480,"wires":[["10079b84.5312b4"]]},{"id":"6c7c8e8a.63dc8","type":"ui_group","name":"Meteo","tab":"ee8fb9fa.4adfe8","order":1,"disp":true,"width":"7","collapse":false},{"id":"a36e2f8a.1c6a6","type":"mqtt-broker","name":"","broker":"192.168.101.3","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"ee8fb9fa.4adfe8","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

the flow variable (flow.Enable) follows the state of the ui switch (Enable Sunrise) true/false.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/3/93a070be98d52fe54f781d4fdff071fda205bb83.png)

now (on the screenshot), the lowest msg.payload debug node value should be 0 if i'd know this thing better.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 April 2021 12:13 UTC](https://discourse.nodered.org/t/enable-a-flow-help/43639/8 "2021-04-04T12:13:54Z")

</div>

Here is a simplified version (I use cron-plus for schedules/solar events - not whatever sunrise node you use - but that should not matter)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/e/ce1865f5e7b220624ec5d27a5894e52df3d9fd21.png)

The premise is...

1. The UI Switch should send true or false (the topic should not be msg.payload)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/2/52a06d81aec95109361e904d6227c017fd1e6039.png)

2. Set flow.Enable to the value of the UI switch  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/8/c8cb35ad14244b849d9f5ff87e5c134915b404b1.png)

3. test the flow.Enable flag - if `true` the message will pass  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/5/15f3e1278c2a4af14d9541aa75450f578c1c8818.png)

```auto
[{"id":"d7b26b1.6c62098","type":"ui_switch","z":"83a23089.dc697","name":"","label":"Enable Sunrise","tooltip":"","group":"6c7c8e8a.63dc8","order":4,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"SunriseEnable","topicType":"str","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"x":440,"y":800,"wires":[["ca6a4694.9aa9f8"]]},{"id":"ba405204.4c60a","type":"debug","z":"83a23089.dc697","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":910,"y":800,"wires":[]},{"id":"fc51004c.ba5fd","type":"debug","z":"83a23089.dc697","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":910,"y":880,"wires":[]},{"id":"78f9ccca.80c4f4","type":"switch","z":"83a23089.dc697","name":"","property":"Enable","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":650,"y":880,"wires":[["fc51004c.ba5fd"]]},{"id":"ca6a4694.9aa9f8","type":"change","z":"83a23089.dc697","name":"","rules":[{"t":"set","p":"Enable","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":800,"wires":[["ba405204.4c60a"]]},{"id":"674324d.1f71cdc","type":"cronplus","z":"83a23089.dc697","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"sunrise","topic":"sunrise","payloadType":"default","payload":"","expressionType":"solar","expression":"0 * * * * * *","location":"","offset":"0","solarType":"selected","solarEvents":"sunrise"}],"x":440,"y":880,"wires":[["78f9ccca.80c4f4"]]},{"id":"6c7c8e8a.63dc8","type":"ui_group","name":"Meteo","tab":"ee8fb9fa.4adfe8","order":1,"disp":true,"width":"7","collapse":false},{"id":"ee8fb9fa.4adfe8","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![biros](https://avatars.discourse-cdn.com/v4/letter/b/e47c2d/32.png) [@biros](https://discourse.nodered.org/u/biros)\
**Post date:** [4 April 2021 12:38 UTC](https://discourse.nodered.org/t/enable-a-flow-help/43639/9 "2021-04-04T12:38:24Z")

</div>

Thank you kindly for the answer, I see you showed the topic related part too, i get the concept now.  
Can you please check if you turn off the Enable Sunrise ui switch while you get a true (or however it works) from the cron-plus, does the debug node connected to the switch will change to false?  
Because mine doesn't and i had this same issue with the original flow.  
Thank you.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 April 2021 12:44 UTC](https://discourse.nodered.org/t/enable-a-flow-help/43639/10 "2021-04-04T12:44:52Z")

</div>

> [@biros](#):
>
> Can you please check if you turn off the Enable Sunrise ui switch while you get a true (or however it works) from the cron-plus, does the debug node connected to the switch will change to false?

the debug node will show the last payload (in my demo case, it shows the default payload cron-plus sends - but that payload could be **whatever you want** )

It works as I suspect you want it to (block messages when enable == false)

![I6U5ffSIRB](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/5/85a4dddbaf6f08f0604f45694a5e3fe2a00a56a6.gif)

Here, i modified the payload of cron-plus to show you the payload can be whatever you want it to be.

![UUnXKX2sR5](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/4/64417dcc1ba74cc26427e37a009a79064cdbeb1c.gif)

---

<div class="post-metadata">

**Author:** ![biros](https://avatars.discourse-cdn.com/v4/letter/b/e47c2d/32.png) [@biros](https://discourse.nodered.org/u/biros)\
**Post date:** [4 April 2021 12:57 UTC](https://discourse.nodered.org/t/enable-a-flow-help/43639/11 "2021-04-04T12:57:41Z")

</div>

I connected the switch node output to a relay (hardware) output on a board, you guys probably call it gpio.  
While the sunrise event gives a "true" state and i turn off the Enable Sunrise ui switch i would like to deactivate the relay.  
Is it possible in node red?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 April 2021 13:15 UTC](https://discourse.nodered.org/t/enable-a-flow-help/43639/12 "2021-04-04T13:15:08Z")

</div>

> [@biros](#):
>
> Is it possible in node red?

Yes. Link the "enable" ui switch to the gpio node.  
NOTE: You will need to change the true false to 1 and 0 before you send it.

a function node can do that easily...

```auto
if(msg.payload == true) {
    msg.payload = 1;
} else {
    msg.payload = 0;
}
return msg;

```

ui\_switch --\> function --\> gpio

---

<div class="post-metadata">

**Author:** ![biros](https://avatars.discourse-cdn.com/v4/letter/b/e47c2d/32.png) [@biros](https://discourse.nodered.org/u/biros)\
**Post date:** [4 April 2021 13:16 UTC](https://discourse.nodered.org/t/enable-a-flow-help/43639/13 "2021-04-04T13:16:59Z")

</div>

And where do i connect the sunrise/set node?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 April 2021 13:24 UTC](https://discourse.nodered.org/t/enable-a-flow-help/43639/14 "2021-04-04T13:24:17Z")

</div>

I'm getting lost.

What is your goal - can you spell it out in some form of pseudo logic.

e.g...

1. if flow.enable is true, allow sunrise message to turn ON and OFF GPIO 1
2. if flow.enable is false, prevent sunrise message from affecting GPIO 1
3. when flow.enable is changed from true to false, switch OFF GPIO

etc.

---

<div class="post-metadata">

**Author:** ![biros](https://avatars.discourse-cdn.com/v4/letter/b/e47c2d/32.png) [@biros](https://discourse.nodered.org/u/biros)\
**Post date:** [4 April 2021 13:25 UTC](https://discourse.nodered.org/t/enable-a-flow-help/43639/15 "2021-04-04T13:25:26Z")

</div>

ok, I added the if condition you gave, at the output of the switch node and then connected the output of the function node to the hardware output and it's working as i wanted originally. (i marked the post with the screenshot as the solution)  
many thanks, looks like this won't roll without learning some js.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [18 April 2021 13:25 UTC](https://discourse.nodered.org/t/enable-a-flow-help/43639/16 "2021-04-18T13:25:34Z")

</div>

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