Cron plus output

Trying to setup cron plus for sunrise sunset events outputting boolean-logic, for several days have tried to see what outputs when but due to several missteps haven't had any luck. I am assuming the node will output true at sunset then false at sunrise, can someone verify that please?

You need to set 2 events; one for sunset, and a second for sunrise.
You can set whatever output you want for each event.

As @Paul-Reed already stated you can output whatever you wish. To add to that ...

You could add 2 schedules (one for sunrise, one for sunset), each with own topic and whatever payload you care to send - just enter what type and value in the payload field in the list of schedules.

Or

You could have 1 schedule with both sunrise and sunset selected with the default payload (if you check the debug output you will see how you can identify which is which)

If you are struggling, I'll send you a screenshot or example flow

Got it so close, but.......
There is a tab on the left side of the node you can press to fire the node. I would like to have the node output every minute or so, is there a way to do that with the solar events selected?

Yes, kinda, but why? A solar event happens once per day.

Explain what you are trying to achieve.

Note: you can always store to context the current solar state & use a 1sec pulse to compare it to a desired value.

Additionally you can trigger any Cron-plus schedule by firing a message into it. Read the built in help for how to & try the built in examples (CTRL-I > examples > Cron-plus)

Trying to countdown to sunset, then count down to sunrise

Ok, so you can send a status request message to the Cron plus node (it's documented in the built in help and in one of the built in demos)

The resulting msg will have various properties relating to solar state - one of them being the time of the next event. You could poll the Cron node and use this timestamp to determine how long until the solar event.

1 Like

Hit a wrinkle, when the node fires on auto pilot it sends msg.cronplus.... when I query status it sends msg.payload....
That messes with the code downstream

Hello Gerry .. Show us how you have configured the cron-plus node. (better share an exported flow)
I suspect you set the node's Output property to send the msg to msg.cronplus ??

node setup

[{"id":"725ce986ad0ed73f","type":"tab","label":"Light Timer","disabled":false,"info":"","env":[]},{"id":"1d722d8e960ff38c","type":"function","z":"725ce986ad0ed73f","name":"on off time","func":"let Z = msg.payload.result[0].status.nextDescription;\nlet MyText = Z;\nlet Result = MyText.replace(\"hour\", \"hr\");\nMyText = Result;\nResult = MyText.replace(\"minutes\", \"min\");\nMyText = Result;\nResult = MyText.replace(\"seconds\", \"sec\");\n\n    msg = {\n        payload: Result,\n    }\n\nnode.status({fill:\"blue\",shape:\"dot\",text: Result});\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":280,"wires":[["5e450ba3197daf5d"]]},{"id":"89a6696b56acaffa","type":"ui_template","z":"725ce986ad0ed73f","group":"e4085d44342e34c2","name":"night or day","order":4,"width":6,"height":1,"format":"<div>\n   <md-button class=\"md-button mine-button\"\n    data-topic=\"target\"\n    data-payload=\"1\">{{msg.payload}}\n   </md-button>\n</div>\n","storeOutMessages":true,"fwdInMessages":false,"resendOnRefresh":false,"templateScope":"local","className":"","x":690,"y":220,"wires":[[]]},{"id":"5e450ba3197daf5d","type":"ui_template","z":"725ce986ad0ed73f","group":"e4085d44342e34c2","name":"off on text","order":5,"width":6,"height":1,"format":"<div>\n   <md-button class=\"md-button mine-button\"\n    data-topic=\"target\"\n    data-payload=\"1\">{{msg.payload}}\n   </md-button>\n</div>\n","storeOutMessages":true,"fwdInMessages":false,"resendOnRefresh":false,"templateScope":"local","x":680,"y":280,"wires":[[]]},{"id":"708a9b7b39125171","type":"ui_template","z":"725ce986ad0ed73f","group":"e4085d44342e34c2","name":"sunrise","order":2,"width":6,"height":1,"format":"<div>\n   <md-button class=\"md-button mine-button\"\n    data-topic=\"target\"\n    data-payload=\"1\">{{msg.payload}}\n   </md-button>\n</div>\n","storeOutMessages":true,"fwdInMessages":false,"resendOnRefresh":false,"templateScope":"local","x":980,"y":320,"wires":[[]]},{"id":"29d0a1e042e45a76","type":"ui_template","z":"725ce986ad0ed73f","group":"e4085d44342e34c2","name":"sunset","order":3,"width":6,"height":1,"format":"<div>\n   <md-button class=\"md-button mine-button\"\n    data-topic=\"target\"\n    data-payload=\"1\">{{msg.payload}}\n   </md-button>\n</div>\n","storeOutMessages":true,"fwdInMessages":false,"resendOnRefresh":false,"templateScope":"local","x":970,"y":400,"wires":[[]]},{"id":"882599ddb8c4cca7","type":"ui_template","z":"725ce986ad0ed73f","group":"e4085d44342e34c2","name":"light timers time date","order":1,"width":6,"height":1,"format":"<div>\n   <md-button class=\"md-button mine-button\"\n    data-topic=\"target\"\n    data-payload=\"1\">{{msg.payload}}\n   </md-button>\n</div>\n","storeOutMessages":true,"fwdInMessages":false,"resendOnRefresh":false,"templateScope":"local","className":"","x":500,"y":120,"wires":[[]]},{"id":"b59011b8a8159713","type":"function","z":"725ce986ad0ed73f","name":"sunset","func":"let Z = msg.payload.result[0].status.solarTimes[0].time;\n\nnode.status({ fill: \"red\", shape: \"ring\", text:Z});\n\nmsg.payload = Z;\n\nreturn msg;\n\n//payload.result[0].status.solarTimes[0].time","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":420,"wires":[["e325f73816856bb7"]]},{"id":"e13f97af6e1c814e","type":"function","z":"725ce986ad0ed73f","name":"sunset fix","func":"msg.payload = 'Sunset is at ' + msg.payload;\nnode.status({fill:\"blue\",shape:\"dot\",text:msg.payload});\nreturn msg;","outputs":1,"noerr":0,"x":820,"y":400,"wires":[["29d0a1e042e45a76"]]},{"id":"1b7d8d6b5dc8c978","type":"function","z":"725ce986ad0ed73f","name":"sunrise","func":"/*\nlet Z = msg.cronplus.status.solarTimes[1].time;\nif (typeof Z == 'undefined') {\n    Z = 100;\n}\n*/\nlet X = msg.payload.result[0].status.solarTimes[1].time;\n\nnode.status({ fill: \"red\", shape: \"ring\", text: X });\n\nmsg.payload = X;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":340,"wires":[["a615e26278b0e09d"]]},{"id":"4a0e676e30fc1f1e","type":"function","z":"725ce986ad0ed73f","name":"sunrise fix","func":"msg.payload = 'Sunrise is at ' + msg.payload;\nnode.status({fill:\"blue\",shape:\"dot\",text:msg.payload});\nreturn msg;","outputs":1,"noerr":0,"x":820,"y":320,"wires":[["708a9b7b39125171"]]},{"id":"0a1ba7458042281c","type":"link in","z":"725ce986ad0ed73f","name":"light timers time in","links":["8d061b4d19f61c93"],"x":235,"y":120,"wires":[["882599ddb8c4cca7"]]},{"id":"e325f73816856bb7","type":"moment","z":"725ce986ad0ed73f","name":"Sunset","topic":"","input":"","inputType":"msg","inTz":"America/Denver","adjAmount":0,"adjType":"days","adjDir":"add","format":"h:mm A","locale":"en_US","output":"","outputType":"msg","outTz":"America/Denver","x":640,"y":420,"wires":[["e13f97af6e1c814e"]]},{"id":"a615e26278b0e09d","type":"moment","z":"725ce986ad0ed73f","name":"Sunrise","topic":"","input":"","inputType":"msg","inTz":"America/Denver","adjAmount":0,"adjType":"days","adjDir":"add","format":"h:mm A","locale":"en_US","output":"","outputType":"msg","outTz":"America/Denver","x":640,"y":340,"wires":[["4a0e676e30fc1f1e"]]},{"id":"846823ed4e3c45a9","type":"cronplus","z":"725ce986ad0ed73f","name":"Sunrise Sunset","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"schedule1","topic":"schedule1","payloadType":"bool","payload":"true","expressionType":"solar","expression":"0 * * * * * *","location":"50.5,-116","offset":"0","solarType":"selected","solarEvents":"sunrise,sunset"}],"x":180,"y":320,"wires":[["db3908a745229680","1d722d8e960ff38c","1b7d8d6b5dc8c978","b59011b8a8159713","a162fdbf0dd358ef"]]},{"id":"db3908a745229680","type":"function","z":"725ce986ad0ed73f","name":"Night or Day","func":"\n\nlet Z = msg.payload.result[0].status.solarState.night;\n\nlet X = msg.payload.result[0].status.solarState.day;\n\nif (Z == false && X == false) {\n    msg = {\n        payload: 'It is Nighttime',\n        topic: 'Night',\n    }\n    flow.set('night', true);\n    node.status({ fill: \"blue\", shape: \"dot\", text: msg.payload });\n    return msg;\n}\n\nif (Z == true) {\n    msg = {\n        payload: 'It is Nighttime',\n        topic: 'Night',\n    }\n    flow.set('night', true);\n}\n\nif (Z == false) {\n    msg = {\n        payload: 'It is Daytime',\n        topic: 'Day',\n    }\n    flow.set('night', false);\n}\n\nnode.status({ fill: \"blue\", shape: \"dot\", text: msg.payload });\n\n\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":220,"wires":[["89a6696b56acaffa"]]},{"id":"4d225e0e5a48fd30","type":"link in","z":"725ce986ad0ed73f","name":"Light time 1 sec in","links":["7f96ac88bb8c31aa"],"x":75,"y":500,"wires":[["41b018158254ea5e"]]},{"id":"a162fdbf0dd358ef","type":"debug","z":"725ce986ad0ed73f","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":470,"y":480,"wires":[]},{"id":"41b018158254ea5e","type":"function","z":"725ce986ad0ed73f","name":"","func":"msg = {\n    payload: 1,\n    topic: 'status-all'\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":190,"y":500,"wires":[["846823ed4e3c45a9"]]},{"id":"af9d0d21e0f24e13","type":"inject","z":"725ce986ad0ed73f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":80,"y":440,"wires":[["41b018158254ea5e"]]},{"id":"e4085d44342e34c2","type":"ui_group","name":"Header","tab":"df1fb04258db07a7","order":1,"disp":false,"width":"6","collapse":false},{"id":"df1fb04258db07a7","type":"ui_tab","name":"Light Timer","icon":"fa-clock-o","order":5,"disabled":false,"hidden":false}]

[EDIT] When the node auto fires I don't know what the output looks like, when I fire the node manually it is a different output

In this case yes .. when you manually trigger the node, you are right, the node's status and config is in msg.cronplus but dont worry about that because when it triggers by itself on sunrise / sunset the msg will be as you configured it (i dont see anything wrong with your configuration)

Once I got my mind wrapped around that (manual vs auto) it seems to be fine. Just wish I had known that small fact about the differences in payload when I started, oh well.

I use the node but i didnt notice the difference either till you mentioned it :sweat_smile:

It would be better if you set your cron-plus node to send the status messages to a seperate output.
The top one for the actual event msg payload and the bottom one for the status msgs.
This way its cleaner to seperate the logic and avoid any errors for the function nodes.

Rewiring :

image

image

1 Like

Thanks, will do.

Excellent demo - might have to add that to the built in examples. :+1:

The node-red-node-suncalc only does sunrise and sunset - but does send a 1 (light) or 0 (dark) every minute...

Thanks for the heads up on the node, I'll put that in my memory bank for future use as I got the cron plus node working like I want
[EDIT]
Just as a side note I moved to cron plus in this instance because big timer for others was having trouble and it appears wasn't supported any more. There was a big timer node in the flow but I was concerned that some where down the road that node would quit when some dependency changed then I'd be hooped.
Is there not some policy/agreement/standard procedure that when a node gets abandoned there should at least be a mention of that on their install for the node?

Yes. Cron-plus can just about do it all. Great place to start.
If a node is abandoned then by definition it is unlikely to get and update to its readme to say that it is no longer receiving updates

I volunteer to find the authors and speed slap them. :slight_smile:

1 Like

Just add a trigger node to the output of Cron+, it will then repeat the last message every minute, or as often as you want.

trigger

1 Like