Hi All.
So I hope that someone cleverer than me can help with optimising a flow that I'm working on (actually had it working, but the raspi memory card died and my backup was faulty)... Anyways, doing it second time, I hoped that someone here would provide help on a smarter way of going about it.
Basically, my flow(s) controls a series of vents in my basement, which dependent on different weather conditions will start.
I have previously done the on/off logic manually, but maybe there's a node or something that will help making it simpler.
The basic functionality is this:
I set a max runtime, and a minimumtime to wait between runs. If the weather conditions are within threshold, a true message will be received, which - if waittime is over - will start the vents running the set runtime.
Anyone knowledgeable of a cleverer way of achieving this than the rather complex way I'm doing it now?
[
{
"id": "76c93132.4718e8",
"type": "tab",
"label": "On-Off logic",
"disabled": false,
"info": ""
},
{
"id": "cc514a9c.f4c488",
"type": "comment",
"z": "76c93132.4718e8",
"name": "GLOBAL HUMIDITY ON / OFF INPUT",
"info": "",
"x": 390,
"y": 560,
"wires": []
},
{
"id": "dce663bc.faf178",
"type": "comment",
"z": "76c93132.4718e8",
"name": "PANEL INPUT",
"info": "",
"x": 250,
"y": 1020,
"wires": []
},
{
"id": "b3c4512f.f9f3d8",
"type": "comment",
"z": "76c93132.4718e8",
"name": "TIMERS",
"info": "",
"x": 1060,
"y": 900,
"wires": []
},
{
"id": "7a6db23d.5a1f0c",
"type": "inject",
"z": "76c93132.4718e8",
"name": "",
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": "",
"topic": "",
"payload": "60",
"payloadType": "num",
"x": 250,
"y": 1140,
"wires": [
[
"1f9d9a45.d46ff6"
]
]
},
{
"id": "1f9d9a45.d46ff6",
"type": "ui_numeric",
"z": "76c93132.4718e8",
"name": "",
"label": "setWaitTime (minutes)",
"tooltip": "Time to wait between runs",
"group": "962c32d6.8a7118",
"order": 2,
"width": 0,
"height": 0,
"wrap": false,
"passthru": false,
"topic": "",
"topicType": "str",
"format": "{{value}}",
"min": "5",
"max": "180",
"step": "5",
"className": "",
"x": 460,
"y": 1140,
"wires": [
[
"b6840176.c22678",
"18d8ccc6a9b681ae"
]
]
},
{
"id": "dcd51979.16762",
"type": "ui_numeric",
"z": "76c93132.4718e8",
"name": "",
"label": "setRunTime (minutes)",
"tooltip": "Maximum time to run fan",
"group": "962c32d6.8a7118",
"order": 3,
"width": 0,
"height": 0,
"passthru": false,
"topic": "",
"format": "{{value}}",
"min": "5",
"max": "180",
"step": "5",
"x": 460,
"y": 1200,
"wires": [
[
"cb15852b.67ba6"
]
]
},
{
"id": "7a7b44ad.970bb4",
"type": "inject",
"z": "76c93132.4718e8",
"name": "",
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": "",
"topic": "",
"payload": "15",
"payloadType": "num",
"x": 250,
"y": 1200,
"wires": [
[
"dcd51979.16762"
]
]
},
{
"id": "dacc0ddd.1fc6d",
"type": "comment",
"z": "76c93132.4718e8",
"name": "PANEL OUTPUT",
"info": "",
"x": 1460,
"y": 320,
"wires": []
},
{
"id": "b6840176.c22678",
"type": "function",
"z": "76c93132.4718e8",
"name": "Set Timer (later to be Minutes*60)",
"func": "global.set(\"setWaitTime\", msg.payload * 60); // seconds to minutes\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 744.9999694824219,
"y": 1141.6666707992554,
"wires": [
[
"2142d13bd7ca8396"
]
]
},
{
"id": "cb15852b.67ba6",
"type": "function",
"z": "76c93132.4718e8",
"name": "Set Timer (later to be Minutes*60)",
"func": "global.set('setRunTime', msg.payload * 60); // seconds to minutes\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 744.9999694824219,
"y": 1196.666714668274,
"wires": [
[]
]
},
{
"id": "a2b3e6a3.ab355",
"type": "mytimeout",
"z": "76c93132.4718e8",
"name": "timerWait",
"outtopic": "timerWait",
"outsafe": "on",
"outwarning": "",
"outunsafe": "off",
"warning": "0",
"timer": "6",
"debug": false,
"ndebug": false,
"ignoreCase": false,
"repeat": false,
"again": false,
"x": 1240,
"y": 1000,
"wires": [
[
"9d703ea6.447f3"
],
[
"1f972648.38551a"
]
]
},
{
"id": "ff2c7ded.225eb8",
"type": "switch",
"z": "76c93132.4718e8",
"name": "True/False",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "true"
},
{
"t": "false"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 848.0000610351562,
"y": 1004,
"wires": [
[
"98bb52b9.e51dd8"
],
[
"4bd91ae.cf4e064"
]
]
},
{
"id": "b1cd4a8b.5790c",
"type": "dsm",
"z": "76c93132.4718e8",
"name": "Main",
"sm_config": "{\n \"currentState\": \"undefined\",\n \"data\": {\n \"timerWait\": false,\n \"timerRun\": false,\n \"toggle_Ah\": false,\n \"toggle_Manual\": false\n },\n \"methods\": {\n \n \"timerWait\": \"sm.data.timerWait = msg.payload;\",\n \"timerRun\": \"sm.data.timerRun = msg.payload;\",\n \"toggle_Ah\": \"sm.data.toggle_Ah = msg.payload;\",\n \"toggle_Manual\": \"sm.data.toggle_Manual = msg.payload;\",\n \"onTransition\": [\n \"if (sm.data.toggle_Manual && sm.data.timerRun) {\",\n \" sm.currentState = true;\",\n \" sm.fill = 'green';\",\n \"} else if (sm.data.toggle_Ah && sm.data.timerRun) {\",\n \" sm.currentState = true;\",\n \" sm.fill = 'green';\",\n \"} else {\",\n \" sm.currentState = false;\",\n \" sm.fill = 'yellow';\",\n \"}\",\n \"msg.payload = sm.currentState;\",\n \"output = true;\"\n ],\n \"status\": {\n \"fill\": {\n \"get\": \"sm.fill;\"\n },\n \"shape\": \"dot\",\n \"text\": {\n \"get\": \"sm.currentState;\"\n }\n }\n }\n}",
"x": 980,
"y": 720,
"wires": [
[
"c9ff195a.e69488",
"f9c92daf.18aca",
"5c3d708d.9cd15",
"82883970.177018"
]
]
},
{
"id": "a9f27c07.0ca5b8",
"type": "function",
"z": "76c93132.4718e8",
"name": "renamer",
"func": "msg.topic = \"timerRun\"\nmsg.name = \"timerRun\"\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1400,
"y": 940,
"wires": [
[
"b1cd4a8b.5790c",
"816f6bca.6fc118",
"ff2c7ded.225eb8"
]
]
},
{
"id": "b233db1a.03ac08",
"type": "switch",
"z": "76c93132.4718e8",
"name": "True/False",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "true"
},
{
"t": "false"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 730,
"y": 720,
"wires": [
[
"b1cd4a8b.5790c",
"b76a2377.ca56b"
],
[]
]
},
{
"id": "c9ff195a.e69488",
"type": "function",
"z": "76c93132.4718e8",
"name": "Test",
"func": "msg.color = (msg.payload === true)?\"red\":\"grey\";\nmsg.topic = (msg.payload === true)?\n\"fa fa-chrome fa-spin fa-2x fa-fw\":\"fa fa-chrome fa-2x\";\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1430,
"y": 360,
"wires": [
[
"ce486d38.3a2f6"
]
]
},
{
"id": "4ec3d35e.d625f4",
"type": "change",
"z": "76c93132.4718e8",
"name": "",
"rules": [
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": "on",
"fromt": "str",
"to": "true",
"tot": "bool"
},
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": "off",
"fromt": "str",
"to": "false",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1220,
"y": 940,
"wires": [
[
"a9f27c07.0ca5b8"
]
]
},
{
"id": "ede78103.079558",
"type": "ui_button",
"z": "76c93132.4718e8",
"name": "toggle_Manual",
"group": "962c32d6.8a7118",
"order": 1,
"width": 0,
"height": 0,
"passthru": false,
"label": "ON",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "true",
"payloadType": "bool",
"topic": "toggle_Manual",
"topicType": "str",
"x": 260,
"y": 1080,
"wires": [
[
"b233db1a.03ac08"
]
]
},
{
"id": "ce486d38.3a2f6",
"type": "ui_text",
"z": "76c93132.4718e8",
"group": "74b09387.ec36dc",
"order": 1,
"width": "2",
"height": "1",
"name": "",
"label": "FAN",
"format": "<font color={{msg.color}} ><i class=\"{{msg.topic}} \" style=\"font-size:2px;\"></i></font>",
"layout": "row-spread",
"x": 1570,
"y": 360,
"wires": []
},
{
"id": "5972b043.ae2db",
"type": "mytimeout",
"z": "76c93132.4718e8",
"name": "timerRun",
"outtopic": "timerRun",
"outsafe": "on",
"outwarning": "",
"outunsafe": "off",
"warning": "0",
"timer": "3",
"debug": false,
"ndebug": false,
"ignoreCase": false,
"repeat": false,
"again": false,
"x": 1060,
"y": 940,
"wires": [
[
"4ec3d35e.d625f4"
],
[
"f3e938d0.aef2a"
]
]
},
{
"id": "b76a2377.ca56b",
"type": "function",
"z": "76c93132.4718e8",
"name": "Get global time settings and timerRun gate ",
"func": "// Need to change the on to\n// { \"payload\": \"on\", \"timeout\": 69, \"warning\": 10 }\n\nif(msg.payload === true) {\n msg.payload = { \n \"payload\": \"on\", \n \"timeout\": global.get('setRunTime'),\n \"warning\": 0\n };\n} else {\n msg.payload = { \"payload\": \"off\" };\n}\n\n if(msg.topic == \"toggle_Ah\" && (!global.get('timerRun') && !global.get('timerWait') === true)) \n {\n return msg;\n }\n if(msg.topic == \"toggle_Manual\" && !global.get('timerRun') === true) \n {\n return msg;\n }\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 650,
"y": 940,
"wires": [
[
"5972b043.ae2db",
"b8c9f632.f35548",
"cbe89198.ae6a38"
]
]
},
{
"id": "c0dfb87e.f22148",
"type": "ui_text",
"z": "76c93132.4718e8",
"group": "74b09387.ec36dc",
"order": 3,
"width": "0",
"height": "0",
"name": "",
"label": "REMAINING RUN TIME",
"format": "{{msg.payload}}",
"layout": "row-spread",
"x": 1690,
"y": 420,
"wires": []
},
{
"id": "4609a9ea.533df8",
"type": "ui_text",
"z": "76c93132.4718e8",
"group": "74b09387.ec36dc",
"order": 4,
"width": "0",
"height": "0",
"name": "",
"label": "REMAINING WAIT TIME",
"format": "{{msg.payload}}",
"layout": "row-spread",
"x": 1690,
"y": 480,
"wires": []
},
{
"id": "35a11ad.3fffce6",
"type": "function",
"z": "76c93132.4718e8",
"name": "Test",
"func": "msg.color = (msg.payload === true)?\"lime\":\"grey\";\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1430,
"y": 540,
"wires": [
[
"c9e20497.c5ff58"
]
]
},
{
"id": "c9e20497.c5ff58",
"type": "ui_text",
"z": "76c93132.4718e8",
"group": "74b09387.ec36dc",
"order": 2,
"width": "3",
"height": "1",
"name": "",
"label": "aH switch",
"format": "<font color={{msg.color}} ><i class=\"fa fa-circle\" style=\"font-size:36px;\"></i></font>",
"layout": "row-spread",
"x": 1580,
"y": 540,
"wires": []
},
{
"id": "75294026.c3b3d",
"type": "function",
"z": "76c93132.4718e8",
"name": "renamer",
"func": "msg.topic = \"timerWait\"\nmsg.name = \"timerWait\"\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1560,
"y": 1000,
"wires": [
[
"b1cd4a8b.5790c",
"3d113495.28c70c"
]
]
},
{
"id": "9d703ea6.447f3",
"type": "change",
"z": "76c93132.4718e8",
"name": "",
"rules": [
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": "on",
"fromt": "str",
"to": "true",
"tot": "bool"
},
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": "off",
"fromt": "str",
"to": "false",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1400,
"y": 1000,
"wires": [
[
"75294026.c3b3d"
]
]
},
{
"id": "f3e938d0.aef2a",
"type": "function",
"z": "76c93132.4718e8",
"name": "[s] to [hh:mm:ss]",
"func": "// Message from preceeding node is in seconds - should be less than 24 hours (86400 seconds).\nvar time = (new Date(msg.payload * 1000)).toUTCString().match(/(\\d\\d:\\d\\d:\\d\\d)/)[0];\n// Pass on the string to the next node, what ever that may be. (groov Data Store for example).\nmsg.payload = time;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1460,
"y": 420,
"wires": [
[
"c0dfb87e.f22148"
]
]
},
{
"id": "1f972648.38551a",
"type": "function",
"z": "76c93132.4718e8",
"name": "[s] to [hh:mm:ss]",
"func": "// Message from preceeding node is in seconds - should be less than 24 hours (86400 seconds).\nvar time = (new Date(msg.payload * 1000)).toUTCString().match(/(\\d\\d:\\d\\d:\\d\\d)/)[0];\n// Pass on the string to the next node, what ever that may be. (groov Data Store for example).\nmsg.payload = time;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1460,
"y": 480,
"wires": [
[
"4609a9ea.533df8"
]
]
},
{
"id": "816f6bca.6fc118",
"type": "function",
"z": "76c93132.4718e8",
"name": "global timerRun",
"func": "global.set('timerRun', msg.payload); \nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1580,
"y": 940,
"wires": [
[]
]
},
{
"id": "3d113495.28c70c",
"type": "function",
"z": "76c93132.4718e8",
"name": "global timerRun",
"func": "global.set('timerWait', msg.payload); \nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1720,
"y": 1000,
"wires": [
[]
]
},
{
"id": "27150f18.7e4138",
"type": "inject",
"z": "76c93132.4718e8",
"name": "",
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"payload": "false",
"payloadType": "bool",
"x": 1430,
"y": 1080,
"wires": [
[
"3d113495.28c70c",
"816f6bca.6fc118"
]
]
},
{
"id": "98bb52b9.e51dd8",
"type": "change",
"z": "76c93132.4718e8",
"name": "reset for manual",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{ \"payload\": \"off\" }",
"tot": "json"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1139.9999618530273,
"y": 1068.3333745002747,
"wires": [
[
"a2b3e6a3.ab355",
"5cf5542b.864d3c"
]
]
},
{
"id": "f72c0e11.a4efa",
"type": "function",
"z": "76c93132.4718e8",
"name": "get global humOnOff",
"func": "msg.payload = global.get(\"humOnOff\");\nmsg.topic = \"toggle_Ah\"\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 340,
"y": 640,
"wires": [
[
"b233db1a.03ac08",
"35a11ad.3fffce6"
]
]
},
{
"id": "f9efdf3f.9ae898",
"type": "inject",
"z": "76c93132.4718e8",
"name": "",
"repeat": "1",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 310,
"y": 600,
"wires": [
[
"f72c0e11.a4efa"
]
]
},
{
"id": "f9c92daf.18aca",
"type": "Sonoff device",
"z": "76c93132.4718e8",
"mode": "0",
"broker": "864c9ec1.9c208",
"device": "sonoff",
"name": "Sonoff switch",
"onValue": "ON",
"offValue": "OFF",
"cmdPrefix": "cmnd",
"statPrefix": "stat",
"telePrefix": "tele",
"x": 1250,
"y": 720,
"wires": [
[]
]
},
{
"id": "5ab34a74.33d784",
"type": "ui_chart",
"z": "76c93132.4718e8",
"name": "",
"group": "326cc72f.e0ba98",
"order": 4,
"width": "6",
"height": "3",
"label": "On/Off",
"chartType": "line",
"legend": "false",
"xformat": "HH:mm:ss",
"interpolate": "step",
"nodata": "",
"dot": false,
"ymin": "0",
"ymax": "20",
"removeOlder": "8",
"removeOlderPoints": "",
"removeOlderUnit": "3600",
"cutout": 0,
"useOneColor": false,
"colors": [
"#ff2600",
"#ff2600",
"#ff2600",
"#ff2600",
"#98df8a",
"#d62728",
"#ff9896",
"#9467bd",
"#c5b0d5"
],
"outputs": 1,
"x": 1716,
"y": 642,
"wires": [
[]
]
},
{
"id": "5c3d708d.9cd15",
"type": "function",
"z": "76c93132.4718e8",
"name": "graph_OnOff (bool to number)",
"func": "var msg1 = {};\n\nif (msg.payload === true){\nmsg1.payload = 15;\nmsg1.topic = 'On/Off';\n}\nelse if (msg.payload === false) {\nmsg1.payload = 5;\nmsg1.topic = 'On/Off';\n}\n\nreturn msg1;",
"outputs": 1,
"noerr": 0,
"x": 1468,
"y": 648,
"wires": [
[
"5ab34a74.33d784",
"923835e9.4f59"
]
]
},
{
"id": "923835e9.4f59",
"type": "link out",
"z": "76c93132.4718e8",
"name": "",
"links": [
"d718360b.e9e73"
],
"x": 1680,
"y": 696,
"wires": []
},
{
"id": "82883970.177018",
"type": "debug",
"z": "76c93132.4718e8",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 1051.6666666666665,
"y": 621.6666666666666,
"wires": []
},
{
"id": "6cda23b8.ef1eec",
"type": "debug",
"z": "76c93132.4718e8",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 1203.333251953125,
"y": 1362.9999389648438,
"wires": []
},
{
"id": "5cf5542b.864d3c",
"type": "debug",
"z": "76c93132.4718e8",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 1220,
"y": 1163.333251953125,
"wires": []
},
{
"id": "b8c9f632.f35548",
"type": "debug",
"z": "76c93132.4718e8",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 1255,
"y": 1216.6666259765625,
"wires": []
},
{
"id": "cbe89198.ae6a38",
"type": "debug",
"z": "76c93132.4718e8",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 938,
"y": 832,
"wires": []
},
{
"id": "4bd91ae.cf4e064",
"type": "function",
"z": "76c93132.4718e8",
"name": "Get setWaitTime",
"func": "var msg1 = {};\n\nif(msg.payload === false) \n{\n msg1.payload = \n { \n \"payload\": \"on\", \n \"timeout\": global.get('setWaitTime'),\n \"warning\": 0\n };\n};\nreturn msg1;\n \n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1048,
"y": 1012,
"wires": [
[
"a2b3e6a3.ab355",
"6cda23b8.ef1eec"
]
]
},
{
"id": "2142d13bd7ca8396",
"type": "debug",
"z": "76c93132.4718e8",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"statusVal": "payload",
"statusType": "auto",
"x": 1010,
"y": 1160,
"wires": []
},
{
"id": "18d8ccc6a9b681ae",
"type": "change",
"z": "76c93132.4718e8",
"name": "",
"rules": [
{
"t": "set",
"p": "setWaitTime",
"pt": "global",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 580,
"y": 1060,
"wires": [
[
"2142d13bd7ca8396"
]
]
},
{
"id": "962c32d6.8a7118",
"type": "ui_group",
"name": "Input",
"tab": "5bd8407f.49a06",
"order": 5,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "74b09387.ec36dc",
"type": "ui_group",
"name": "Fan Status",
"tab": "5bd8407f.49a06",
"order": 2,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "864c9ec1.9c208",
"type": "mqtt-broker",
"name": "",
"broker": "192.168.1.45",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"compatmode": false,
"protocolVersion": "4",
"keepalive": "15",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthRetain": "false",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeRetain": "false",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willRetain": "false",
"willPayload": "",
"willMsg": {},
"sessionExpiry": ""
},
{
"id": "326cc72f.e0ba98",
"type": "ui_group",
"name": "Input",
"tab": "fefb308c.3ddd1",
"order": 4,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "5bd8407f.49a06",
"type": "ui_tab",
"name": "Home",
"icon": "dashboard",
"order": 1,
"disabled": false,
"hidden": false
},
{
"id": "fefb308c.3ddd1",
"type": "ui_tab",
"name": "Detail",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]