Pause cronplus node until restarted (Edited title)

Hi,

@knolleary, @Steve-Mcl

I am not sure if I am using the node correctly, but I seem to be having some problems with this small flow using msg.topic and msg.payload to control the node. Any comments, suggestions greatly accepted!!

Basically I need runs a cron job until a certain condition is met, at which point the cron job is paused. Restart of the paused cron job is at the same time each day. (Seeing if InfluxDB has 'future' data in it, if not, go and fetch until it does!)

My Dummy flow should simulate this...

cronplus set to check for data every 20 seconds
if data (Random node), pause cronplus (and sendEmail - set variable)
if no data, run again in 20 seconds

Restart cronplus from inject node when you want it to run again (same time each day)

However, I seem to be getting data delayed/flooding. I am not sure if this is due to the flow, or the Debug window in Node Red, or something else. The debug messages pause for a while (not every time) and then I get a flood, but the flow should have paused after the first pair of messages in the flood! The delay was added in case of some kind of race condition.

I am aware that I am using the Node-RED 1.1.0-beta.3, hence me posting here now rather than fault find for a few days.

30 Jun 16:00:01 - [info] Node-RED version: v1.1.0-beta.3
30 Jun 16:00:01 - [info] Node.js version: v12.18.1
30 Jun 16:00:01 - [info] Linux 5.3.0-61-generic x64 LE
30 Jun 16:00:01 - [info] Loading palette nodes
30 Jun 16:00:01 - [info] Dashboard version 2.22.1 started at /ui
30 Jun 16:00:01 - [warn] rpi-gpio : Raspberry Pi specific node set inactive
30 Jun 16:00:01 - [info] Settings file : .node-red/settings.js
30 Jun 16:00:01 - [info] Context store : 'default' [module=memory]
30 Jun 16:00:01 - [info] User directory : .node-red
30 Jun 16:00:01 - [warn] Projects disabled : editorTheme.projects.enabled=false
30 Jun 16:00:01 - [info] Flows file : .node-red/flows_XXXX.json
30 Jun 16:00:01 - [info] Server now running at http://127.0.0.1:1880/

