-
Notifications
You must be signed in to change notification settings - Fork 4
Scheduler
cflurin edited this page Dec 5, 2018
·
8 revisions
This example shows how to combine several schedulers (schedex) for turning on/off devices. Additionally a manual control can be used which turns the auto mode off.
Note: You need to install node-red-contrib-schedex
{
"currentState": "auto",
"stateOutput": "payload",
"states": {
"auto": {
"man": "man"
},
"man": {
"auto": "auto"
}
},
"methods": {
"auto": [
"output = false;"
],
"man": [
"output = false;"
],
"sched": [
"if (sm.currentState === 'auto') {",
" output = true;",
"}"
],
"default": [
"if (msg.payload === 'on' || msg.payload === 'off') {",
" sm.currentState = 'man';",
" output = true;",
"}"
],
"status": {
"fill": {
"get": "sm.currentState === 'auto' ? 'green' : 'grey';"
},
"shape": "dot",
"text": {
"get": "sm.currentState"
}
}
}
}
[{"id":"a60eee37.7e1a1","type":"dsm","z":"895bbff8.0e6c4","name":"","sm_config":"{\n \"currentState\": \"auto\",\n \"stateOutput\": \"payload\",\n \"states\": {\n \"auto\": {\n \"man\": \"man\"\n },\n \"man\": {\n \"auto\": \"auto\"\n }\n },\n \"methods\": {\n \"auto\": [\n \"output = false;\"\n ],\n \"man\": [\n \"output = false;\"\n ],\n \"sched\": [\n \"if (sm.currentState === 'auto') {\",\n \" output = true;\",\n \"}\"\n ],\n \"default\": [\n \"if (msg.payload === 'on' || msg.payload === 'off') {\",\n \" sm.currentState = 'man';\",\n \" output = true;\",\n \"}\"\n ],\n \"status\": {\n \"fill\": {\n \"get\": \"sm.currentState === 'auto' ? 'green' : 'grey';\"\n },\n \"shape\": \"dot\",\n \"text\": {\n \"get\": \"sm.currentState\"\n }\n }\n }\n}\n","x":450,"y":840,"wires":[["603bf24c.f512dc"]]},{"id":"603bf24c.f512dc","type":"debug","z":"895bbff8.0e6c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":450,"y":900,"wires":[]},{"id":"36d962f4.f78b8e","type":"inject","z":"895bbff8.0e6c4","name":"","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":740,"wires":[["a60eee37.7e1a1"]]},{"id":"6e3d8ee9.2ef1a","type":"inject","z":"895bbff8.0e6c4","name":"","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":780,"wires":[["a60eee37.7e1a1"]]},{"id":"7cd7448.e2390bc","type":"schedex","z":"895bbff8.0e6c4","name":"","suspended":false,"lat":"52.2","lon":"0.12","ontime":"06:0","ontopic":"sched","onpayload":"on","onoffset":0,"onrandomoffset":0,"offtime":"sunrise","offtopic":"sched","offpayload":"off","offoffset":0,"offrandomoffset":0,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"sun":true,"x":160,"y":820,"wires":[["a60eee37.7e1a1"]]},{"id":"4ab6726b.2ab82c","type":"schedex","z":"895bbff8.0e6c4","name":"","suspended":false,"lat":"52.2","lon":"0.12","ontime":"sunset","ontopic":"sched-on","onpayload":"","onoffset":0,"onrandomoffset":0,"offtime":"23:30","offtopic":"sched-off","offpayload":"","offoffset":0,"offrandomoffset":0,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"sun":true,"x":160,"y":880,"wires":[["a60eee37.7e1a1"]]},{"id":"bd42809b.25ffa","type":"inject","z":"895bbff8.0e6c4","name":"","topic":"auto","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":450,"y":740,"wires":[["a60eee37.7e1a1"]]},{"id":"f37be184.f9aa4","type":"inject","z":"895bbff8.0e6c4","name":"","topic":"man","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":450,"y":780,"wires":[["a60eee37.7e1a1"]]}]