Using a dashboard switch to enable/disable interval inject

1,088 views
Skip to first unread message

mark hubrich

unread,
Feb 26, 2017, 10:20:35 PM2/26/17
to Node-RED
Hi. Is there a way to mimic enabling or disabling an interval inject by using a switch?

I'd like to be able to start/stop the inject from dashboard. 

Thanks!!
Mark

Cor Bosman

unread,
Feb 27, 2017, 6:59:07 AM2/27/17
to Node-RED
You could have the output of the switch go into a change node and set a global variable. Then after the inject, put a switch node to check the global var and only if it matches continue on.

Dave C-J

unread,
Feb 27, 2017, 2:36:54 PM2/27/17
to node...@googlegroups.com
Or also set the topic - then feed a function that uses the topic to discriminate and act as a gate...

[{"id":"af07d51.5afe728","type":"ui_switch","z":"d629259e.613838","name":"","label":"switch","group":"415ff655.a1d8f8","order":0,"width":0,"height":0,"passthru":true,"topic":"gate","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":245.5,"y":1005,"wires":[["c8edc66a.057cb8"]]},{"id":"c8edc66a.057cb8","type":"function","z":"d629259e.613838","name":"control","func":"if (msg.topic === \"gate\") {\n    context.pass = (msg.payload === true) ? true : false;\n    return null;  // exit out early as it's just the control\n}\nif (context.pass) {\n    return msg; // if enabled pass msg\n}\nreturn null; // or drop it","outputs":1,"noerr":0,"x":433.5,"y":1025,"wires":[["bd6caa17.447778"]]},{"id":"5bb586be.00a6a8","type":"inject","z":"d629259e.613838","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"x":268,"y":1067,"wires":[["c8edc66a.057cb8"]]},{"id":"bd6caa17.447778","type":"debug","z":"d629259e.613838","name":"","active":true,"console":"false","complete":"payload","x":644,"y":1026,"wires":[]},{"id":"415ff655.a1d8f8","type":"ui_group","z":"","name":"Default","tab":"622a3108.4411e","disp":true,"width":"6"},{"id":"622a3108.4411e","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]

mark hubrich

unread,
Feb 27, 2017, 3:46:37 PM2/27/17
to node...@googlegroups.com
Thanks Guys!!

On Mon, Feb 27, 2017 at 1:36 PM, Dave C-J <dce...@gmail.com> wrote:
Or also set the topic - then feed a function that uses the topic to discriminate and act as a gate...

[{"id":"af07d51.5afe728","type":"ui_switch","z":"d629259e.613838","name":"","label":"switch","group":"415ff655.a1d8f8","order":0,"width":0,"height":0,"passthru":true,"topic":"gate","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":245.5,"y":1005,"wires":[["c8edc66a.057cb8"]]},{"id":"c8edc66a.057cb8","type":"function","z":"d629259e.613838","name":"control","func":"if (msg.topic === \"gate\") {\n    context.pass = (msg.payload === true) ? true : false;\n    return null;  // exit out early as it's just the control\n}\nif (context.pass) {\n    return msg; // if enabled pass msg\n}\nreturn null; // or drop it","outputs":1,"noerr":0,"x":433.5,"y":1025,"wires":[["bd6caa17.447778"]]},{"id":"5bb586be.00a6a8","type":"inject","z":"d629259e.613838","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"x":268,"y":1067,"wires":[["c8edc66a.057cb8"]]},{"id":"bd6caa17.447778","type":"debug","z":"d629259e.613838","name":"","active":true,"console":"false","complete":"payload","x":644,"y":1026,"wires":[]},{"id":"415ff655.a1d8f8","type":"ui_group","z":"","name":"Default","tab":"622a3108.4411e","disp":true,"width":"6"},{"id":"622a3108.4411e","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/FNJhC1sXHkY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/CACXWFwL8LUOnJKyz5ihqmRf3rmR_ODSBS31npH6JzzrXC5atmg%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

mark hubrich

unread,
Feb 27, 2017, 7:37:06 PM2/27/17
to node...@googlegroups.com
Btw what do I Google to find the best resource for learning the language? I need to know the basics. I look up JavaScript and I got lost. I found the best way to learn was by examples. 

Where can I find a page that contains many examples of function?

Thanks
Mark

Cor Bosman

unread,
Feb 27, 2017, 8:06:44 PM2/27/17
to Node-RED
Check out flows.nodered.org, tons of flow examples.

Cor

steve rickus

unread,
Feb 27, 2017, 11:58:34 PM2/27/17
to Node-RED
Hey Mark, when you say you want many examples of functions, I'm guessing you mean how to use the built-in javascript language, not necessarily node-red examples. Is that correct?

Personally, I don't think a day goes by where I don't have to look up javascript syntax, and I've been working with js for the better part of 10 years! The language keeps evolving and picking up nice features, driven by things like nodejs and loads of third-party libraries. I always keep a tab open to the Mozilla pages, like the Javascript Guide (for a good overview), and the list of Array operators and functions and Working with Objects.

There are many sites that will discuss javascript from primarily the client side of the web, as its initial use was for adding interactivity and logic to the web browser. Most of that you can ignore for programming in node-red, unless you want to build your own UI pages from scratch, or to add html/graphics in ui_template nodes. But I don't see you needing much of that for your current projects...
--
Steve

Colin Law

unread,
Feb 28, 2017, 3:41:53 AM2/28/17
to node...@googlegroups.com
On 28 February 2017 at 00:37, mark hubrich <meis...@gmail.com> wrote:
> Btw what do I Google to find the best resource for learning the language? I
> need to know the basics. I look up JavaScript and I got lost. I found the
> best way to learn was by examples.
>
> Where can I find a page that contains many examples of function?

I suggest starting with https://www.w3schools.com/js/. There is an
introductory section then a reference with all the functions having
good examples. If you know approximately what you want to do that is
an excellent place to look. For example if you want to do something
with an array then the section on arrays shows how to do all the basic
stuff.

Colin

mark hubrich

unread,
Mar 1, 2017, 12:25:36 AM3/1/17
to node...@googlegroups.com
Great resources thanks. I have learned lots from w3schools. I have to pull my head out of arduinos I guess :D 

--
http://nodered.org

Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/FNJhC1sXHkY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send an email to node...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages