Created
February 7, 2021 17:57
-
-
Save sstratoti/6b533812ebbdf1b063c7f19029a4a4b0 to your computer and use it in GitHub Desktop.
NodeRed Flow - Unfinished - baby came too soon!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| { | |
| "id": "360f1317.265a9c", | |
| "type": "tab", | |
| "label": "BabbyBuddy", | |
| "disabled": false, | |
| "info": "" | |
| }, | |
| { | |
| "id": "3df976b9.981fea", | |
| "type": "http request", | |
| "z": "360f1317.265a9c", | |
| "name": "", | |
| "method": "POST", | |
| "ret": "obj", | |
| "paytoqs": false, | |
| "url": "https://babybuddy.YOURSERVER.com/api/timers/", | |
| "tls": "", | |
| "proxy": "", | |
| "authType": "", | |
| "x": 1470, | |
| "y": 160, | |
| "wires": [ | |
| [ | |
| "62eacc78.271f1c" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "26aa4590.ba8b3a", | |
| "type": "function", | |
| "z": "360f1317.265a9c", | |
| "name": "Set Message", | |
| "func": "msg.payload = '{\"child\":1,\"start\":\"' + msg.myrawdate + '\",\"user\":4}'\nmsg.headers = {};\nmsg.headers[\"content-type\"] = 'application/json'\nmsg.headers[\"Authorization\"] = 'Token 70554cbcaa42ad98ad7033079e757199260a2aae';\nreturn msg;", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 1290, | |
| "y": 160, | |
| "wires": [ | |
| [ | |
| "3df976b9.981fea" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "4ae5bb46.8d6774", | |
| "type": "moment", | |
| "z": "360f1317.265a9c", | |
| "name": "", | |
| "topic": "", | |
| "input": "", | |
| "inputType": "date", | |
| "inTz": "America/New_York", | |
| "adjAmount": 0, | |
| "adjType": "days", | |
| "adjDir": "add", | |
| "format": "", | |
| "locale": "POSIX", | |
| "output": "myrawdate", | |
| "outputType": "msg", | |
| "outTz": "America/New_York", | |
| "x": 1080, | |
| "y": 160, | |
| "wires": [ | |
| [ | |
| "26aa4590.ba8b3a" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "2de79b1e.9776d4", | |
| "type": "comment", | |
| "z": "360f1317.265a9c", | |
| "name": "Start a Timer", | |
| "info": "", | |
| "x": 170, | |
| "y": 100, | |
| "wires": [] | |
| }, | |
| { | |
| "id": "e675b4cb.cf71d8", | |
| "type": "inject", | |
| "z": "360f1317.265a9c", | |
| "name": "", | |
| "topic": "", | |
| "payload": "", | |
| "payloadType": "date", | |
| "repeat": "", | |
| "crontab": "", | |
| "once": false, | |
| "onceDelay": 0.1, | |
| "x": 180, | |
| "y": 280, | |
| "wires": [ | |
| [ | |
| "e5dd322.2bf27d" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "40df048c.8ae00c", | |
| "type": "http request", | |
| "z": "360f1317.265a9c", | |
| "name": "", | |
| "method": "POST", | |
| "ret": "obj", | |
| "paytoqs": false, | |
| "url": "", | |
| "tls": "", | |
| "proxy": "", | |
| "authType": "", | |
| "x": 1210, | |
| "y": 280, | |
| "wires": [ | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "8a587800.3a1f68", | |
| "type": "comment", | |
| "z": "360f1317.265a9c", | |
| "name": "Stop Currently Running Timer", | |
| "info": "", | |
| "x": 220, | |
| "y": 220, | |
| "wires": [] | |
| }, | |
| { | |
| "id": "1c194e32.e0d552", | |
| "type": "http request", | |
| "z": "360f1317.265a9c", | |
| "name": "Get Running Timers", | |
| "method": "GET", | |
| "ret": "obj", | |
| "paytoqs": false, | |
| "url": "https://babybuddy.YOURSERVER.com/api/timers/?active=true", | |
| "tls": "", | |
| "proxy": "", | |
| "authType": "", | |
| "x": 560, | |
| "y": 280, | |
| "wires": [ | |
| [ | |
| "160d59ef.935096" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "e5dd322.2bf27d", | |
| "type": "function", | |
| "z": "360f1317.265a9c", | |
| "name": "Set Message", | |
| "func": "msg.payload = '';\nmsg.headers = {};\nmsg.headers[\"content-type\"] = 'application/json'\nmsg.headers[\"Authorization\"] = 'Token 70554cbcaa42ad98ad7033079e757199260a2aae';\nreturn msg;", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 350, | |
| "y": 280, | |
| "wires": [ | |
| [ | |
| "1c194e32.e0d552" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "160d59ef.935096", | |
| "type": "switch", | |
| "z": "360f1317.265a9c", | |
| "name": "Timer Running?", | |
| "property": "payload.results[0].active", | |
| "propertyType": "msg", | |
| "rules": [ | |
| { | |
| "t": "true" | |
| } | |
| ], | |
| "checkall": "true", | |
| "repair": false, | |
| "outputs": 1, | |
| "x": 780, | |
| "y": 280, | |
| "wires": [ | |
| [ | |
| "644c5c5c.f38314" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "644c5c5c.f38314", | |
| "type": "function", | |
| "z": "360f1317.265a9c", | |
| "name": "Stop Timer", | |
| "func": "var id = msg.payload.results[0].id;\nmsg = {};\nmsg.payload = '{\"timer\":' + id + '}';\nmsg.headers = {};\nmsg.headers[\"content-type\"] = 'application/json';\nmsg.headers[\"Authorization\"] = 'Token 70554cbcaa42ad98ad7033079e757199260a2aae';\nmsg.url = \"https://babybuddy.YOURSERVER.com/api/sleep/\";\nreturn msg;\n", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 970, | |
| "y": 280, | |
| "wires": [ | |
| [ | |
| "40df048c.8ae00c" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "16493dab.c862c2", | |
| "type": "http request", | |
| "z": "360f1317.265a9c", | |
| "name": "", | |
| "method": "POST", | |
| "ret": "obj", | |
| "paytoqs": false, | |
| "url": "", | |
| "tls": "", | |
| "proxy": "", | |
| "authType": "", | |
| "x": 1830, | |
| "y": 460, | |
| "wires": [ | |
| [ | |
| "23b5da96.082426" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "184e1228.3e015e", | |
| "type": "http request", | |
| "z": "360f1317.265a9c", | |
| "name": "Get Running Timers", | |
| "method": "GET", | |
| "ret": "obj", | |
| "paytoqs": false, | |
| "url": "https://babybuddy.YOURSERVER.com/api/timers/?active=true", | |
| "tls": "", | |
| "proxy": "", | |
| "authType": "", | |
| "x": 920, | |
| "y": 540, | |
| "wires": [ | |
| [ | |
| "ca0eb16b.3f1a1" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "f82a394b.deec", | |
| "type": "function", | |
| "z": "360f1317.265a9c", | |
| "name": "Clear Payload - Set Headers", | |
| "func": "msg.payload = '';\nmsg.headers = {};\nmsg.headers[\"content-type\"] = 'application/json'\nmsg.headers[\"Authorization\"] = 'Token 70554cbcaa42ad98ad7033079e757199260a2aae';\nreturn msg;", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 660, | |
| "y": 540, | |
| "wires": [ | |
| [ | |
| "184e1228.3e015e" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "ca0eb16b.3f1a1", | |
| "type": "switch", | |
| "z": "360f1317.265a9c", | |
| "name": "Timer Running?", | |
| "property": "payload.results[0].active", | |
| "propertyType": "msg", | |
| "rules": [ | |
| { | |
| "t": "true" | |
| }, | |
| { | |
| "t": "false" | |
| } | |
| ], | |
| "checkall": "true", | |
| "repair": false, | |
| "outputs": 2, | |
| "x": 1140, | |
| "y": 540, | |
| "wires": [ | |
| [ | |
| "a71d7b89.2bc998" | |
| ], | |
| [ | |
| "8b8e0827.963938" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "6952d59b.404484", | |
| "type": "function", | |
| "z": "360f1317.265a9c", | |
| "name": "Compose API Call", | |
| "func": "var child = 1;\nvar user = 4;\nvar myrawdate = msg.myrawdate;\n\nvar timerId = msg.payload.results[0].id;\nvar command = flow.get('bbCommand').split(\"|\");\n\nmsg.payload = {};\n\n// command[0] - api end point\n\n// changes: time, wet, solid, color\n// feedings: type, method, amount\n// sleep: \n// tummy-times: \n\nif (command[0] !== '') {\n \n if (command[0]=='sleep' || command[0]=='tummy-times') {\n // just stop the timer.\n msg.payload.timer = timerId;\n } else if (command[0]=='changes') {\n msg.payload.time = myrawdate;\n msg.payload.user = 4;\n msg.payload.child = child;\n if (command[1]=='wet') msg.payload.wet = true;\n if (command[2]=='solid') msg.payload.solid = true;\n if (command[3]!=='') msg.payload.color = command[3];\n } else if (command[0]=='feedings') {\n msg.payload.timer = timerId;\n if (command[1]!=='') msg.payload.type = command[1];\n if (command[2]!=='') msg.payload.method = command[2];\n if (command[3]!=='') msg.payload.amount = command[3];\n } else {\n node.error(command[0] + \" is not a valid command.\", flow.get('bbCommand'))\n }\n msg.headers = {};\n msg.headers[\"content-type\"] = 'application/json';\n msg.headers[\"Authorization\"] = 'Token 70554cbcaa42ad98ad7033079e757199260a2aae';\n msg.url = \"https://babybuddy.YOURSERVER.com/api/\" + command[0] + \"/\";\n}\n\n\n//Clear the flow variable\nflow.set('bbCommand','');\n\nreturn msg;\n", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 1610, | |
| "y": 460, | |
| "wires": [ | |
| [ | |
| "16493dab.c862c2", | |
| "c777a1c8.057c38" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "1b27c8e4.83baef", | |
| "type": "server-state-changed", | |
| "z": "360f1317.265a9c", | |
| "name": "BabyBuddy Command", | |
| "server": "74f36281.ae094c", | |
| "version": 1, | |
| "exposeToHomeAssistant": false, | |
| "haConfig": [ | |
| { | |
| "property": "name", | |
| "value": "" | |
| }, | |
| { | |
| "property": "icon", | |
| "value": "" | |
| } | |
| ], | |
| "entityidfilter": "input_text.bb_command", | |
| "entityidfiltertype": "exact", | |
| "outputinitially": true, | |
| "state_type": "str", | |
| "haltifstate": "unknown", | |
| "halt_if_type": "str", | |
| "halt_if_compare": "is_not", | |
| "outputs": 2, | |
| "output_only_on_state_change": true, | |
| "x": 200, | |
| "y": 540, | |
| "wires": [ | |
| [ | |
| "f4d3e4b0.7d42d" | |
| ], | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "fb86f5fb.ffc17", | |
| "type": "inject", | |
| "z": "360f1317.265a9c", | |
| "name": "", | |
| "topic": "", | |
| "payload": "changes|wet|solid|brown", | |
| "payloadType": "str", | |
| "repeat": "", | |
| "crontab": "", | |
| "once": false, | |
| "onceDelay": 0.1, | |
| "x": 230, | |
| "y": 460, | |
| "wires": [ | |
| [ | |
| "f4d3e4b0.7d42d" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "f4d3e4b0.7d42d", | |
| "type": "change", | |
| "z": "360f1317.265a9c", | |
| "name": "Save Command", | |
| "rules": [ | |
| { | |
| "t": "set", | |
| "p": "bbCommand", | |
| "pt": "flow", | |
| "to": "payload", | |
| "tot": "msg" | |
| } | |
| ], | |
| "action": "", | |
| "property": "", | |
| "from": "", | |
| "to": "", | |
| "reg": false, | |
| "x": 420, | |
| "y": 540, | |
| "wires": [ | |
| [ | |
| "f82a394b.deec" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "a71d7b89.2bc998", | |
| "type": "moment", | |
| "z": "360f1317.265a9c", | |
| "name": "", | |
| "topic": "", | |
| "input": "", | |
| "inputType": "date", | |
| "inTz": "America/New_York", | |
| "adjAmount": 0, | |
| "adjType": "days", | |
| "adjDir": "add", | |
| "format": "", | |
| "locale": "POSIX", | |
| "output": "myrawdate", | |
| "outputType": "msg", | |
| "outTz": "America/New_York", | |
| "x": 1360, | |
| "y": 460, | |
| "wires": [ | |
| [ | |
| "6952d59b.404484" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "c777a1c8.057c38", | |
| "type": "debug", | |
| "z": "360f1317.265a9c", | |
| "name": "", | |
| "active": true, | |
| "tosidebar": true, | |
| "console": false, | |
| "tostatus": false, | |
| "complete": "false", | |
| "x": 1830, | |
| "y": 400, | |
| "wires": [] | |
| }, | |
| { | |
| "id": "23b5da96.082426", | |
| "type": "debug", | |
| "z": "360f1317.265a9c", | |
| "name": "", | |
| "active": true, | |
| "tosidebar": true, | |
| "console": false, | |
| "tostatus": false, | |
| "complete": "false", | |
| "x": 2010, | |
| "y": 460, | |
| "wires": [] | |
| }, | |
| { | |
| "id": "3e73fe04.3ac30a", | |
| "type": "http request", | |
| "z": "360f1317.265a9c", | |
| "name": "", | |
| "method": "POST", | |
| "ret": "obj", | |
| "paytoqs": false, | |
| "url": "", | |
| "tls": "", | |
| "proxy": "", | |
| "authType": "", | |
| "x": 1830, | |
| "y": 620, | |
| "wires": [ | |
| [ | |
| "6f8d7422.a8ab1c" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "cf010de6.5575", | |
| "type": "function", | |
| "z": "360f1317.265a9c", | |
| "name": "Compose API Call", | |
| "func": "var child = 1;\nvar user = 4;\nvar myrawdate = msg.myrawdate;\n\nvar command = flow.get('bbCommand').split(\"|\");\n\nmsg.payload = {};\n\n// command[0] - api end point\n\n// changes: time, wet, solid, color\n\nif (command[0] !== '') {\n \n if (command[0]=='changes') {\n msg.payload.time = myrawdate;\n msg.payload.user = 4;\n msg.payload.child = child;\n if (command[1]=='wet') msg.payload.wet = true;\n if (command[2]=='solid') msg.payload.solid = true;\n if (command[3]!=='') msg.payload.color = command[3];\n } else {\n node.error('No timer running. ' + command[0] + \" is not a valid command.\", flow.get('bbCommand'))\n }\n msg.headers = {};\n msg.headers[\"content-type\"] = 'application/json';\n msg.headers[\"Authorization\"] = 'Token 70554cbcaa42ad98ad7033079e757199260a2aae';\n msg.url = \"https://babybuddy.YOURDOMAIN.com/api/\" + command[0] + \"/\";\n}\n\n\n//Clear the flow variable\nflow.set('bbCommand','');\n\nreturn msg;\n", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 1610, | |
| "y": 620, | |
| "wires": [ | |
| [ | |
| "3e73fe04.3ac30a", | |
| "f01aa403.c0ccd8" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "8b8e0827.963938", | |
| "type": "moment", | |
| "z": "360f1317.265a9c", | |
| "name": "", | |
| "topic": "", | |
| "input": "", | |
| "inputType": "date", | |
| "inTz": "America/New_York", | |
| "adjAmount": 0, | |
| "adjType": "days", | |
| "adjDir": "add", | |
| "format": "", | |
| "locale": "POSIX", | |
| "output": "myrawdate", | |
| "outputType": "msg", | |
| "outTz": "America/New_York", | |
| "x": 1360, | |
| "y": 620, | |
| "wires": [ | |
| [ | |
| "cf010de6.5575" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "f01aa403.c0ccd8", | |
| "type": "debug", | |
| "z": "360f1317.265a9c", | |
| "name": "", | |
| "active": true, | |
| "tosidebar": true, | |
| "console": false, | |
| "tostatus": false, | |
| "complete": "false", | |
| "x": 1830, | |
| "y": 560, | |
| "wires": [] | |
| }, | |
| { | |
| "id": "6f8d7422.a8ab1c", | |
| "type": "debug", | |
| "z": "360f1317.265a9c", | |
| "name": "", | |
| "active": true, | |
| "tosidebar": true, | |
| "console": false, | |
| "tostatus": false, | |
| "complete": "false", | |
| "x": 2010, | |
| "y": 620, | |
| "wires": [] | |
| }, | |
| { | |
| "id": "b570a6e5.aba628", | |
| "type": "server-state-changed", | |
| "z": "360f1317.265a9c", | |
| "name": "BabyBuddy Timer On", | |
| "server": "74f36281.ae094c", | |
| "version": 1, | |
| "exposeToHomeAssistant": false, | |
| "haConfig": [ | |
| { | |
| "property": "name", | |
| "value": "" | |
| }, | |
| { | |
| "property": "icon", | |
| "value": "" | |
| } | |
| ], | |
| "entityidfilter": "input_boolean.bb_timer_on", | |
| "entityidfiltertype": "exact", | |
| "outputinitially": true, | |
| "state_type": "str", | |
| "haltifstate": "on", | |
| "halt_if_type": "str", | |
| "halt_if_compare": "is", | |
| "outputs": 2, | |
| "output_only_on_state_change": true, | |
| "x": 200, | |
| "y": 160, | |
| "wires": [ | |
| [ | |
| "1ac16140.1f0187" | |
| ], | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "62eacc78.271f1c", | |
| "type": "api-call-service", | |
| "z": "360f1317.265a9c", | |
| "name": "Reset Timer On Boolean", | |
| "server": "74f36281.ae094c", | |
| "version": 1, | |
| "debugenabled": false, | |
| "service_domain": "homeassistant", | |
| "service": "turn_off", | |
| "entityId": "input_boolean.bb_timer_on", | |
| "data": "", | |
| "dataType": "json", | |
| "mergecontext": "", | |
| "output_location": "", | |
| "output_location_type": "none", | |
| "mustacheAltTags": false, | |
| "x": 1690, | |
| "y": 160, | |
| "wires": [ | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "9ad0f7b7.e81cb", | |
| "type": "http request", | |
| "z": "360f1317.265a9c", | |
| "name": "Get Running Timers", | |
| "method": "GET", | |
| "ret": "obj", | |
| "paytoqs": false, | |
| "url": "https://babybuddy.YOURDOMAIN.com/api/timers/?active=true", | |
| "tls": "", | |
| "proxy": "", | |
| "authType": "", | |
| "x": 620, | |
| "y": 160, | |
| "wires": [ | |
| [ | |
| "5b750ad8.d76e74" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "1ac16140.1f0187", | |
| "type": "function", | |
| "z": "360f1317.265a9c", | |
| "name": "Set Message", | |
| "func": "msg.payload = '';\nmsg.headers = {};\nmsg.headers[\"content-type\"] = 'application/json'\nmsg.headers[\"Authorization\"] = 'Token 70554cbcaa42ad98ad7033079e757199260a2aae';\nreturn msg;", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 410, | |
| "y": 160, | |
| "wires": [ | |
| [ | |
| "9ad0f7b7.e81cb" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "5b750ad8.d76e74", | |
| "type": "switch", | |
| "z": "360f1317.265a9c", | |
| "name": "Timer Running?", | |
| "property": "payload.results[0].active", | |
| "propertyType": "msg", | |
| "rules": [ | |
| { | |
| "t": "true" | |
| }, | |
| { | |
| "t": "false" | |
| } | |
| ], | |
| "checkall": "true", | |
| "repair": false, | |
| "outputs": 2, | |
| "x": 840, | |
| "y": 160, | |
| "wires": [ | |
| [ | |
| "33e3513b.05b64e" | |
| ], | |
| [ | |
| "4ae5bb46.8d6774" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "33e3513b.05b64e", | |
| "type": "api-call-service", | |
| "z": "360f1317.265a9c", | |
| "name": "Reset Timer On Boolean", | |
| "server": "74f36281.ae094c", | |
| "version": 1, | |
| "debugenabled": false, | |
| "service_domain": "homeassistant", | |
| "service": "turn_off", | |
| "entityId": "input_boolean.bb_timer_on", | |
| "data": "", | |
| "dataType": "json", | |
| "mergecontext": "", | |
| "output_location": "", | |
| "output_location_type": "none", | |
| "mustacheAltTags": false, | |
| "x": 1090, | |
| "y": 100, | |
| "wires": [ | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "82331e08.7a9f7", | |
| "type": "comment", | |
| "z": "360f1317.265a9c", | |
| "name": "Log Sleep Session", | |
| "info": "", | |
| "x": 190, | |
| "y": 980, | |
| "wires": [] | |
| }, | |
| { | |
| "id": "f55d87e9.6bd03", | |
| "type": "server-state-changed", | |
| "z": "360f1317.265a9c", | |
| "name": "Snoo State Asleep?", | |
| "server": "74f36281.ae094c", | |
| "version": 1, | |
| "exposeToHomeAssistant": false, | |
| "haConfig": [ | |
| { | |
| "property": "name", | |
| "value": "" | |
| }, | |
| { | |
| "property": "icon", | |
| "value": "" | |
| } | |
| ], | |
| "entityidfilter": "sensor.snoo_state", | |
| "entityidfiltertype": "exact", | |
| "outputinitially": true, | |
| "state_type": "str", | |
| "haltifstate": "Asleep", | |
| "halt_if_type": "str", | |
| "halt_if_compare": "is", | |
| "outputs": 2, | |
| "output_only_on_state_change": true, | |
| "x": 190, | |
| "y": 1040, | |
| "wires": [ | |
| [ | |
| "b3a3fa10.801718" | |
| ], | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "ca4d89e1.8d3278", | |
| "type": "http request", | |
| "z": "360f1317.265a9c", | |
| "name": "", | |
| "method": "POST", | |
| "ret": "obj", | |
| "paytoqs": false, | |
| "url": "https://babybuddy.YOURDOMAIN.com/api/timers/", | |
| "tls": "", | |
| "proxy": "", | |
| "authType": "", | |
| "x": 1810, | |
| "y": 1040, | |
| "wires": [ | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "5a48267a.98e15", | |
| "type": "function", | |
| "z": "360f1317.265a9c", | |
| "name": "Set Snoo Timer Message", | |
| "func": "msg.payload = '{\"child\":1,\"start\":\"' + msg.myrawdate + '\",\"user\":4,\"name\":\"Snoo\"}'\nmsg.headers = {};\nmsg.headers[\"content-type\"] = 'application/json'\nmsg.headers[\"Authorization\"] = 'Token 70554cbcaa42ad98ad7033079e757199260a2aae';\nreturn msg;", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 1610, | |
| "y": 1040, | |
| "wires": [ | |
| [ | |
| "ca4d89e1.8d3278" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "7ff32c40.6ca794", | |
| "type": "moment", | |
| "z": "360f1317.265a9c", | |
| "name": "", | |
| "topic": "", | |
| "input": "", | |
| "inputType": "date", | |
| "inTz": "America/New_York", | |
| "adjAmount": 0, | |
| "adjType": "days", | |
| "adjDir": "add", | |
| "format": "", | |
| "locale": "POSIX", | |
| "output": "myrawdate", | |
| "outputType": "msg", | |
| "outTz": "America/New_York", | |
| "x": 1380, | |
| "y": 1040, | |
| "wires": [ | |
| [ | |
| "5a48267a.98e15" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "4c5298d9.a30a4", | |
| "type": "http request", | |
| "z": "360f1317.265a9c", | |
| "name": "Get Running Timers", | |
| "method": "GET", | |
| "ret": "obj", | |
| "paytoqs": false, | |
| "url": "https://babybuddy.YOURDOMAIN.com/api/timers/?active=true", | |
| "tls": "", | |
| "proxy": "", | |
| "authType": "", | |
| "x": 680, | |
| "y": 1040, | |
| "wires": [ | |
| [ | |
| "71069f73.026ae8" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "b3a3fa10.801718", | |
| "type": "function", | |
| "z": "360f1317.265a9c", | |
| "name": "Set Message", | |
| "func": "msg.payload = {};\nmsg.headers = {};\nmsg.headers[\"content-type\"] = 'application/json'\nmsg.headers[\"Authorization\"] = 'Token 70554cbcaa42ad98ad7033079e757199260a2aae';\nreturn msg;", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 470, | |
| "y": 1040, | |
| "wires": [ | |
| [ | |
| "4c5298d9.a30a4" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "f7a5c369.c0cd08", | |
| "type": "switch", | |
| "z": "360f1317.265a9c", | |
| "name": "Timer Running?", | |
| "property": "payload", | |
| "propertyType": "msg", | |
| "rules": [ | |
| { | |
| "t": "nempty" | |
| }, | |
| { | |
| "t": "else" | |
| } | |
| ], | |
| "checkall": "true", | |
| "repair": false, | |
| "outputs": 2, | |
| "x": 1140, | |
| "y": 1040, | |
| "wires": [ | |
| [], | |
| [ | |
| "7ff32c40.6ca794" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "71069f73.026ae8", | |
| "type": "function", | |
| "z": "360f1317.265a9c", | |
| "name": "Find a Snoo Timer", | |
| "func": "var timerFound = false;\nmsg.payload.results.forEach(function (timer) {\n if (timer.name === 'Snoo') {\n msg.payload = timer;\n timerFound = true;\n }\n});\nif (!timerFound) msg.payload = {};\nreturn msg;\n", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 910, | |
| "y": 1040, | |
| "wires": [ | |
| [ | |
| "f7a5c369.c0cd08" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "93991d08.8fc888", | |
| "type": "server-state-changed", | |
| "z": "360f1317.265a9c", | |
| "name": "Snoo State Awake?", | |
| "server": "74f36281.ae094c", | |
| "version": 1, | |
| "exposeToHomeAssistant": false, | |
| "haConfig": [ | |
| { | |
| "property": "name", | |
| "value": "" | |
| }, | |
| { | |
| "property": "icon", | |
| "value": "" | |
| } | |
| ], | |
| "entityidfilter": "sensor.snoo_state", | |
| "entityidfiltertype": "exact", | |
| "outputinitially": false, | |
| "state_type": "str", | |
| "haltifstate": "Awake", | |
| "halt_if_type": "str", | |
| "halt_if_compare": "is", | |
| "outputs": 2, | |
| "output_only_on_state_change": true, | |
| "x": 190, | |
| "y": 1120, | |
| "wires": [ | |
| [ | |
| "480f4290.4e6d2c" | |
| ], | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "4369f3df.5bbe9c", | |
| "type": "http request", | |
| "z": "360f1317.265a9c", | |
| "name": "", | |
| "method": "POST", | |
| "ret": "obj", | |
| "paytoqs": false, | |
| "url": "https://babybuddy.YOURDOMAIN.com/api/sleep/", | |
| "tls": "", | |
| "proxy": "", | |
| "authType": "", | |
| "x": 1650, | |
| "y": 1120, | |
| "wires": [ | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "cb1651aa.d5da68", | |
| "type": "function", | |
| "z": "360f1317.265a9c", | |
| "name": "Set Snoo END Timer Message", | |
| "func": "var id = msg.payload.id;\nmsg = {};\nmsg.payload = '{\"timer\":' + id + '}';\nmsg.headers = {};\nmsg.headers[\"content-type\"] = 'application/json';\nmsg.headers[\"Authorization\"] = 'Token 70554cbcaa42ad98ad7033079e757199260a2aae';\nmsg.url = \"https://babybuddy.YOURDOMAIN.com/api/sleep/\";\nreturn msg;", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 1410, | |
| "y": 1120, | |
| "wires": [ | |
| [ | |
| "4369f3df.5bbe9c" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "1c68ed60.139933", | |
| "type": "http request", | |
| "z": "360f1317.265a9c", | |
| "name": "Get Running Timers", | |
| "method": "GET", | |
| "ret": "obj", | |
| "paytoqs": false, | |
| "url": "https://babybuddy.YOURDOMAIN.com/api/timers/?active=true", | |
| "tls": "", | |
| "proxy": "", | |
| "authType": "", | |
| "x": 680, | |
| "y": 1120, | |
| "wires": [ | |
| [ | |
| "7bffe208.9e9334" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "480f4290.4e6d2c", | |
| "type": "function", | |
| "z": "360f1317.265a9c", | |
| "name": "Set Message", | |
| "func": "msg.payload = {};\nmsg.headers = {};\nmsg.headers[\"content-type\"] = 'application/json'\nmsg.headers[\"Authorization\"] = 'Token 70554cbcaa42ad98ad7033079e757199260a2aae';\nreturn msg;", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 470, | |
| "y": 1120, | |
| "wires": [ | |
| [ | |
| "1c68ed60.139933" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "da8d3df4.1c568", | |
| "type": "switch", | |
| "z": "360f1317.265a9c", | |
| "name": "Timer Running?", | |
| "property": "payload", | |
| "propertyType": "msg", | |
| "rules": [ | |
| { | |
| "t": "nempty" | |
| }, | |
| { | |
| "t": "else" | |
| } | |
| ], | |
| "checkall": "true", | |
| "repair": false, | |
| "outputs": 2, | |
| "x": 1140, | |
| "y": 1120, | |
| "wires": [ | |
| [ | |
| "cb1651aa.d5da68" | |
| ], | |
| [] | |
| ] | |
| }, | |
| { | |
| "id": "7bffe208.9e9334", | |
| "type": "function", | |
| "z": "360f1317.265a9c", | |
| "name": "Find a Snoo Timer", | |
| "func": "var timerFound = false;\nmsg.payload.results.forEach(function (timer) {\n if (timer.name === 'Snoo') {\n msg.payload = timer;\n timerFound = true;\n }\n});\n//if (!timerFound) msg.payload = {};\nreturn msg;\n", | |
| "outputs": 1, | |
| "noerr": 0, | |
| "x": 910, | |
| "y": 1120, | |
| "wires": [ | |
| [ | |
| "da8d3df4.1c568" | |
| ] | |
| ] | |
| }, | |
| { | |
| "id": "74f36281.ae094c", | |
| "type": "server", | |
| "z": "", | |
| "name": "Home Assistant", | |
| "legacy": false, | |
| "rejectUnauthorizedCerts": true, | |
| "ha_boolean": "y|yes|true|on|home|open" | |
| } | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment