How can I start a flow by a specific time? I have a created a time-variable (msg.payload). Now I ask myself how can I start the flow at this variable time?
Take a look at flows.nodered.org where there are lots of timer nodes, some of which allow you to send a message to the node with the time
The cron+ node lets you send the time (specified in CRON format). Many of the timer nodes don't let you send a message to define the time.
I need exactly the opposite.
I've packed the time into a variable and that's supposed to be done at the time.
I need exactly the opposite.
I doubt it. You "packed" the time into a variable, so instead of "packing" it in a variable, inject it in a cron node for example.
Explore this example, may be you'll get some ideas https://flows.nodered.org/flow/986e43672b35b4329d58ceb3d987596b
Do you actually want to do something some time after the present time? In other words after a delay from now? If so then is it a fixed delay or variable?
I am trying to bulid a Power-On Switch for a lamp. The data where the lamp should be turned on comes from a calendar. So my Idea is, I read out the data of the calendar and extract the start date into a variable. The variable is the start button.
I'm not still quite sure how I can use the cron+ node for that.
Do you want to do that each day or read the calendar and set up a repeating schedule for the future?
Currently I have my calendar read out twice a day. But I'm just seperating the upcoming date. Exactly this date should turn on a lamp.
I would like to steer the lamp over a calendar entry, since I work in shift service I have irregular times.
Understood, so you want to trigger a one-off event at some time in the future.
I don't know of a one-shot timer node that will trigger at a defined time. Others may be able to suggest something.
I think I would probably do that in javascript using setTimeout(). Alternatively you could calculate how far in the future it is and then send the message to a delay node, telling the node how much to delay the message for. How to do that is described in the info panel for the Delay node.
The cron-plus node can be (dynamically) set via time or timestamp or string date time
IE. It doesn't have to be a Cron expression
Good Idea, Colin.
I will also check out cron+. I still haven't senn how can I handle it. But I'm brand new in Node-Red.
I also found a node called calendar trigger. That sound good to me as well.
And here is how to do it with time events. As there is always many ways to do it.
[{"id":"fa9d56dd.b926f8","type":"function","z":"d0a71ce6.110d8","name":"Time Events","func":"var stamp = msg.payload;\n\nfunction pretty(num) {\n if (num < 10) {\n return \"0\" + num;\n }\n return \"\" + num;\n}\nvar updated = false;\nvar o_second = null;\nvar o_minute = null;\nvar o_hour = null;\nvar o_date = null;\nvar o_month = null;\nvar o_year = null;\nvar timeupdate = new Date(stamp);\n\nvar currenttime = global.get(\"currenttime\") || {second:0,minute:0,hour:0,date:0,month:0,year:0};\n\nif (currenttime.second !== timeupdate.getSeconds()) {\n currenttime.second = timeupdate.getSeconds();\n updated = true;\n o_second = {\n topic: \"TimeEventSecond\",\n payload: currenttime.second,\n timestamp: stamp\n };\n}\nif (currenttime.minute !== timeupdate.getMinutes()) {\n currenttime.minute = timeupdate.getMinutes();\n o_minute = {\n topic: \"TimeEventMinute\",\n payload: currenttime.minute,\n timestamp: stamp\n };\n}\nif (currenttime.hour !== timeupdate.getHours()) {\n currenttime.hour = timeupdate.getHours();\n o_hour = {\n topic: \"TimeEventHour\",\n payload: currenttime.hour,\n timestamp: stamp\n };\n}\nif (currenttime.date !== timeupdate.getDate()) {\n currenttime.date = timeupdate.getDate();\n o_date = {\n topic: \"TimeEventDate\",\n payload: currenttime.date,\n timestamp: stamp\n };\n}\nif (currenttime.month !== timeupdate.getMonth() + 1) {\n currenttime.month = timeupdate.getMonth() + 1;\n o_month = {\n topic: \"TimeEventMonth\",\n payload: currenttime.month,\n timestamp: stamp\n };\n}\nif (currenttime.year !== timeupdate.getFullYear()) {\n currenttime.year = timeupdate.getFullYear();\n o_year = {\n topic: \"TimeEventYear\",\n payload: currenttime.year,\n timestamp: stamp\n };\n}\nif (updated) {\n currenttime.timestamp = stamp;\n // can hold prettyfied date-time values in currenttime if needed \n /*\n var displaytime = pretty(currenttime.hour) + \":\" + pretty(currenttime.minute) + \":\" + pretty(currenttime.second);\n currenttime.displaytime = displaytime;\n currenttime.displaydate = pretty(currenttime.date) + \".\" + pretty(currenttime.month);\n */\n global.set(\"currenttime\", currenttime);\n \n \n return [o_second, o_minute, o_hour, o_date, o_month, o_year];\n \n}","outputs":6,"noerr":0,"x":330,"y":200,"wires":[["7e172815.fa88b8"],["43cfb168.9a04b"],["cfbff7e4.ff20d8"],["86740614.819928"],["5feaae2c.e30b8"],["93745496.41ac88"]]},{"id":"8e360b48.8a7298","type":"inject","z":"d0a71ce6.110d8","name":"","topic":"","payload":"","payloadType":"date","repeat":".5","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":200,"wires":[["fa9d56dd.b926f8"]]},{"id":"7e172815.fa88b8","type":"link out","z":"d0a71ce6.110d8","name":"te-second","links":[],"x":495,"y":100,"wires":[]},{"id":"43cfb168.9a04b","type":"link out","z":"d0a71ce6.110d8","name":"te-minute","links":["1aae89ad.457c66","435e96bd.8d5388"],"x":495,"y":140,"wires":[]},{"id":"cfbff7e4.ff20d8","type":"link out","z":"d0a71ce6.110d8","name":"te-hour","links":["cd2a9f30.2e52d"],"x":495,"y":180,"wires":[]},{"id":"86740614.819928","type":"link out","z":"d0a71ce6.110d8","name":"te-date","links":[],"x":495,"y":220,"wires":[]},{"id":"5feaae2c.e30b8","type":"link out","z":"d0a71ce6.110d8","name":"te-month","links":[],"x":495,"y":260,"wires":[]},{"id":"93745496.41ac88","type":"link out","z":"d0a71ce6.110d8","name":"te-year","links":[],"x":495,"y":300,"wires":[]},{"id":"1aae89ad.457c66","type":"link in","z":"d0a71ce6.110d8","name":"listen minute","links":["43cfb168.9a04b"],"x":105,"y":700,"wires":[["35cc7978.f7f4d6"]]},{"id":"35cc7978.f7f4d6","type":"switch","z":"d0a71ce6.110d8","name":"hour 10","property":"currenttime.hour","propertyType":"global","rules":[{"t":"eq","v":"10","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":230,"y":700,"wires":[["ef630780.145ec8","c6695639.c621f8"]]},{"id":"ef630780.145ec8","type":"switch","z":"d0a71ce6.110d8","name":"minute 15","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"15","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":440,"y":680,"wires":[["c824c9c2.94f4c8"]]},{"id":"c6695639.c621f8","type":"switch","z":"d0a71ce6.110d8","name":"minute 17","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"17","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":440,"y":720,"wires":[["b6347371.3da2c"]]},{"id":"c824c9c2.94f4c8","type":"debug","z":"d0a71ce6.110d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":590,"y":680,"wires":[]},{"id":"b6347371.3da2c","type":"debug","z":"d0a71ce6.110d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":590,"y":720,"wires":[]},{"id":"c6cac971.edcef8","type":"comment","z":"d0a71ce6.110d8","name":"Do something every day at 10:15AM","info":"","x":520,"y":640,"wires":[]},{"id":"8a3daff5.fc1dc","type":"comment","z":"d0a71ce6.110d8","name":"Do something every day at 10:17AM","info":"","x":520,"y":760,"wires":[]},{"id":"d0eaa338.6add2","type":"comment","z":"d0a71ce6.110d8","name":"Connected to listen TimeEventMinute","info":"","x":190,"y":640,"wires":[]},{"id":"cd2a9f30.2e52d","type":"link in","z":"d0a71ce6.110d8","name":"listen hour","links":["cfbff7e4.ff20d8"],"x":135,"y":510,"wires":[["b37c8d5d.c602a"]]},{"id":"b37c8d5d.c602a","type":"switch","z":"d0a71ce6.110d8","name":"hour 12","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"12","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":230,"y":510,"wires":[["2a5460a8.da475"],["cc044898.badfb8"]]},{"id":"2a5460a8.da475","type":"debug","z":"d0a71ce6.110d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":430,"y":490,"wires":[]},{"id":"732f45d4.9c9a2c","type":"comment","z":"d0a71ce6.110d8","name":"Do something every day at midday","info":"","x":520,"y":450,"wires":[]},{"id":"f3683f54.3304d","type":"comment","z":"d0a71ce6.110d8","name":"Do something else on every other hour","info":"","x":530,"y":570,"wires":[]},{"id":"cc044898.badfb8","type":"debug","z":"d0a71ce6.110d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":430,"y":530,"wires":[]},{"id":"e7dc37b1.78e3b8","type":"comment","z":"d0a71ce6.110d8","name":"Connected to listen TimeEventHour","info":"","x":200,"y":460,"wires":[]},{"id":"8951381b.1126c8","type":"function","z":"d0a71ce6.110d8","name":"set upcoming time","func":"var upcoming = {date:31,hour:22,minute:15}\n// make object with separated units of time to make it\n//easely compareable with time events\n// and store somewhere. flow context will be fine\nflow.set(\"upcoming\",upcoming)\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":860,"wires":[[]]},{"id":"53bb14f8.fd710c","type":"inject","z":"d0a71ce6.110d8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":860,"wires":[["8951381b.1126c8"]]},{"id":"435e96bd.8d5388","type":"link in","z":"d0a71ce6.110d8","name":"upcoming","links":["43cfb168.9a04b"],"x":85,"y":950,"wires":[["32197b88.1c98c4"]]},{"id":"32197b88.1c98c4","type":"switch","z":"d0a71ce6.110d8","name":"compare date","property":"upcoming.date","propertyType":"flow","rules":[{"t":"eq","v":"currenttime.date","vt":"global"}],"checkall":"true","repair":false,"outputs":1,"x":230,"y":950,"wires":[["44bc5416.1cc3ec"]]},{"id":"44bc5416.1cc3ec","type":"switch","z":"d0a71ce6.110d8","name":"compare hours","property":"upcoming.hour","propertyType":"flow","rules":[{"t":"eq","v":"currenttime.hour","vt":"global"}],"checkall":"true","repair":false,"outputs":1,"x":410,"y":950,"wires":[["2aeae7cf.cc37e8"]]},{"id":"2aeae7cf.cc37e8","type":"switch","z":"d0a71ce6.110d8","name":"compare minute","property":"upcoming.minute","propertyType":"flow","rules":[{"t":"eq","v":"currenttime.minute","vt":"global"}],"checkall":"true","repair":false,"outputs":1,"x":600,"y":950,"wires":[["789afae8.f77be4"]]},{"id":"789afae8.f77be4","type":"debug","z":"d0a71ce6.110d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":750,"y":950,"wires":[]},{"id":"89f8a19d.3f139","type":"comment","z":"d0a71ce6.110d8","name":"Do something at the time stored in flow","info":"","x":310,"y":910,"wires":[]}]
Has anyone here experience with calendar trigger? Unfortunately, this does not work for me.
Yes, I do. I have incorporated it into a calendar flow. You need to parse the date in as an array, even if it is only an array of 1.
It works fine, but is rather limited. So I was forking/updating it, until someone else came along and made my efforts redundant.
How can I parse the date into an array?
Take a look here https://www.w3schools.com/js/js_date_formats.asp at the proper formatting needed (specifically at the ISO Dates (Date-Time) section).
Once your date is formatted then just use msg.dates[0] = your properly formatted date in a Function node, and parse this to the Calendar-Trigger node.
As well as using a function node and JavaScript, you can do it with a change node and JSONata.
This is a guess, I haven't tried it but something like:
[payload]
might do the job. Assuming the data is on the payload.