How do I stop messages according to date?

I have a command that turns on power to the blinds at 05:55, so my wife, who gets up early, can lower halfway down the one in the window she's sitting by (there are several) and not be blinded by the low sun. But it's only necessary from mid May to mid September here in Norway. How can I stop mesages if the date is from the 16th of September and to the 14th of May, but let them go through if it's from the 15th of May and to the 15th of September? I have a sneaking suspicion that the answer may be a Function node. I have one with this code:

msg.payload = {
    relay:0,
    on:true
};
return msg;

That's the code to turn on the Shelly switch, which turns on the power to the blinds. I think I should use an if-then there, so the payload is set to something else (which then won't trigger the Shelly) if between 16th of September and 14th of May, but I'm not sure what that should be.

Many ways to do this.
This example uses JSONata and moments in a switch node.
There are contrib nodes that will do this to.

[{"id":"14e67ff4e0591ac4","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":" {     \"relay\":0,     \"on\":true }","payloadType":"json","x":330,"y":80,"wires":[["675924b00eaaa4da"]]},{"id":"675924b00eaaa4da","type":"switch","z":"d1395164b4eec73e","name":"","property":"$number($moment().format(\"DDD\"))","propertyType":"jsonata","rules":[{"t":"btwn","v":"136","vt":"num","v2":"259","v2t":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":490,"y":80,"wires":[[],["4c147035c4b63827"]]},{"id":"4c147035c4b63827","type":"debug","z":"d1395164b4eec73e","name":"debug 2565","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":80,"wires":[]}]
1 Like

You could use cron-plus to only send the message from 15th May to 15th September.

You would need three schedules defined in the node:

  1. 55 5 15-31 5 * (15th to 31st May)
  2. 55 5 * 6-8 * (Jun to Aug)
  3. 55 5 1-15 9 * (1st to 15th Sep)

Note that cron-plus can also send messages at sunrise or at sunrise +n minutes

1 Like

Thanks, both of you! I have implemented the solution from @E1cid, and then I'll check the logs of the Shellys to see if it works as it should, which I fully expect them to do!

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