Skip to content

Instantly share code, notes, and snippets.

@TomGranot
Last active February 26, 2020 18:58
Show Gist options
  • Save TomGranot/9fa7197bd8963376eb7199a96ab64744 to your computer and use it in GitHub Desktop.
Save TomGranot/9fa7197bd8963376eb7199a96ab64744 to your computer and use it in GitHub Desktop.
ForgetMeNot Node-RED Flow
[
{
"id": "dfd248d3.68e5c8",
"type": "tab",
"label": "ForgetMeNot",
"disabled": false,
"info": ""
},
{
"id": "6e222d22.55f4f4",
"type": "http in",
"z": "dfd248d3.68e5c8",
"name": "Integromat WiFi Leave Endpoing",
"url": "wifi/leave",
"method": "post",
"upload": false,
"swaggerDoc": "",
"x": 410,
"y": 160,
"wires": [
[
"71761962.4a0dc8",
"82d69095.8ed6a",
"b8a28c5c.0ec3d",
"f004e04a.ad584"
]
]
},
{
"id": "73ec8c19.f41ec4",
"type": "ui_switch",
"z": "dfd248d3.68e5c8",
"name": "Smart Outlet Switch",
"label": "Smart Outlet On / Off",
"tooltip": "",
"group": "6507d143.d40d9",
"order": 0,
"width": 0,
"height": 0,
"passthru": true,
"decouple": "false",
"topic": "house/switch",
"style": "",
"onvalue": "on",
"onvalueType": "str",
"onicon": "",
"oncolor": "",
"offvalue": "off",
"offvalueType": "str",
"officon": "",
"offcolor": "",
"x": 610,
"y": 620,
"wires": [
[
"daa7bafd.684cb8",
"ef09547a.02d478"
]
]
},
{
"id": "daa7bafd.684cb8",
"type": "mqtt out",
"z": "dfd248d3.68e5c8",
"name": "Smart Outlet Activator",
"topic": "house/switch",
"qos": "",
"retain": "",
"broker": "f5b7e35.f1f8a2",
"x": 1130,
"y": 620,
"wires": []
},
{
"id": "b3e5869c.736a98",
"type": "pushbullet",
"z": "dfd248d3.68e5c8",
"config": "c10abbb9.a3b138",
"pushtype": "note",
"title": "",
"chan": "",
"name": "Send Push Notification",
"x": 1280,
"y": 160,
"wires": []
},
{
"id": "82d69095.8ed6a",
"type": "function",
"z": "dfd248d3.68e5c8",
"name": "Build Push Notification",
"func": "// Get status of ALL THE THINGS\nvar doorState = global.get('doorState') || 'closed'; \nvar smartOutletState = global.get('smartOutletState') || 'off'; \nvar lightState = global.get('lightState') || 'off'; \nvar windowState = global.get('windowState') || 'closed'; \nvar heateState = global.get('heatState') || 'off'; \n\n// Logs\nconsole.log('received:', msg.req.body);\nconsole.log('current status of door is:', doorState);\nconsole.log('current status of smart outlet is:', smartOutletState);\nconsole.log('current status of light is:', lightState);\nconsole.log('current status of window is:', windowState);\nconsole.log('current status of space heater is:', heatState);\n\n\n// Accumulate notifcation messages\nvar cumulativeReminders = '';\n\nif(doorState == 'open') {\n cumulativeReminders += \" Door is open!\\n\";\n}\n\nif(smartOutletState == 'on') {\n cumulativeReminders += \" Smart Outlet is on!\\n\";\n}\n\nif(lightState == 'on') {\n cumulativeReminders += \" Light is on!\\n\";\n}\n\nif(windowState == 'open') {\n cumulativeReminders += \" Window is open!\\n\";\n}\nif(heatState == 'on') {\n cumulativeReminders += \" Space heater seems to be hot, we will notify you in 5 minutes if it is still on\\n\";\n}\n\n// check if need to send notification\nif(cumulativeReminders === ''){\n return;\n}\n// Send payload to notification \nelse{\nreturn {payload: 'Oh No! You forgot something:\\n' + cumulativeReminders + '\\nCheck your dashboard here: http://YOUR_NGROK_ID.ngrok.io/ui', topic:'ForgetMeNot Notification'};\n}",
"outputs": 1,
"noerr": 0,
"x": 920,
"y": 160,
"wires": [
[
"b3e5869c.736a98"
]
]
},
{
"id": "71761962.4a0dc8",
"type": "http response",
"z": "dfd248d3.68e5c8",
"name": "Send Success Message To Integromat",
"statusCode": "200",
"headers": {},
"x": 870,
"y": 280,
"wires": []
},
{
"id": "83503653.764ef8",
"type": "ui_text",
"z": "dfd248d3.68e5c8",
"group": "64b34077.320eb",
"order": 3,
"width": 0,
"height": 0,
"name": "Window State Indicator",
"label": "Window is",
"format": "{{msg.payload}}",
"layout": "row-center",
"x": 1170,
"y": 1000,
"wires": []
},
{
"id": "e78a8f8b.3b9dd",
"type": "mqtt in",
"z": "dfd248d3.68e5c8",
"name": "Window Sensor Input",
"topic": "house/window",
"qos": "2",
"datatype": "auto",
"broker": "f5b7e35.f1f8a2",
"x": 640,
"y": 1000,
"wires": [
[
"83503653.764ef8",
"295e7dee.ba1112"
]
]
},
{
"id": "5a3d3418.a312ac",
"type": "ui_text",
"z": "dfd248d3.68e5c8",
"group": "e7c1d39f.9832a",
"order": 3,
"width": 0,
"height": 0,
"name": "Door State Indicator",
"label": "Door is ",
"format": "{{msg.payload}}",
"layout": "row-center",
"x": 1140,
"y": 400,
"wires": []
},
{
"id": "39faef09.3af4b",
"type": "ui_switch",
"z": "dfd248d3.68e5c8",
"name": "Door Switch",
"label": "Close / Open Door",
"tooltip": "",
"group": "e7c1d39f.9832a",
"order": 0,
"width": 0,
"height": 0,
"passthru": true,
"decouple": "false",
"topic": "door",
"style": "",
"onvalue": "open",
"onvalueType": "str",
"onicon": "",
"oncolor": "",
"offvalue": "closed",
"offvalueType": "str",
"officon": "",
"offcolor": "",
"x": 590,
"y": 480,
"wires": [
[
"11394a1d.c9d1a6",
"345e2aae.6f6c46"
]
]
},
{
"id": "11394a1d.c9d1a6",
"type": "mqtt out",
"z": "dfd248d3.68e5c8",
"name": "Door Activator",
"topic": "house/door",
"qos": "2",
"retain": "",
"broker": "f5b7e35.f1f8a2",
"x": 1120,
"y": 480,
"wires": []
},
{
"id": "6934ada7.b7a964",
"type": "ui_text",
"z": "dfd248d3.68e5c8",
"group": "14c17a5a.ee6676",
"order": 3,
"width": "0",
"height": "0",
"name": "Light State Indicator",
"label": "Light is",
"format": "{{msg.payload}}",
"layout": "row-center",
"x": 1160,
"y": 860,
"wires": []
},
{
"id": "fb150415.37af08",
"type": "mqtt in",
"z": "dfd248d3.68e5c8",
"name": "Light Sensor Input",
"topic": "house/light",
"qos": "0",
"datatype": "auto",
"broker": "f5b7e35.f1f8a2",
"x": 630,
"y": 860,
"wires": [
[
"6934ada7.b7a964",
"48c7696b.1abe38"
]
]
},
{
"id": "345e2aae.6f6c46",
"type": "function",
"z": "dfd248d3.68e5c8",
"name": "Door State Logic",
"func": "var doorState = msg.payload;\nglobal.set('doorState', doorState);\nreturn {payload: doorState};",
"outputs": 1,
"noerr": 0,
"x": 890,
"y": 440,
"wires": [
[
"5a3d3418.a312ac",
"f4edd4a0.de56b8"
]
]
},
{
"id": "295e7dee.ba1112",
"type": "function",
"z": "dfd248d3.68e5c8",
"name": "Window State Logic",
"func": "var windowState = msg.payload;\nglobal.set('windowState', windowState);\nreturn {payload: windowState};",
"outputs": 1,
"noerr": 0,
"x": 880,
"y": 960,
"wires": [
[
"83503653.764ef8",
"8601a6e1.7e0818"
]
]
},
{
"id": "ef09547a.02d478",
"type": "function",
"z": "dfd248d3.68e5c8",
"name": "Smart Outlet State Logic",
"func": "var smartOutletState = msg.payload;\nglobal.set('smartOutletState', smartOutletState);\nreturn {payload: smartOutletState};",
"outputs": 1,
"noerr": 0,
"x": 860,
"y": 580,
"wires": [
[
"ca7d4ef2.2fe78",
"c6a9e3c8.bf474"
]
]
},
{
"id": "ca7d4ef2.2fe78",
"type": "ui_text",
"z": "dfd248d3.68e5c8",
"group": "6507d143.d40d9",
"order": 3,
"width": 0,
"height": 0,
"name": "Smart Outlet State Indicator",
"label": "Smart Outlet Is",
"format": "{{msg.payload}}",
"layout": "row-center",
"x": 1150,
"y": 540,
"wires": []
},
{
"id": "48c7696b.1abe38",
"type": "function",
"z": "dfd248d3.68e5c8",
"name": "Light State Logic",
"func": "var lightState = msg.payload;\nglobal.set('lightState', lightState);\nreturn {payload: lightState};",
"outputs": 1,
"noerr": 0,
"x": 890,
"y": 820,
"wires": [
[
"6934ada7.b7a964",
"3b971be8.84a894"
]
]
},
{
"id": "895e935b.a8769",
"type": "comment",
"z": "dfd248d3.68e5c8",
"name": "Main Application Logic",
"info": "",
"x": 860,
"y": 60,
"wires": []
},
{
"id": "38d7150b.301b9a",
"type": "comment",
"z": "dfd248d3.68e5c8",
"name": "Component Logic",
"info": "",
"x": 850,
"y": 340,
"wires": []
},
{
"id": "c6a9e3c8.bf474",
"type": "ui_led",
"z": "dfd248d3.68e5c8",
"group": "6507d143.d40d9",
"order": 2,
"width": 0,
"height": 0,
"label": "",
"labelPlacement": "left",
"labelAlignment": "left",
"colorForValue": [
{
"color": "grey",
"value": "off",
"valueType": "str"
},
{
"color": "red",
"value": "on",
"valueType": "str"
}
],
"allowColorForValueInMessage": false,
"name": "Smart Outlet State LED",
"x": 1140,
"y": 580,
"wires": []
},
{
"id": "f4edd4a0.de56b8",
"type": "ui_led",
"z": "dfd248d3.68e5c8",
"group": "e7c1d39f.9832a",
"order": 2,
"width": 0,
"height": 0,
"label": "",
"labelPlacement": "left",
"labelAlignment": "left",
"colorForValue": [
{
"color": "grey",
"value": "closed",
"valueType": "str"
},
{
"color": "red",
"value": "open",
"valueType": "str"
}
],
"allowColorForValueInMessage": false,
"name": "Door State LED",
"x": 1120,
"y": 440,
"wires": []
},
{
"id": "3b971be8.84a894",
"type": "ui_led",
"z": "dfd248d3.68e5c8",
"group": "14c17a5a.ee6676",
"order": 2,
"width": "0",
"height": "0",
"label": "",
"labelPlacement": "left",
"labelAlignment": "left",
"colorForValue": [
{
"color": "grey",
"value": "off",
"valueType": "str"
},
{
"color": "red",
"value": "on",
"valueType": "str"
}
],
"allowColorForValueInMessage": false,
"name": "Light State LED",
"x": 1140,
"y": 820,
"wires": []
},
{
"id": "8601a6e1.7e0818",
"type": "ui_led",
"z": "dfd248d3.68e5c8",
"group": "64b34077.320eb",
"order": 2,
"width": 0,
"height": 0,
"label": "",
"labelPlacement": "left",
"labelAlignment": "left",
"colorForValue": [
{
"color": "grey",
"value": "closed",
"valueType": "str"
},
{
"color": "red",
"value": "open",
"valueType": "str"
}
],
"allowColorForValueInMessage": false,
"name": "Window State LED",
"x": 1150,
"y": 960,
"wires": []
},
{
"id": "b8a28c5c.0ec3d",
"type": "debug",
"z": "dfd248d3.68e5c8",
"name": "Get Request",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "req",
"targetType": "msg",
"x": 680,
"y": 100,
"wires": []
},
{
"id": "cd27fffc.8a885",
"type": "function",
"z": "dfd248d3.68e5c8",
"name": "Heater State Logic",
"func": "var heatState = msg.payload;\nglobal.set('heatState', heatState);\nreturn {payload: heatState};",
"outputs": 1,
"noerr": 0,
"x": 870,
"y": 1100,
"wires": [
[
"1da976d2.99a5a9",
"e1cbb488.8d3d58"
]
]
},
{
"id": "b8551430.0942e8",
"type": "mqtt in",
"z": "dfd248d3.68e5c8",
"name": "Heat Sensor Input",
"topic": "house/heat",
"qos": "0",
"datatype": "auto",
"broker": "f5b7e35.f1f8a2",
"x": 610,
"y": 1140,
"wires": [
[
"1da976d2.99a5a9",
"cd27fffc.8a885"
]
]
},
{
"id": "1da976d2.99a5a9",
"type": "ui_text",
"z": "dfd248d3.68e5c8",
"group": "c80e041c.bfcd08",
"order": 3,
"width": "0",
"height": "0",
"name": "Heater State Indicator",
"label": "Space Heater is (in the last 5 minutes)",
"format": "{{msg.payload}}",
"layout": "row-center",
"x": 1120,
"y": 1140,
"wires": []
},
{
"id": "e1cbb488.8d3d58",
"type": "ui_led",
"z": "dfd248d3.68e5c8",
"group": "c80e041c.bfcd08",
"order": 2,
"width": "0",
"height": "0",
"label": "",
"labelPlacement": "left",
"labelAlignment": "left",
"colorForValue": [
{
"color": "grey",
"value": "off",
"valueType": "str"
},
{
"color": "red",
"value": "on",
"valueType": "str"
}
],
"allowColorForValueInMessage": false,
"name": "Heater State LED",
"x": 1130,
"y": 1100,
"wires": []
},
{
"id": "db7c5e1c.af8fd",
"type": "function",
"z": "dfd248d3.68e5c8",
"name": "Switch Press Logic",
"func": "var switchPressState = msg.payload;\nglobal.set('switchPressState', switchPressState);\nreturn {payload: switchPressState};",
"outputs": 1,
"noerr": 0,
"x": 890,
"y": 720,
"wires": [
[
"bb4ddeca.6ddf4",
"a93e122f.04971"
]
]
},
{
"id": "525796a.76adc68",
"type": "ui_switch",
"z": "dfd248d3.68e5c8",
"name": "Switch Press",
"label": "Turn switch on/off",
"tooltip": "",
"group": "8da0aa1a.4946d8",
"order": 0,
"width": 0,
"height": 0,
"passthru": true,
"decouple": "false",
"topic": "door",
"style": "",
"onvalue": "on",
"onvalueType": "str",
"onicon": "",
"oncolor": "",
"offvalue": "off",
"offvalueType": "str",
"officon": "",
"offcolor": "",
"x": 590,
"y": 760,
"wires": [
[
"2c8f467e.cc77ca",
"db7c5e1c.af8fd"
]
]
},
{
"id": "bb4ddeca.6ddf4",
"type": "ui_text",
"z": "dfd248d3.68e5c8",
"group": "8da0aa1a.4946d8",
"order": 3,
"width": 0,
"height": 0,
"name": "Switch Press Indicator",
"label": "Switch Press is ",
"format": "{{msg.payload}}",
"layout": "row-center",
"x": 1140,
"y": 680,
"wires": []
},
{
"id": "a93e122f.04971",
"type": "ui_led",
"z": "dfd248d3.68e5c8",
"group": "8da0aa1a.4946d8",
"order": 2,
"width": 0,
"height": 0,
"label": "",
"labelPlacement": "left",
"labelAlignment": "left",
"colorForValue": [
{
"color": "grey",
"value": "off",
"valueType": "str"
},
{
"color": "red",
"value": "on",
"valueType": "str"
}
],
"allowColorForValueInMessage": false,
"name": "Switch Press LED",
"x": 1130,
"y": 720,
"wires": []
},
{
"id": "2c8f467e.cc77ca",
"type": "mqtt out",
"z": "dfd248d3.68e5c8",
"name": "Switch Press Activator",
"topic": "house/switchPress",
"qos": "2",
"retain": "",
"broker": "f5b7e35.f1f8a2",
"x": 1140,
"y": 760,
"wires": []
},
{
"id": "dfe3c8a2.b30008",
"type": "inject",
"z": "dfd248d3.68e5c8",
"name": "default light setting off",
"topic": "house/light",
"payload": "off",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"x": 880,
"y": 900,
"wires": [
[
"6934ada7.b7a964",
"3b971be8.84a894"
]
]
},
{
"id": "cc1f1891.ada158",
"type": "inject",
"z": "dfd248d3.68e5c8",
"name": "default door setting closed",
"topic": "house/door",
"payload": "closed",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"x": 860,
"y": 400,
"wires": [
[
"5a3d3418.a312ac",
"f4edd4a0.de56b8"
]
]
},
{
"id": "c85ce4a0.83ddc8",
"type": "inject",
"z": "dfd248d3.68e5c8",
"name": "default smart outlet setting off",
"topic": "house/switch",
"payload": "off",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"x": 840,
"y": 540,
"wires": [
[
"ca7d4ef2.2fe78",
"c6a9e3c8.bf474"
]
]
},
{
"id": "eb182e4c.c7173",
"type": "inject",
"z": "dfd248d3.68e5c8",
"name": "default window setting closed",
"topic": "house/window",
"payload": "closed",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"x": 850,
"y": 1040,
"wires": [
[
"83503653.764ef8",
"8601a6e1.7e0818"
]
]
},
{
"id": "1162cf6.e4f6631",
"type": "inject",
"z": "dfd248d3.68e5c8",
"name": "default heater setting off",
"topic": "house/heat",
"payload": "off",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"x": 850,
"y": 1180,
"wires": [
[
"1da976d2.99a5a9",
"e1cbb488.8d3d58"
]
]
},
{
"id": "916d14c2.e6bdb8",
"type": "inject",
"z": "dfd248d3.68e5c8",
"name": "default switch press setting off",
"topic": "house/switchPress",
"payload": "off",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"x": 850,
"y": 680,
"wires": [
[
"bb4ddeca.6ddf4",
"a93e122f.04971"
]
]
},
{
"id": "f004e04a.ad584",
"type": "function",
"z": "dfd248d3.68e5c8",
"name": "Build Push Notification",
"func": "// Wait 5 minutes and then check if sace heater is still on if so send payload to notification node\nsetTimeout(function(){\n var heatState = global.get('heatState') || 'off'; \n if(heatState == 'on'){\n return {payload: 'Oh No! You forgot your Space Heater on' + '\\nCheck your dashboard here: http://c573eb1f.ngrok.io/ui', topic:'ForgetMeNot Notification'};\n }\n }, 300000);\n\n\n",
"outputs": 1,
"noerr": 0,
"x": 920,
"y": 200,
"wires": [
[
"b3e5869c.736a98"
]
]
},
{
"id": "6507d143.d40d9",
"type": "ui_group",
"z": "",
"name": "Smart Outlet",
"tab": "6a0af55f.6bec7c",
"order": 2,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "f5b7e35.f1f8a2",
"type": "mqtt-broker",
"z": "",
"name": "Mosquitto",
"broker": "localhost",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": false,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
},
{
"id": "c10abbb9.a3b138",
"type": "pushbullet-config",
"z": "",
"name": "PushBullet Config"
},
{
"id": "64b34077.320eb",
"type": "ui_group",
"z": "",
"name": "Window",
"tab": "6a0af55f.6bec7c",
"order": 5,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "e7c1d39f.9832a",
"type": "ui_group",
"z": "",
"name": "Door",
"tab": "6a0af55f.6bec7c",
"order": 3,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "14c17a5a.ee6676",
"type": "ui_group",
"z": "",
"name": "Light",
"tab": "6a0af55f.6bec7c",
"order": 4,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "c80e041c.bfcd08",
"type": "ui_group",
"z": "",
"name": "Space Heater",
"tab": "6a0af55f.6bec7c",
"order": 5,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "8da0aa1a.4946d8",
"type": "ui_group",
"z": "",
"name": "Switch Press",
"tab": "6a0af55f.6bec7c",
"order": 6,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "6a0af55f.6bec7c",
"type": "ui_tab",
"z": "",
"name": "ForgetMeNot - Smart Home Notifcation System",
"icon": "dashboard",
"order": 1,
"disabled": false,
"hidden": false
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment