Issue with dynamic Schedules in node-red-contrib-cron-plus

Hi, i have some issues with dynamic Schedules in Cron+...

I use a File input to read my schedules from an Textfile /home/pi/schedules. The File contains this:

Aussenbeleuchtung morgens an;0 0 7 * * *;kmt004-3=on
Aussenbeleuchtung morgens aus;0 30 8 * * *;kmt-004-3=off
Aussenbeleuchtung abends an;0 0 19 * * *;kmt004-3=on
Aussenbeleuchtung abends aus;0 0 23 * * *;kmt004-3=off
Licht Buero abends aus;0 59 23 * * *;kmt002-3=off
Licht Garage abends aus;0 59 23 * * *;kmt002-2=off
Licht Buero WC abends aus;0 59 23 * * *;kmt003-4=off
Rasensprenger Kreis 0 an;0 0 5 * * *;kmt007-1=on
Rasensprenger Kreis 0 aus;0 0 7 * * *;kmt007-1=off
Test;*/5 * * * *;kmt999-1=off

This Textfile is forwarded with each line as a message to a function with this code:

var Nachricht = msg.payload.split(";");
var New= new Object();

New.status = "OK";
New.payload = Nachricht[2];
New.name = Nachricht[0];
New.expression = Nachricht[1];
New.command = "add";
New.type = "str";

if (Nachricht.length > 1)
{
   msg.payload = New;
   return msg;
}
else
{
    return msg;
}

The result of this function is forwarded then to the Cron+ Scheduler and all schedules are shown in the "Show dynamic schedules" perfectly - but: as soon as this flow was triggered, the first Scheduler was fired. in this case, the Scheduler switch on the light what is scheduled for 7am at any time when the file was processed.

the Plan is to read the content of the file each night at midnight to take care for new schedules, but in this case, the light what is scheduled for 7am will start lighting at midnight - no clue why this happens :frowning:

My Flow:
[{"id":"b78c42ad4c098d49","type":"comment","z":"9a20f8c8.908398","name":"Timer ","info":"","x":110,"y":560,"wires":[]},{"id":"135758461bb3ac45","type":"file in","z":"9a20f8c8.908398","name":"","filename":"/home/pi/schedules","format":"lines","chunk":false,"sendError":false,"encoding":"utf8","allProps":false,"x":370,"y":600,"wires":[["e2f16f31e5186ca6"]]},{"id":"e2f16f31e5186ca6","type":"function","z":"9a20f8c8.908398","name":"","func":"var Nachricht = msg.payload.split(\";\");\nvar New= new Object();\n\nNew.status = \"OK\";\nNew.payload = Nachricht[2];\nNew.name = Nachricht[0];\nNew.expression = Nachricht[1];\nNew.command = \"add\";\nNew.type = \"str\";\n\nif (Nachricht.length > 1)\n{\n msg.payload = New;\n return msg;\n}\nelse\n{\n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":600,"wires":[["c7113bf2abb8ca7e"]]},{"id":"41776a72d75f1b89","type":"inject","z":"9a20f8c8.908398","name":"Einlesen der Timer","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"59 23 * * *","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":160,"y":600,"wires":[["135758461bb3ac45"]]},{"id":"c7113bf2abb8ca7e","type":"cronplus","z":"9a20f8c8.908398","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[],"x":680,"y":600,"wires":[["63273061b491d702"]]},{"id":"63273061b491d702","type":"debug","z":"9a20f8c8.908398","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":830,"y":600,"wires":[]}]

Any Help will be appreciated...

thank you
Martin

Damn... sorry...

just change the

if (Nachricht.length > 1)
{
   msg.payload = New;
   return msg;
}
else
{
    return msg;
}
 if (Nachricht.length > 1)
{
   msg.payload = New;
   return msg;
}
else
{
    return null;
}

does the trick - because the last line will return the msg what still contains the msg object from the file Reader.... sorry - somethimes you dont see the forest between all the trees :slight_smile:

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