Help cron-plus and raspberry pi

hello, everyone
this is my first project with node-red and raspberry pi and I need your help
what I'm trying to make is...
-I had my med button (GPIO input node) that turn off led
-remind me later button (GPIO input node ) that delay the led 10m if the button pressed and if the led is on
-let's pretend that the debug nodes are LEDs (GPIO output nodes) the switch node output is string "scheduleX" then I add on change node to turn it to 1 .....is there a better way
I appreciate any help !!! thank u

[{"id":"4138d84d.b6a638","type":"tab","label":"ReMedy","disabled":false,"info":""},{"id":"975d7ea8.cca72","type":"trigger","z":"4138d84d.b6a638","op1":"0","op2":"1","op1type":"num","op2type":"str","duration":"10","extend":false,"units":"min","reset":"","bytopic":"all","name":"","x":330,"y":100,"wires":[[]]},{"id":"8b3269df.100958","type":"switch","z":"4138d84d.b6a638","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"schedule1","vt":"str"},{"t":"eq","v":"schedule2","vt":"str"},{"t":"eq","v":"schedule3","vt":"str"},{"t":"eq","v":"schedule4","vt":"str"},{"t":"eq","v":"schedule5","vt":"str"},{"t":"eq","v":"schedule6","vt":"str"},{"t":"eq","v":"schedule7","vt":"str"},{"t":"eq","v":"schedule8","vt":"str"},{"t":"eq","v":"schedule9","vt":"str"},{"t":"eq","v":"schedule10","vt":"str"},{"t":"eq","v":"schedule11","vt":"str"},{"t":"eq","v":"schedule12","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":13,"x":250,"y":340,"wires":[["43201e02.2908b"],["72bbd107.55178"],["fbf67d6d.60ac5"],["d5d35e96.974d9"],["75be7440.85b61c"],["76dee429.936eec"],["b64b7e4c.ab6d9"],["5f9902a2.a564fc"],["c1799296.56fa"],["2ad4bcc9.e7d764"],["eefc9f7d.6a4cd"],["1c9f5bac.82bea4"],[]]},{"id":"acced8a.f01e528","type":"comment","z":"4138d84d.b6a638","name":"I take my medicine","info":"","x":690,"y":40,"wires":[]},{"id":"ec760d98.d4494","type":"comment","z":"4138d84d.b6a638","name":"Remind me later","info":"","x":260,"y":40,"wires":[]},{"id":"7e8c5bb0.2fd684","type":"comment","z":"4138d84d.b6a638","name":"which schedule for witch container","info":"","x":180,"y":220,"wires":[]},{"id":"a906bd29.92583","type":"switch","z":"4138d84d.b6a638","name":"if input is 1","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":570,"y":100,"wires":[["2b8093e1.3521ac"],[]]},{"id":"2b8093e1.3521ac","type":"change","z":"4138d84d.b6a638","name":"turn 0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":100,"wires":[[]]},{"id":"7c514d74.288d24","type":"cronplus","z":"4138d84d.b6a638","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"schedule1","topic":"schedule1","payloadType":"default","payload":"","expressionType":"cron","expression":"0 */1 * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule2","topic":"schedule2","payloadType":"default","payload":"","expressionType":"cron","expression":"0 */2 * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule3","topic":"schedule3","payloadType":"default","payload":"","expressionType":"cron","expression":"0 */3 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule4","topic":"schedule4","payloadType":"default","payload":"","expressionType":"cron","expression":"0 */4 * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule5","topic":"schedule5","payloadType":"default","payload":"","expressionType":"cron","expression":"0 */5 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule6","topic":"schedule6","payloadType":"default","payload":"","expressionType":"cron","expression":"0 */6 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule7","topic":"schedule7","payloadType":"default","payload":"","expressionType":"cron","expression":"0 */7 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule8","topic":"schedule8","payloadType":"default","payload":"","expressionType":"cron","expression":"0 */8 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule9","topic":"schedule9","payloadType":"default","payload":"","expressionType":"cron","expression":"0 */9 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule10","topic":"schedule10","payloadType":"default","payload":"","expressionType":"cron","expression":"0 */10 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule11","topic":"schedule11","payloadType":"default","payload":"","expressionType":"cron","expression":"0 */11 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule12","topic":"schedule12","payloadType":"default","payload":"","expressionType":"cron","expression":"0 */12 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":100,"y":340,"wires":[["8b3269df.100958"]]},{"id":"43f0b8ea.df4af8","type":"debug","z":"4138d84d.b6a638","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":770,"y":200,"wires":[]},{"id":"f7c79999.245458","type":"debug","z":"4138d84d.b6a638","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":630,"y":220,"wires":[]},{"id":"fbf67d6d.60ac5","type":"debug","z":"4138d84d.b6a638","name":"3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":770,"y":240,"wires":[]},{"id":"76dee429.936eec","type":"debug","z":"4138d84d.b6a638","name":"6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":630,"y":300,"wires":[]},{"id":"1c9f5bac.82bea4","type":"debug","z":"4138d84d.b6a638","name":"12","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":630,"y":420,"wires":[]},{"id":"eefc9f7d.6a4cd","type":"debug","z":"4138d84d.b6a638","name":"11","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":770,"y":400,"wires":[]},{"id":"2ad4bcc9.e7d764","type":"debug","z":"4138d84d.b6a638","name":"10","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":630,"y":380,"wires":[]},{"id":"c1799296.56fa","type":"debug","z":"4138d84d.b6a638","name":"9","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":770,"y":360,"wires":[]},{"id":"5f9902a2.a564fc","type":"debug","z":"4138d84d.b6a638","name":"8","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":630,"y":340,"wires":[]},{"id":"b64b7e4c.ab6d9","type":"debug","z":"4138d84d.b6a638","name":"7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":770,"y":320,"wires":[]},{"id":"75be7440.85b61c","type":"debug","z":"4138d84d.b6a638","name":"5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":770,"y":280,"wires":[]},{"id":"d5d35e96.974d9","type":"debug","z":"4138d84d.b6a638","name":"4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":630,"y":260,"wires":[]},{"id":"43201e02.2908b","type":"change","z":"4138d84d.b6a638","name":"on","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":200,"wires":[["43f0b8ea.df4af8"]]},{"id":"72bbd107.55178","type":"change","z":"4138d84d.b6a638","name":"on","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":240,"wires":[["f7c79999.245458"]]},{"id":"1c866e9b.ece571","type":"switch","z":"4138d84d.b6a638","name":"if input is 1","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":130,"y":100,"wires":[["975d7ea8.cca72"],[]]}]

