Cronplus - trigger based on schedule condition?

My apologies if I missed this within the excellent docs I have read so far.

Can cronplus node act as a condition for incoming triggers? For example, I have a door sensor which I want to trigger a light to come on, but only when it's dark (i.e. within a particular schedule as defined by cronplus?)

It's very easy to do with the gate node, but I just wondered if this was built in?

A reason why it might not be so good using a gate node is as follows: I have to wait for the cron condition to set that gate. For example, I may restart Node-RED and then nothing will work until the next cron event.

Yes you can use cron-tab to set a flow variable. In combination with a switch, node you can steer if a motion event will pass the switch node or not.

With an inject node you can initialize this flow variable as well, to have a defined condition.

You can even use only a switch node which can decide directly if the motion event will pass without any scheduling event, just by testing the daytime when the event occurs. In this case not even an initialization is necessary.

I like the idea of using an environment variable like a gate node, it just shows there are so many different ways to achieve the same thing in Node-RED.

Yes this is exactly what I'm asking, how to do this? How to set the state of a variable based on a condition (i.e. open if dark, closed if light), not just setting it manually (i.e. open). How do I inject into the cronplus node, to achieve an outcome based on the current time of day?

I understand that the cronplus node will send a single message when it changes from light to dark (based on sunrise / sunset), which can set up a variable / gate status / etc. However I still don't understand how to dynamically test for those conditions, e.g. if the variable / gate status has not yet been set?

You dont have to inject anything to Cron plus .. the opposite ..
as @mickym2 said configure Cron plus (solar events) to inject and set a flow context variable that defines whether its day or night (a variable that can be later used in other parts of your flow to block execution)

For Example:

[{"id":"f58f72032eb7bd50","type":"cronplus","z":"54efb553244c241f","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"day","topic":"day","payloadType":"bool","payload":"true","expressionType":"solar","expression":"0 * * * * * *","location":"35.36038458458532 32.87109375","offset":"0","solarType":"selected","solarEvents":"sunrise"},{"name":"night","topic":"night","payloadType":"bool","payload":"false","expressionType":"solar","expression":"0 * * * * * *","location":"34.9291775968022 33.046875","offset":"0","solarType":"selected","solarEvents":"sunset"}],"x":540,"y":1260,"wires":[["b3f1ab45e814b0b8"]]},{"id":"b3f1ab45e814b0b8","type":"change","z":"54efb553244c241f","name":"","rules":[{"t":"set","p":"isDay","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":1260,"wires":[[]]}]

If its day .. flow.isDay will be true
if its night .. flow.isDay will false

So you can directly ask the status of the cronplus node if it is day or night.

The result is in

msg.payload.result.status.solarState.state

In a switch Node you can directly ask the content of the flow variable.

image

And the inject Node will initialize the flow variable.

You can also use directly bool- variables as the result of the crontab node is very detailed:

Ahhh - that's exactly what I wanted to know. I just didn't know how to query the cronplus node for its current status, but that explains it.

To be honest, I thought sending "status" to the cronplus node would confirm the status of the schedule, i.e. whether that schedule was enabled or disabled, and other metadata. I didn't try it, because I didn't even think it would "trigger" a query to see whether that schedule was currently active.

Thanks!

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