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

**URL:** https://discourse.nodered.org/t/issue-with-dynamic-schedules-in-node-red-contrib-cron-plus/51031
**Category:** Developing Nodes
**Created:** [14 September 2021 18:39 UTC](https://discourse.nodered.org/t/issue-with-dynamic-schedules-in-node-red-contrib-cron-plus/51031 "2021-09-14T18:39:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![MartinOHV](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/martinohv/32/33114_2.png) [@MartinOHV](https://discourse.nodered.org/u/MartinOHV)
#### Post date: [14 September 2021 18:39 UTC](https://discourse.nodered.org/t/issue-with-dynamic-schedules-in-node-red-contrib-cron-plus/51031/1 "2021-09-14T18:39:58Z")

</div>

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:

```auto
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:

```auto
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 ☹

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

---

<div class="post-metadata">

### Author: ![MartinOHV](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/martinohv/32/33114_2.png) [@MartinOHV](https://discourse.nodered.org/u/MartinOHV)
#### Post date: [14 September 2021 18:44 UTC](https://discourse.nodered.org/t/issue-with-dynamic-schedules-in-node-red-contrib-cron-plus/51031/2 "2021-09-14T18:44:04Z")

</div>

Damn... sorry...

just change the

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

```

```auto
 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 🙂

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [28 September 2021 18:44 UTC](https://discourse.nodered.org/t/issue-with-dynamic-schedules-in-node-red-contrib-cron-plus/51031/3 "2021-09-28T18:44:11Z")

</div>

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