Hi, I there isnt really a right or wrong way, but you have (IMO) some unnecessary nodes)

For example, the CRON node can send a Number 1 (there is no need for change nodes)

Also, while the CRON node can store multiple schedules, the HUGE card coded switch you had after it is not needed if you use individual CRON nodes
...

This is how i might approach your requirement. (NOTE: I am not 100% certain of your requirements - some guesses were made)

[{"id":"f8a85fc5.a75a5","type":"trigger","z":"66814e71.9e0b9","op1":"0","op2":"1","op1type":"num","op2type":"str","duration":"10","extend":false,"units":"min","reset":"","bytopic":"all","name":"","x":530,"y":120,"wires":[["b84561b3.e39d1"]]},{"id":"ade55054.4e0b3","type":"comment","z":"66814e71.9e0b9","name":"I took my medicine (finished)","info":"","x":820,"y":80,"wires":[]},{"id":"3caff1dc.b8499e","type":"comment","z":"66814e71.9e0b9","name":"Remind me later (snooze)","info":"","x":370,"y":80,"wires":[]},{"id":"11989b02.934ba5","type":"comment","z":"66814e71.9e0b9","name":"which schedule for witch container","info":"","x":320,"y":320,"wires":[]},{"id":"9e996bed.01cf08","type":"change","z":"66814e71.9e0b9","name":"turn 0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1010,"y":120,"wires":[["910e9aaf.fe6b08"]]},{"id":"840bdcc8.025ca","type":"cronplus","z":"66814e71.9e0b9","name":"schedule1","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"schedule1","topic":"schedule1","payloadType":"default","payload":"","expressionType":"cron","expression":"0 */1 * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":270,"y":380,"wires":[["a7e9517b.4fed2"]]},{"id":"a7e9517b.4fed2","type":"debug","z":"66814e71.9e0b9","name":"GPIO 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":440,"y":400,"wires":[]},{"id":"dffa0b7a.a0e0b8","type":"switch","z":"66814e71.9e0b9","name":"if input 1 is 1","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":120,"wires":[["f8a85fc5.a75a5"],[]]},{"id":"1116965b.39ef7a","type":"inject","z":"66814e71.9e0b9","name":"Finished 1 (Fake UI button)","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":830,"y":120,"wires":[["9e996bed.01cf08"]]},{"id":"6ed316c2.9db828","type":"inject","z":"66814e71.9e0b9","name":"Snooze (UI button)","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":140,"wires":[["dffa0b7a.a0e0b8","62dafe62.51796","522d4473.176e3c"]]},{"id":"87151d06.8c8da","type":"link in","z":"66814e71.9e0b9","name":"","links":["b84561b3.e39d1","910e9aaf.fe6b08"],"x":275,"y":420,"wires":[["a7e9517b.4fed2"]]},{"id":"b84561b3.e39d1","type":"link out","z":"66814e71.9e0b9","name":"","links":["87151d06.8c8da"],"x":635,"y":120,"wires":[]},{"id":"ac87b2bb.60fae","type":"link out","z":"66814e71.9e0b9","name":"","links":["62e3182b.94bad8"],"x":635,"y":160,"wires":[]},{"id":"fe874fd4.8ca5d","type":"trigger","z":"66814e71.9e0b9","op1":"0","op2":"1","op1type":"num","op2type":"str","duration":"10","extend":false,"units":"min","reset":"","bytopic":"all","name":"","x":530,"y":160,"wires":[["ac87b2bb.60fae"]]},{"id":"62dafe62.51796","type":"switch","z":"66814e71.9e0b9","name":"if input 2 is 1","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":160,"wires":[["fe874fd4.8ca5d"],[]]},{"id":"522d4473.176e3c","type":"switch","z":"66814e71.9e0b9","name":"if input 2 is 1","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":200,"wires":[["f90e26e8.613988"],[]]},{"id":"f90e26e8.613988","type":"trigger","z":"66814e71.9e0b9","op1":"0","op2":"1","op1type":"num","op2type":"str","duration":"10","extend":false,"units":"min","reset":"","bytopic":"all","name":"","x":530,"y":200,"wires":[["ed76d08c.be58a"]]},{"id":"ed76d08c.be58a","type":"link out","z":"66814e71.9e0b9","name":"","links":["2fb3b25.ec7fa4e"],"x":635,"y":200,"wires":[]},{"id":"910e9aaf.fe6b08","type":"link out","z":"66814e71.9e0b9","name":"","links":["87151d06.8c8da"],"x":1115,"y":120,"wires":[]},{"id":"e827cd8f.30085","type":"inject","z":"66814e71.9e0b9","name":"Finished 2 (Fake UI button)","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":830,"y":160,"wires":[["5f8ac06a.3dbba"]]},{"id":"c02d5572.485098","type":"inject","z":"66814e71.9e0b9","name":"Finished 3 (Fake UI button)","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":830,"y":200,"wires":[["ba2e06cd.7e9ad8"]]},{"id":"5f8ac06a.3dbba","type":"change","z":"66814e71.9e0b9","name":"turn 0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1010,"y":160,"wires":[["8338ccaf.452a2"]]},{"id":"8338ccaf.452a2","type":"link out","z":"66814e71.9e0b9","name":"","links":["43319953.18abd8","62e3182b.94bad8"],"x":1115,"y":160,"wires":[]},{"id":"ba2e06cd.7e9ad8","type":"change","z":"66814e71.9e0b9","name":"turn 0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1010,"y":200,"wires":[["72c8f298.497fac"]]},{"id":"72c8f298.497fac","type":"link out","z":"66814e71.9e0b9","name":"","links":["64323ae1.315ac4","2fb3b25.ec7fa4e"],"x":1115,"y":200,"wires":[]},{"id":"45e9831a.d83ccc","type":"debug","z":"66814e71.9e0b9","name":"GPIO 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":440,"y":500,"wires":[]},{"id":"32716e0b.6d9692","type":"cronplus","z":"66814e71.9e0b9","name":"schedule2","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"schedule2","topic":"schedule2","payloadType":"default","payload":"","expressionType":"cron","expression":"0 */2 * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":270,"y":480,"wires":[["45e9831a.d83ccc"]]},{"id":"62e3182b.94bad8","type":"link in","z":"66814e71.9e0b9","name":"","links":["ac87b2bb.60fae","8338ccaf.452a2"],"x":275,"y":520,"wires":[["45e9831a.d83ccc"]]},{"id":"ace9abf9.4b0168","type":"debug","z":"66814e71.9e0b9","name":"GPIO 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":440,"y":600,"wires":[]},{"id":"3c6565e5.a2fcca","type":"cronplus","z":"66814e71.9e0b9","name":"schedule1","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"schedule3","topic":"schedule3","payloadType":"default","payload":"","expressionType":"cron","expression":"0 */1 * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":270,"y":580,"wires":[["ace9abf9.4b0168"]]},{"id":"2fb3b25.ec7fa4e","type":"link in","z":"66814e71.9e0b9","name":"","links":["ed76d08c.be58a","72c8f298.497fac"],"x":275,"y":620,"wires":[["ace9abf9.4b0168"]]}]

Hope it helps put you on the right path.


Future improvements...

  • Set the CRON schedules dynamically from the dashboard (read the built in help & see built in dashboard demo)
    image
  • send a reset to the timer when the "complete" button is pressed
2 Likes

I thought that too many CRON nodes would be too much that's why I used the switch node, but that's definitely a better idea since I might need to add more schedules to the same output thank you @Steve-Mcl for that it was very helpful

1 Like

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