Hi!
I have to empty the tank of my dehumidifier every 20 days. I need a reminder to do it!
So, I want to send a telegram message every 20 days to remind me of this.
With cronplus, I have tried the */20 for the days but it ends up being 1st and 21st of the month (kind of modulo rounded by month).
My alternative would be to program in cronplus the next dynamic schedule 20 days from the current execution.
Is there a better way in cronplus or else to do this "every 20 days" ? The inject method with a frequency of 480 hours is reset by the restart of the flows, so, this one is not usable. I think.
Thanks.
(Maybe edit the title to something like: How to get a 20 day time between signals)
As is it is a bit confusing.
And sorry I can't help. That is a good question.
How about this:
[{"id":"0345eaaca6d49d66","type":"trigger","z":"0918ee609bf69fc7","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"-480","extend":false,"overrideDelay":false,"units":"hr","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":2600,"y":3900,"wires":[[]]}]
I think you should use persistent context to store the date it was last sent and inject (timestamp) by cronplus once a day.
This function might do the job
const now = msg.payload;
const then = context.get('lastsent') || 0
const interval = 20 * 24 * 60 * 60 * 1000 // milliseconds!
if ( now - then > interval) {
context.set ('lastsent', now)
return msg
}
The best solution would be something that doesnt rely on "remembering" anything (as that memory can get lost).
A simple way is to fire a CRON or INJECT once per day (at the time you wish to be alerted) then calculate the number of days since epoch then modulo 20.
e.g...
const mod = (parseInt(Date.now() / 1000 / 60 / 60 / 24) % 20)
if (mod === 0) {
// today is the day
msg.payload = "whatever you want"
return msg
}
You can always spice it up with some node status
Demo flow (import using CTRL-I
)
[{"id":"0e0b79405aa2abd7","type":"inject","z":"10ece3ab98e93683","name":"23rd 12:00","props":[{"p":"date","v":"1666522800000","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":2140,"y":1580,"wires":[["da9711c8a01c1732"]]},{"id":"c99f1b00b380c42d","type":"cronplus","z":"10ece3ab98e93683","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","defaultLocation":"","defaultLocationType":"default","outputs":1,"options":[{"name":"noon","topic":"noon","payloadType":"str","payload":"Fill the tank","expressionType":"cron","expression":"0 0 12 * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":2130,"y":1480,"wires":[["da9711c8a01c1732"]]},{"id":"da9711c8a01c1732","type":"function","z":"10ece3ab98e93683","name":"Is it time?","func":"const days = 20\nconst mod = (parseInt((msg.date || Date.now()) / 1000 / 60 / 60 / 24) % days)\nif (mod === 0) {\n // today is the day\n msg.payload = \"whatever you want\"\n // @ts-ignore\n node.status({ fill: \"blue\", shape: \"ring\", text: `Next message in ${days} day${days === 1 ? \"\" : \"s\"}` });\n return msg\n} \nconst daysUntil = days - mod\nnode.status({ fill: \"blue\", shape: \"ring\", text: `Next message in ${daysUntil} day${daysUntil == 1 ? \"\" : \"s\"}`});","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2360,"y":1480,"wires":[["fd8ded425df58d62"]]},{"id":"fd8ded425df58d62","type":"debug","z":"10ece3ab98e93683","name":"Send telegram ->","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":2390,"y":1420,"wires":[]},{"id":"6865444b45fd511e","type":"inject","z":"10ece3ab98e93683","name":"24th 12:00","props":[{"p":"date","v":"1666609200000","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":2140,"y":1620,"wires":[["da9711c8a01c1732"]]},{"id":"c3c94c936182ae63","type":"inject","z":"10ece3ab98e93683","name":"25th 12:00","props":[{"p":"date","v":"1666695600000","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":2140,"y":1660,"wires":[["da9711c8a01c1732"]]},{"id":"bbead8dc41557e95","type":"inject","z":"10ece3ab98e93683","name":"26th 12:00","props":[{"p":"date","v":"1666782000000","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":2140,"y":1700,"wires":[["da9711c8a01c1732"]]},{"id":"fe0fa5982fb87cb9","type":"inject","z":"10ece3ab98e93683","name":"27th 12:00","props":[{"p":"date","v":"1666868400000","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":2140,"y":1740,"wires":[["da9711c8a01c1732"]]},{"id":"ccf588da28e12c73","type":"inject","z":"10ece3ab98e93683","name":"28th 12:00","props":[{"p":"date","v":"1666954800000","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":2140,"y":1780,"wires":[["da9711c8a01c1732"]]},{"id":"555a405b55bda354","type":"inject","z":"10ece3ab98e93683","name":"29th 12:00","props":[{"p":"date","v":"1667041200000","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":2140,"y":1820,"wires":[["da9711c8a01c1732"]]},{"id":"2d6289cf7c6d6373","type":"inject","z":"10ece3ab98e93683","name":"30th 12:00","props":[{"p":"date","v":"1667131200000","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":2140,"y":1860,"wires":[["da9711c8a01c1732"]]},{"id":"a6d6017c1f7d2d84","type":"inject","z":"10ece3ab98e93683","name":"31th 12:00","props":[{"p":"date","v":"1667217600000","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":2140,"y":1900,"wires":[["da9711c8a01c1732"]]},{"id":"0ae2588603d16a5e","type":"inject","z":"10ece3ab98e93683","name":"1st 12:00","props":[{"p":"date","v":"1667304000000","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":2140,"y":1940,"wires":[["da9711c8a01c1732"]]},{"id":"8b5add061c9879f0","type":"inject","z":"10ece3ab98e93683","name":"2nd 12:00","props":[{"p":"date","v":"1667390400000","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":2140,"y":1980,"wires":[["da9711c8a01c1732"]]},{"id":"4811478dfdab60a8","type":"inject","z":"10ece3ab98e93683","name":"3rd 12:00","props":[{"p":"date","v":"1667476800000","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":2140,"y":2020,"wires":[["da9711c8a01c1732"]]},{"id":"2e0fb163d60e6c75","type":"inject","z":"10ece3ab98e93683","name":"4th 12:00","props":[{"p":"date","v":"1667563200000","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":2140,"y":2060,"wires":[["da9711c8a01c1732"]]},{"id":"9a2abb5d3086ca87","type":"inject","z":"10ece3ab98e93683","name":"5th 12:00","props":[{"p":"date","v":"1667649600000","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":2140,"y":2100,"wires":[["da9711c8a01c1732"]]}]
The best solution would be to have the dehumidifier empty automatically, and a level alert and auto shut down if auto empty fails.
haha - thats true! I guess I should have said "the better solution, given current requirements"
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.