Managing schedule of mutually exclusive scenes

Say that I have 2 scenes, morning and evening and I want different nodes to trigger every x minutes. For the sake of the example, the Night node triggers every 5 minutes during the morning and the Evening node triggers ever 5 minutes during the evening. No nodes should trigger in the afternoon.

One way of dealing with it is with a set of timers that trigger at the beginning and end of the morning and another that triggers at the beginning and end of the night. BigTimer does this however it is very cumbersome, especially if I have more than 2 scenes and if a scene ends at the same time that another scene starts.

Ideally I want something like node-red-contrib-light-scheduler (node) - Node-RED which allows me to set a schedule. This particular contrib however does not tell me the "name" of the scene so I can't distinguish between the morning and the evening without looking at the time.

Does anyone have any suggestions on how to do it nicely?

Node-red-contrib-cron-plus can do everything you need. It has lots of built in examples (ctrl+I --> examples)

A lot of folks are scared off by the Cron syntax but this node has a helper & extensive tool tips.

You can use one or multiple nodes. Each node can have 0, 1 or more schedules. You can set the topic and payload that is sent to anything you want.

And everything can be automated by input control messages. These are all documented in the built in help.

I've given it a try but I'm not sure it does what I want (I am quite familiar with the cron syntax) in a simpler way than with BigTimer.
What I want to be able to do is stuff like
10:00 -> 12:00 : Send "Morning" every minute
12:00 -> 16:37 : Send "Afternoon" every minute
16:37 -> 20:00 : Send "Afternoon" every minute

am I missing something?

do you really want to send a string of "Morning" every minute between 10:00 ~ 12:00?

image

Alternatively, if you didnt mean fixed times (and want actual solar state from location coordinates) then you can simply poll the CRON node every minute & ask for solar state...

[{"id":"4a271714.8ef808","type":"cronplus","z":"a2d1264d.2189b8","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[],"x":1700,"y":120,"wires":[["f741509.947aeb","3c05b2a6.a43e1e"]]},{"id":"560a940b.49825c","type":"cronplus","z":"a2d1264d.2189b8","name":"every-minute","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"min","topic":"describe","payloadType":"json","payload":"{\"command\":\"describe\",\"expressionType\":\"solar\",\"solarType\":\"all\",\"solarEvents\":\"sunrise,sunset\",\"location\":\"51.5024701136258 0.011844635009765625\"}","expressionType":"cron","expression":"0 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":1490,"y":120,"wires":[["4a271714.8ef808"]]},{"id":"8e87e155.6e8e5","type":"debug","z":"a2d1264d.2189b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload.state","statusType":"msg","x":1870,"y":200,"wires":[]},{"id":"f741509.947aeb","type":"function","z":"a2d1264d.2189b8","name":"morning? afternoon? night?","func":"var solarState = msg.payload.result.solarState;\nmsg.payload = { };\nif(solarState.day && solarState.direction == \"fall\") {\n    msg.payload.state = \"afternoon\";\n} else if (solarState.eveningTwilight) {\n    msg.payload.state = \"evening\";\n} else if (solarState.night) {\n    msg.payload.state = \"night\";\n} else {\n    msg.payload.state = \"morning\";\n}\nmsg.payload.details = solarState;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1540,"y":200,"wires":[["8e87e155.6e8e5"]]},{"id":"3c05b2a6.a43e1e","type":"debug","z":"a2d1264d.2189b8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1850,"y":120,"wires":[]}]

I was just making an example - I don't actually care about the mornings. I just want to be able to get the state of multiple, non overlapping events, in an easy way.

Unfortunately Cron doesn't have syntax to express non full hours intervals. Eh. 10:30 to 11:16

Imagine a UI like a thermostat but with multiple values.

The simple node-red-node-timeswitch (node) - Node-RED does that - I has a per minute output as well as "on the event" output. Only one timer per node instance though.

No, it doesnt but you can add multiple schedules (either statically or dynamically via a dashboard forexample)


Any how, there isnt much you cant do with cron-plus (sometimes more with the addition of another node like a switch or function to act as a filter or a change to store state etc) but I hope at least I have demonstrated some possibilities.

Feel free to take or leave it :slight_smile:

If you are using the node-red-dashboard then also have a look at: node-red-contrib-ui-time-scheduler.

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