[{"id":"91dc1292.bb15b8","type":"function","z":"42c2a631.eb624","name":"Slot got value?","func":"var cost = msg.payload;\nif (cost !== 0) {\n    msg.sendEmail = 1;\n    msg.topic = \"pause\"\n    msg.payload = \"refetch\"\n}\nelse {\n    msg.sendEmail = 0\n    msg.topic = \"start\"\n    msg.payload = \"refetch\"\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":660,"y":400,"wires":[["90939623.74a8c8","ebccfa55.f2fed","becebb3b.a72778"]]},{"id":"6a7768be.e5648","type":"cronplus","z":"42c2a631.eb624","name":"Check Data","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"refetch","topic":"refetch","payloadType":"str","payload":"1","expressionType":"cron","expression":"0/20 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":310,"y":400,"wires":[["2e0e0a52.804b16"]]},{"id":"90939623.74a8c8","type":"debug","z":"42c2a631.eb624","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"sendEmail","targetType":"msg","statusVal":"","statusType":"auto","x":920,"y":400,"wires":[]},{"id":"2e0e0a52.804b16","type":"random","z":"42c2a631.eb624","name":"","low":"0","high":"1","inte":"true","property":"payload","x":480,"y":400,"wires":[["91dc1292.bb15b8"]]},{"id":"61ed2543.31c014","type":"inject","z":"42c2a631.eb624","name":"","props":[{"p":"payload"},{"p":"topic","v":"start","vt":"msg"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"payload":"refetch","payloadType":"msg","x":110,"y":280,"wires":[["6a7768be.e5648"]]},{"id":"ebccfa55.f2fed","type":"debug","z":"42c2a631.eb624","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":360,"wires":[]},{"id":"becebb3b.a72778","type":"delay","z":"42c2a631.eb624","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":120,"y":400,"wires":[["6a7768be.e5648"]]}]

You could try configuring the Debug node to also log to the console - that would flush straight away (at the point the Debug node received the message) and would rule in/out any issues with the comms link between runtime and editor getting jammed up.

Hi mudwalker, you have created a loop in your flow.

You need something in the flow to stop the feedback once you have done your task.

Try setting the "Command Resp" to a separate output to prevent the command coming through & looping back around

image

Alternatively, dont reply in your function node if the topic is pause-all or start-all

EDIT: only newer version of CRON+ can output command responses to a 2nd pin. What version do you have installed? If you can, then update. If you cant, update your function so something like below...

if(msg.topic=="start" || msg.topic=="pause"){
    return null; //stop the cmd response msg looping back
}

var cost = msg.payload;

if (cost !== 0) {
    msg.sendEmail = 1;
    msg.topic = "pause"
    msg.payload = "refetch"
}
else {
    msg.sendEmail = 0
    msg.topic = "start"
    msg.payload = "refetch"
}
return msg;

OK, thank you. Thank you both. I will have a play.

Version 1.0.3. Just playing now.

I am still seeing the same thing.

Command Resp - Send to separate output

Debug nodes to Console.txt (2.5 KB)

[Edit}. As long as you are aware, I shall now have a play. Thank you.

That should do the job as long as you haven't looped the 2nd output back.

Can you screen shot your flow & post an updated export?

Hi Steve,

Screenshots different between Production 1.0.6 and Beta beta.3 versions (Inject Node).



The flood would seem to be apparent in both Node-RED versions.

[{"id":"91dc1292.bb15b8","type":"function","z":"42c2a631.eb624","name":"Slot got value?","func":"var cost = msg.payload;\nif (cost !== 0) {\n    msg.sendEmail = 1;\n    msg.topic = \"pause\"\n    msg.payload = \"refetch\"\n}\nelse {\n    msg.sendEmail = 0\n    msg.topic = \"start\"\n    msg.payload = \"refetch\"\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":660,"y":400,"wires":[["90939623.74a8c8","ebccfa55.f2fed","becebb3b.a72778"]]},{"id":"6a7768be.e5648","type":"cronplus","z":"42c2a631.eb624","name":"Check Data","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output2","outputs":2,"options":[{"name":"refetch","topic":"refetch","payloadType":"str","payload":"1","expressionType":"cron","expression":"0/20 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":310,"y":400,"wires":[["2e0e0a52.804b16","fb43f463.b29a"],["5703c6ce.16a408"]]},{"id":"90939623.74a8c8","type":"debug","z":"42c2a631.eb624","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"sendEmail","targetType":"msg","statusVal":"","statusType":"auto","x":930,"y":400,"wires":[]},{"id":"2e0e0a52.804b16","type":"random","z":"42c2a631.eb624","name":"","low":"0","high":"1","inte":"true","property":"payload","x":480,"y":400,"wires":[["91dc1292.bb15b8"]]},{"id":"61ed2543.31c014","type":"inject","z":"42c2a631.eb624","name":"","props":[{"p":"payload"},{"p":"topic","v":"start","vt":"msg"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"payload":"refetch","payloadType":"msg","x":90,"y":340,"wires":[["6a7768be.e5648"]]},{"id":"ebccfa55.f2fed","type":"debug","z":"42c2a631.eb624","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"topic","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":360,"wires":[]},{"id":"becebb3b.a72778","type":"delay","z":"42c2a631.eb624","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":120,"y":400,"wires":[["6a7768be.e5648"]]},{"id":"fb43f463.b29a","type":"debug","z":"42c2a631.eb624","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":490,"y":340,"wires":[]},{"id":"5703c6ce.16a408","type":"debug","z":"42c2a631.eb624","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":490,"y":460,"wires":[]}]

I'm not seeing any issue (with your latest flow).

I do see a bunch of extraneous console logging (which I need to remove (next update)) but your flow doesnt seem to be running away - I am not seeing this delayed/flooding.

Can I suggest you give all your debug nodes unique names & when the condition occurs, screenshot or dump logs please.

Also, TBH, I am not 100% sure what your end goal is - can you import this & let me know if you are still seeing run-away condition...

[{"id":"ee5aa1e3.353ee","type":"function","z":"132ac715.5caf59","name":"Slot got value?","func":"var cost = msg.payload;\n\nvar controlMsg = {\n    payload : \"refetch\"\n}\n\nif (cost !== 0) {\n    msg.topic = \"Cost is not zero\"; //email subject\n    msg.payload = \"Cost value is \" + cost; //email body\n    msg.sendEmail = 1; //uneccesary flag\n    msg.cost = cost; //for easy access\n\n    controlMsg.topic = \"pause\"; //pause cron\n}\nelse {\n    msg.topic = \"Zero cost\"\n    msg.payload = \"\"\n    msg.sendEmail = 0\n    controlMsg.topic = \"start\"; //start cron\n}\nreturn [msg, controlMsg];","outputs":2,"noerr":0,"x":760,"y":260,"wires":[["bb8da836.15fe68","50b43ed3.ac44","7d2bd06c.431a8"],["1b8d87ea.54bbf8","636b1fc9.0c739"]]},{"id":"4f3f9f7c.192f3","type":"cronplus","z":"132ac715.5caf59","name":"Check Data","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output2","outputs":2,"options":[{"name":"refetch","topic":"refetch","payloadType":"str","payload":"1","expressionType":"cron","expression":"0/20 * * * * *","location":"49.58578744112235 22.148437499999996","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":330,"y":260,"wires":[["77b68706.91dde8","a154bd39.bd9b1"],["44786d11.824164"]]},{"id":"bb8da836.15fe68","type":"debug","z":"132ac715.5caf59","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","x":1020,"y":280,"wires":[]},{"id":"77b68706.91dde8","type":"random","z":"132ac715.5caf59","name":"","low":"0","high":"1","inte":"true","property":"payload","x":580,"y":260,"wires":[["ee5aa1e3.353ee"]]},{"id":"4e7cd905.40a388","type":"inject","z":"132ac715.5caf59","name":"","topic":"","payload":"refetch","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":570,"y":180,"wires":[["77b68706.91dde8"]]},{"id":"50b43ed3.ac44","type":"debug","z":"132ac715.5caf59","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"topic","targetType":"msg","x":1010,"y":220,"wires":[]},{"id":"a154bd39.bd9b1","type":"debug","z":"132ac715.5caf59","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":370,"y":180,"wires":[]},{"id":"44786d11.824164","type":"debug","z":"132ac715.5caf59","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":370,"y":340,"wires":[]},{"id":"1b8d87ea.54bbf8","type":"link out","z":"132ac715.5caf59","name":"","links":["e8d024a6.9a19e8"],"x":835,"y":320,"wires":[]},{"id":"e8d024a6.9a19e8","type":"link in","z":"132ac715.5caf59","name":"","links":["1b8d87ea.54bbf8"],"x":195,"y":300,"wires":[["4f3f9f7c.192f3"]]},{"id":"636b1fc9.0c739","type":"debug","z":"132ac715.5caf59","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"topic","targetType":"msg","x":1010,"y":360,"wires":[]},{"id":"7d2bd06c.431a8","type":"debug","z":"132ac715.5caf59","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"sendEmail","targetType":"msg","x":1030,"y":160,"wires":[]}]

Hi Steve,

I have loaded your flow and will look deeper.

I really need to run this in the 'real world' to see what is happening. But like all these closed loop systems, things rely on other things over which we have no control, to either happen, or not happen!

As to what the flow does, I tried to explain in my first post, just not very well.
If some InfluxDB data obtained from an API is not available at a certain time, I need to trigger a fetch from the same API until the data does become available and is stored in the InfluxDB. Once the data is available, I need to stop accessing the API and also send an email with some of the accessed data in. This happens once a day and so the process starts again at the same time the next day.

This is all part of a far more extensive flow, just trying to keep things simple for developing the flow.

As I mentioned, my concern was that this might be a problem in beta.3 but gladly it seems not, so I am happy. I will carry on experimenting adding your tips into my flow. As ever, the pointers and tips are much appreciated. Even going to add the Context Data flow you gave me before to help me understand.

Thanks for the comments in the function! Very helpful for me!!

1 Like

I have now sat and had a play. Struggling but I think I may have found what is causing the problem.

Having cut the flow down to about as small as makes sense and then played around, I have 3 different nodes, effectively doing the same job (hopefully!).

<controlMsg "start"> is just this...
controlMsg.topic = "start"; //start cron
return [msg, controlMsg];

/Only controlMsg/ is the original function with this change on the last line...
return [controlMsg];

both would appear to work correctly.

As soon as I use your function that has been cut down /Slot got value?/, but with the original...
return [msg, controlMsg];

The problem occurs.

The data in the attached file is from the Context Data log.

Dell Precision M6700
Ubuntu 18.04 LTS
2 Jul 13:34:54 - [info] Node-RED version: v1.1.0
2 Jul 13:34:54 - [info] Node.js version: v12.18.1
2 Jul 13:34:54 - [info] Linux 5.3.0-61-generic x64 LE
2 Jul 13:34:55 - [info] Loading palette nodes
2 Jul 13:34:55 - [info] Dashboard version 2.22.1 started at /ui
2 Jul 13:34:56 - [warn] rpi-gpio : Raspberry Pi specific node set inactive

...and yes, I have updated to cronplus 1.0.4

[{"id":"29fe22bc.d8644e","type":"function","z":"1fe2e6f5.206b79","name":"controlMsg \"start\"","func":"controlMsg.topic = \"start\"; //start cron\n\nreturn [msg, controlMsg];","outputs":2,"noerr":0,"initialize":"","finalize":"","x":450,"y":220,"wires":[[],["2f3d2f97.ae8dd"]]},{"id":"1c819368.f5f60d","type":"cronplus","z":"1fe2e6f5.206b79","name":"Check Data","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output2","outputs":2,"options":[{"name":"refetch","topic":"refetch","payloadType":"str","payload":"1","expressionType":"cron","expression":"0/20 * * * * *","location":"49.58578744112235 22.148437499999996","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":190,"y":220,"wires":[["4b370e9f.ac9528","c09d8686.76d87"],[]]},{"id":"2f3d2f97.ae8dd","type":"link out","z":"1fe2e6f5.206b79","name":"","links":["63a81466.153c44"],"x":595,"y":260,"wires":[]},{"id":"63a81466.153c44","type":"link in","z":"1fe2e6f5.206b79","name":"","links":["2f3d2f97.ae8dd","66a7609e.3162c8","c37657d4.22ba28"],"x":55,"y":260,"wires":[["1c819368.f5f60d"]]},{"id":"4b370e9f.ac9528","type":"function","z":"1fe2e6f5.206b79","name":"Context log","func":"var contextname = \"cron_log\";\n\nvar log = flow.get(contextname) || [];\n\nvar logEntry = {\n    msg: RED.util.cloneMessage(msg),\n    time: new Date()\n}\n\nlog.push(logEntry);\n\nflow.set(contextname, log);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":430,"y":160,"wires":[[]]},{"id":"c09d8686.76d87","type":"function","z":"1fe2e6f5.206b79","name":"Slot got value?","func":"var cost = 0;\n//var cost = msg.payload;\n\nvar controlMsg = {\n    payload : \"refetch\"\n}\n\nif (cost !== 0) {\n    msg.topic = \"Cost is not zero\"; //email subject\n    msg.payload = \"Cost value is \" + cost; //email body\n    msg.sendEmail = 1; //uneccesary flag\n    msg.cost = cost; //for easy access\n\n    controlMsg.topic = \"pause\"; //pause cron\n}\nelse {\n    msg.topic = \"Zero cost\"\n    msg.payload = \"\"\n    msg.sendEmail = 0\n    controlMsg.topic = \"start\"; //start cron\n}\nreturn [msg, controlMsg];","outputs":2,"noerr":0,"initialize":"","finalize":"","x":460,"y":280,"wires":[[],["66a7609e.3162c8"]]},{"id":"66a7609e.3162c8","type":"link out","z":"1fe2e6f5.206b79","name":"","links":["71457be0.e7c1bc","63a81466.153c44"],"x":595,"y":320,"wires":[]},{"id":"89195fd9.10ea88","type":"function","z":"1fe2e6f5.206b79","name":"Only controlMsg","func":"var cost = 0;\n//var cost = msg.payload;\n\nvar controlMsg = {\n    payload : \"refetch\"\n}\n\nif (cost !== 0) {\n    msg.topic = \"Cost is not zero\"; //email subject\n    msg.payload = \"Cost value is \" + cost; //email body\n    msg.sendEmail = 1; //uneccesary flag\n    msg.cost = cost; //for easy access\n\n    controlMsg.topic = \"pause\"; //pause cron\n}\nelse {\n    msg.topic = \"Zero cost\"\n    msg.payload = \"\"\n    msg.sendEmail = 0\n    controlMsg.topic = \"start\"; //start cron\n}\nreturn [controlMsg];","outputs":2,"noerr":0,"initialize":"","finalize":"","x":460,"y":340,"wires":[[],["c37657d4.22ba28"]]},{"id":"c37657d4.22ba28","type":"link out","z":"1fe2e6f5.206b79","name":"","links":["63a81466.153c44"],"x":595,"y":380,"wires":[]}]

Cron_log.txt (9.5 KB)

1 Like

I see it now - gonna look into this ASAP

Thanks for your patience and feedback.

Thank you.

No rush from my end.

Hey @mudwalker

I believe I have found the issue and "contained it" for now (I have raised an issue on an underlying library).

Can you please update to V1.0.6 and let me know :crossed_fingers:

Thanks for your patience and support.

Steve.

Hi @Steve-Mcl ,

Thank you for your rapid response!! Much appreciated.

Ran my 'noddy' flow and all appears to be good. I will leave it running and let you know, but I don't doubt that if you have identified the problem, your workaround will be good!

Colin

1 Like

Hi @Steve-Mcl

Just an FYI
To better explain what I was/am trying to do, here is the flow I have ended up with.

Your efforts have not gone in vain and are much appreciated!

[{"id":"3ae76361.c44e84","type":"change","z":"1fe2e6f5.206b79","name":"","rules":[{"t":"set","p":"slots","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":100,"wires":[["c47ce33b.acc1b8"]]},{"id":"f967f962.57fb2","type":"comment","z":"1fe2e6f5.206b79","name":"Get Octopus slot pricing & store @17:53, data is for 1600 today until 2300 tomorrow","info":"https://discourse.nodered.org/t/best-strategy-for-reading-sorting-electricity-cost-array/7929\n","x":370,"y":60,"wires":[]},{"id":"2c62a350.5abbe4","type":"file","z":"1fe2e6f5.206b79","name":"","filename":"OctopusPrices.json","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"none","x":1030,"y":100,"wires":[["3ee0a0a4.5e4718"]]},{"id":"c47ce33b.acc1b8","type":"http request","z":"1fe2e6f5.206b79","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-H/standard-unit-rates/","tls":"","persist":false,"proxy":"","authType":"","x":530,"y":100,"wires":[["b499a7a8.89ad5"]]},{"id":"fc481d42.5de148","type":"function","z":"1fe2e6f5.206b79","name":"","func":"var now =  Date.now();\n\nvar payload = msg.payload.results;\n\n//payload.results[0].valid_from\n\nfor(var i = 0; i < payload.length; i++){\n    msg.payload.results[i].valid_from = Date.parse(msg.payload.results[i].valid_from);\n    msg.payload.results[i].valid_to = Date.parse(msg.payload.results[i].valid_to);\n}\n\n/*\n//Comment this section out when data missing.\nvar data = msg.payload.results;\nvar newData = data.filter(item => {\n    return item.valid_from > now;\n});\nmsg.payload.results = newData;\n//\nmsg.payload.results = data;\n// to get missing data\n*/\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":840,"y":100,"wires":[["2c62a350.5abbe4","a0c2161b.5472e"]]},{"id":"b499a7a8.89ad5","type":"json","z":"1fe2e6f5.206b79","name":"","property":"payload","action":"obj","pretty":false,"x":690,"y":100,"wires":[["fc481d42.5de148"]]},{"id":"577f452e.0df87c","type":"link out","z":"1fe2e6f5.206b79","name":"","links":["207838b6.102de8"],"x":1315,"y":100,"wires":[]},{"id":"3ee0a0a4.5e4718","type":"delay","z":"1fe2e6f5.206b79","name":"","pauseType":"delay","timeout":"30","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1220,"y":100,"wires":[["577f452e.0df87c","47351e64.6b203"]]},{"id":"4f4e7d65.e2b2d4","type":"comment","z":"1fe2e6f5.206b79","name":"Check InfluxFB has been filled for midnight today, if so, send email, if not refetch","info":"","x":820,"y":140,"wires":[]},{"id":"ddf1ed4c.0d881","type":"cronplus","z":"1fe2e6f5.206b79","name":"Update Octopus","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output2","outputs":2,"options":[{"name":"Update","topic":"Update","payloadType":"str","payload":"8","expressionType":"cron","expression":"0 53 17 * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":140,"y":100,"wires":[["3ae76361.c44e84"],[]]},{"id":"a0c2161b.5472e","type":"link out","z":"1fe2e6f5.206b79","name":"API Slots","links":["cf76cd0a.7986b8"],"x":935,"y":60,"wires":[]},{"id":"ba71f6ac.c921d","type":"cronplus","z":"1fe2e6f5.206b79","name":"Check Data */1","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output2","outputs":2,"options":[{"name":"refetch","topic":"refetch","payloadType":"str","payload":"1","expressionType":"cron","expression":"0/5 * * * * ","location":"49.58578744112235 22.148437499999996","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":200,"y":160,"wires":[["3ae76361.c44e84"],[]]},{"id":"c25a0794.4e241","type":"link in","z":"1fe2e6f5.206b79","name":"","links":["2f3d2f97.ae8dd","3263b051.51d618","c37657d4.22ba28"],"x":55,"y":160,"wires":[["ba71f6ac.c921d"]]},{"id":"3263b051.51d618","type":"link out","z":"1fe2e6f5.206b79","name":"","links":["c25a0794.4e241"],"x":1175,"y":200,"wires":[]},{"id":"47351e64.6b203","type":"function","z":"1fe2e6f5.206b79","name":"InfluxDB query","func":"var d = new Date();\n//d.setHours(25,0,0,0); // next midnight\nd.setHours(1,0,0,0); // previous midnight\nd = Date.parse(d);\nd = d * 1000000\nd = \"SELECT * FROM slots WHERE time = \" + d;\nmsg.query = d;\n//msg.payload =\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":180,"wires":[["6dcbfd09.dab3b4"]]},{"id":"6dcbfd09.dab3b4","type":"influxdb in","z":"1fe2e6f5.206b79","influxdb":"6e737abc.a8cef4","name":"InfluxDB / energy","query":"","rawOutput":false,"precision":"","retentionPolicy":"","x":830,"y":180,"wires":[["79ec9b17.a46b5c"]]},{"id":"79ec9b17.a46b5c","type":"function","z":"1fe2e6f5.206b79","name":"Slot got value?","func":"var cost = msg.payload;\n\n\nvar controlMsg = {\n    payload : \"refetch\"\n}\n\nif (cost === 0) {\n    msg.email = 0;\n    controlMsg.topic = \"start\"; //start cron\n}\nelse {\n    msg.email = 1;\n    controlMsg.topic = \"pause\"; //pause cron\n}\nreturn [msg, controlMsg];","outputs":2,"noerr":0,"initialize":"","finalize":"","x":1040,"y":180,"wires":[["571c4497.4087b4"],["3263b051.51d618"]]},{"id":"9acc5590.ddcda","type":"debug","z":"1fe2e6f5.206b79","name":"eMail","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1230,"y":240,"wires":[]},{"id":"b4b95892.d10a4","type":"link out","z":"1fe2e6f5.206b79","name":"Send email out","links":["f39ea767.1fbcb8"],"x":975,"y":300,"wires":[]},{"id":"f39ea767.1fbcb8","type":"link in","z":"1fe2e6f5.206b79","name":"Send email in","links":["b4b95892.d10a4"],"x":295,"y":300,"wires":[["cbe9d1da.c9a8e"]]},{"id":"18a666f5.6286d1","type":"inject","z":"1fe2e6f5.206b79","name":"evening stop","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"email","v":"0","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"pause","payload":"evening","payloadType":"str","x":350,"y":340,"wires":[["cbe9d1da.c9a8e"]]},{"id":"5fd8791f.193b88","type":"function","z":"1fe2e6f5.206b79","name":"msg.email","func":"if (msg.email === 1) {\n    msg.payload = \"evening\";\n    msg.topic = \"start\"; //start cron\n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":410,"y":260,"wires":[["cbe9d1da.c9a8e"]]},{"id":"cbe9d1da.c9a8e","type":"cronplus","z":"1fe2e6f5.206b79","name":"send_eMails","outputField":"topic","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output2","outputs":2,"options":[{"name":"Morning","topic":"morning","payloadType":"str","payload":"0800hrs to 2300hrs today","expressionType":"cron","expression":" 0 0 8 * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"evening","topic":"evening","payloadType":"str","payload":"now until 2300hrs tomorrow","expressionType":"cron","expression":"* 18-23 * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":590,"y":280,"wires":[["3d33c899.9b5ce"],[]]},{"id":"fcbd07a9.14b7","type":"change","z":"1fe2e6f5.206b79","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"message","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"subject","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1040,"y":260,"wires":[["9acc5590.ddcda","71e9c04b.a13f6"]]},{"id":"3d33c899.9b5ce","type":"function","z":"1fe2e6f5.206b79","name":"send email. pause cron","func":"var slots = msg.topic;\n\n\nvar controlMsg = {\n    payload : \"evening\"\n}\n\n\n    msg.subject = \"Octopus slots from \" + slots;\n    msg.message = \"Some message here\"\n    msg.to = \"Joe <recipient@example.com>\";\n    msg.from = \"Node Red <sender@example.com>\";\n    \n    \n    \n    controlMsg.topic = \"pause\"; //pause cron\n\n\nreturn [msg, controlMsg];","outputs":2,"noerr":0,"initialize":"","finalize":"","x":810,"y":280,"wires":[["fcbd07a9.14b7"],["b4b95892.d10a4"]]},{"id":"f387424f.05f2a8","type":"link in","z":"1fe2e6f5.206b79","name":"","links":["45a2afc9.2ddac","571c4497.4087b4"],"x":295,"y":260,"wires":[["5fd8791f.193b88"]]},{"id":"71e9c04b.a13f6","type":"function","z":"1fe2e6f5.206b79","name":"Log2Context","func":"var contextname = \"cron_log\";\n\nvar log = flow.get(contextname) || [];\n\nvar logEntry = {\n    msg: RED.util.cloneMessage(msg),\n    time: new Date()\n}\n\nlog.push(logEntry);\n\nflow.set(contextname, log);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1250,"y":280,"wires":[[]]},{"id":"571c4497.4087b4","type":"link out","z":"1fe2e6f5.206b79","name":"","links":["f387424f.05f2a8"],"x":1175,"y":160,"wires":[]},{"id":"b85323d.a697ee","type":"inject","z":"1fe2e6f5.206b79","name":"Push to Test!","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":410,"y":180,"wires":[["47351e64.6b203"]]},{"id":"6dd78b49.d8ae7c","type":"inject","z":"1fe2e6f5.206b79","name":"refetch stop","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"pause","payload":"refetch","payloadType":"str","x":110,"y":220,"wires":[["ba71f6ac.c921d"]]},{"id":"65a231aa.96568","type":"comment","z":"1fe2e6f5.206b79","name":"Send an email @ 0800, and when data first becomes available after fetching","info":"","x":810,"y":220,"wires":[]},{"id":"6e737abc.a8cef4","type":"influxdb","z":"","hostname":"localhost","port":"8086","protocol":"http","database":"","name":"","usetls":false,"tls":""}]
1 Like

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