Cron plus dynamic schedule on dashboard 2

Probably not specific to dashboard 2 but that's what I'm using so I threw that in. I have looked at all the examples imported and they work fine. I use what I think are the same settings in a function node and it doesn't setup a schedule. I am missing something spectacularly simple I think but after two long days I'm going to yell for help. If I use the example inject node it puts a schedule into cron. I can check that with the export schedule inject. If I inject the function node then use the export schedule there is no schedule. Here's my flow.

[{"id":"9ce844e480478dbd","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"c73de127c455c567","type":"cronplus","z":"9ce844e480478dbd","name":"","outputField":"payload","timeZone":"","storeName":"","commandResponseMsgOutput":"output1","defaultLocation":"","defaultLocationType":"default","outputs":1,"options":[],"x":600,"y":340,"wires":[["5b91e9dc82be1e6a"]]},{"id":"e94b58d201700f4c","type":"function","z":"9ce844e480478dbd","name":"Load Cron","func":"\nlet Z = flow.get(\"TempHr\");\nlet Y = flow.get(\"TempMin\");\nlet X = flow.get(\"TempPm\");\nlet W = flow.get(\"TempDay\");\n\nif (X == \"PM\"){\n    Z = Z + 12;\n}\n\nmsg = \n{\n    command: \"add\",\n    name: \"every 20s Wed~Sun\",\n    expression: \"*/20 * * * * 3-7 *\",\n    payload: \"Hi wed~sun\",\n    type: \"default\",\n    limit: 3,\n    topic: \"add\",\n}\n\nnode.status({fill:\"blue\",shape:\"dot\",text: msg.expression});\n\nreturn msg;\n/*\n\nmsg = \n{\n    command: \"add\",\n    name: \"every 20s Wed~Sun\",\n    expression: \"0 \" + Y + \" \" + Z + \" ? * \" + W + \" *\",\n    payload: \"Hi wed~sun\",\n    type: \"default\",\n    limit: 3,\n    topic: \"add\",\n}\n\n*/","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":400,"wires":[["c73de127c455c567","5b91e9dc82be1e6a"]]},{"id":"6c510f0ec8aab0da","type":"inject","z":"9ce844e480478dbd","name":"Get list of schedules","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"list-all","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"list-all","payload":"","payloadType":"date","x":370,"y":120,"wires":[["c73de127c455c567"]]},{"id":"5b91e9dc82be1e6a","type":"debug","z":"9ce844e480478dbd","name":"debug 48","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":880,"y":340,"wires":[]},{"id":"6d25e5a3685511c8","type":"inject","z":"9ce844e480478dbd","name":"export all dynamic schedules","props":[{"p":"payload","v":"{\"command\":\"export-all-dynamic\"}","vt":"json"},{"p":"topic","v":"","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"command\":\"export-all-dynamic\"}","payloadType":"json","x":300,"y":200,"wires":[["c73de127c455c567"]]},{"id":"327841489ba3e79e","type":"inject","z":"9ce844e480478dbd","name":"add 3 schedules","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"command\":\"add\",\"name\":\"every 20s Wed~Sun\",\"expression\":\"*/20 * * * * 3-7 *\",\"payload\":\"Hi wed~sun\",\"type\":\"default\",\"limit\":3}","payloadType":"json","x":260,"y":260,"wires":[["c73de127c455c567","5b91e9dc82be1e6a"]]},{"id":"3578168ae0f5950a","type":"inject","z":"9ce844e480478dbd","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"str","x":210,"y":400,"wires":[["e94b58d201700f4c"]]},{"id":"ce79ee98d12a5ff6","type":"inject","z":"9ce844e480478dbd","name":"remove-all-dynamic","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"remove-all-dynamic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"remove-all-dynamic","payload":"","payloadType":"date","x":230,"y":340,"wires":[["c73de127c455c567"]]}]

Any help appreciated.
here's the function node code by itself
msg =
{
command: "add",
name: "every 20s Wed~Sun",
expression: "*/20 * * * * 3-7 *",
payload: "Hi wed~sun",
type: "default",
limit: 3,
topic: "add",
}

I have not used dynamic schedules, but looking in the help text I see this:
Adding one (or more) schedules
Example...

payload: [
  {
    "command": "add",
    "name": "every 6",
    "expression": "*/6 * * * * * *",
    "expressionType": "cron",
    "payloadType": "default",
    "limit": 3 
  },
  {
    "command": "add",
    "name": "new years eve 2030",
    "expression": "2030-01-01",
    "expressionType": "dates",
    "payloadType": "default"
  },
  {
    "command": "add",
    "name": "alarm1",
    "expressionType": "solar",
    "solarType": "selected",
    "solarEvents": "civilDawn,sunrise,sunset",
    "location": "54.999320540937035 -1.417407989501953",
    "offset": "-60",
    "payloadType": "str",
    "payload": "In 60 mins, it will be a great time to take photographs",
    "limit": null
  }
]

Which appears to be saying everything should be in msg.payload rather than the top level message. It is showing an array, but looking further down it suggests that it need not be an array if you are only adding one.

Interesting, moving everything into msg.payload seems to work,
Thanks

You are setting the msg not the payload

change

msg = {
    command: "add",
    name: "every 20s Wed~Sun",
    expression: "*/20 * * * * 3-7 *",
    payload: "Hi wed~sun",
    type: "default",
    limit: 3,
    topic: "add",
}

to

msg.payload = {
    command: "add",
    name: "every 20s Wed~Sun",
    expression: "*/20 * * * * 3-7 *",
    payload: "Hi wed~sun",
    type: "default",
    limit: 3,
    topic: "add",
}

(or set payload to an array as Colin describes)

chrome_D1LDdCq6KE

I knew it had to be something irritatingly simple.

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