Hello,
i have installed a template node with inside 7 checkbox (one for each day of the week) and some javascript code to manage checkbox , msg input and msg output.
I know the code i write is extremely poor and from beginner , sure can be otpimized. But in any case is working, when just one instance on flow !
I need to use more instance of same type in same flow, but something is wrong with multiple instance, i have changed the variable name for each instance, but i think still some problem with msg management scritp.
I need help to more expert writer to be drived on right method to manage this issue.
[
{
"id": "56df6ccc205c9952",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "b4d5f415b9859b8d",
"type": "ui_template",
"z": "56df6ccc205c9952",
"group": "83deb30e959514e8",
"name": "Doso Week 0",
"order": 2,
"width": 0,
"height": 0,
"format": "<div>\n<input type=\"checkbox\" id=\"doso0Day0\" onchange=\"onChangeDoso0()\">Su\n<input type=\"checkbox\" id=\"doso0Day1\" onchange=\"onChangeDoso0()\">Mo\n<input type=\"checkbox\" id=\"doso0Day2\" onchange=\"onChangeDoso0()\">Tu \n<input type=\"checkbox\" id=\"doso0Day3\" onchange=\"onChangeDoso0()\">We \n<input type=\"checkbox\" id=\"doso0Day4\" onchange=\"onChangeDoso0()\">Th \n<input type=\"checkbox\" id=\"doso0Day5\" onchange=\"onChangeDoso0()\">Fr\n<input type=\"checkbox\" id=\"doso0Day6\" onchange=\"onChangeDoso0()\">Sa\n</div>\n<script>\n (function(scope) {\n scope.$watch('msg', function(msg) { \n DosoWeek0 = msg.payload;\n \n if (DosoWeek0 & 1)\n document.getElementById('doso0Day0').checked = true ;\n else\n document.getElementById('doso0Day0').checked = false ;\n\n if (DosoWeek0 & 2)\n document.getElementById('doso0Day1').checked = true ;\n else\n document.getElementById('doso0Day1').checked = false ;\n\n if (DosoWeek0 & 4)\n document.getElementById('doso0Day2').checked = true ;\n else\n document.getElementById('doso0Day2').checked = false ;\n\n if (DosoWeek0 & 8)\n document.getElementById('doso0Day3').checked = true ;\n else\n document.getElementById('doso0Day3').checked = false ;\n\n if (DosoWeek0 & 16)\n document.getElementById('doso0Day4').checked = true ;\n else\n document.getElementById('doso0Day4').checked = false ;\n\n if (DosoWeek0 & 32)\n document.getElementById('doso0Day5').checked = true ;\n else\n document.getElementById('doso0Day5').checked = false ;\n\n if (DosoWeek0 & 64)\n document.getElementById('doso0Day6').checked = true ;\n else\n document.getElementById('doso0Day6').checked = false ;\n })\n})(scope);\n\nvar theScope = scope;\n\nfunction onChangeDoso0(){\n DosoWeek0 = 0;\n if (document.getElementById(\"doso0Day0\").checked == true)\n DosoWeek0 += 1;\n if (document.getElementById(\"doso0Day1\").checked == true)\n DosoWeek0 += 2; \n if (document.getElementById(\"doso0Day2\").checked == true)\n DosoWeek0 += 4;\n if (document.getElementById(\"doso0Day3\").checked == true)\n DosoWeek0 += 8;\n if (document.getElementById(\"doso0Day4\").checked == true)\n DosoWeek0 += 16;\n if (document.getElementById(\"doso0Day5\").checked == true)\n DosoWeek0 += 32;\n if (document.getElementById(\"doso0Day6\").checked == true)\n DosoWeek0 += 64; \n//then use where needed\ntheScope.send({payload:DosoWeek0}); \n}; \n</script>\n",
"storeOutMessages": false,
"fwdInMessages": false,
"resendOnRefresh": true,
"templateScope": "local",
"className": "",
"x": 580,
"y": 400,
"wires": [
[
"e31f971ebd719203",
"608b5d257f237585"
]
]
},
{
"id": "2fe6e7849e853429",
"type": "mqtt in",
"z": "56df6ccc205c9952",
"name": "",
"topic": "doso/DosoWeek0",
"qos": "2",
"datatype": "auto-detect",
"broker": "52a64934d1309ded",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 340,
"y": 400,
"wires": [
[
"b4d5f415b9859b8d",
"4cda65e3915a758d"
]
]
},
{
"id": "e31f971ebd719203",
"type": "mqtt out",
"z": "56df6ccc205c9952",
"name": "",
"topic": "doso/DosoWeek0&",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "52a64934d1309ded",
"x": 810,
"y": 400,
"wires": []
},
{
"id": "4cda65e3915a758d",
"type": "debug",
"z": "56df6ccc205c9952",
"name": "debug 8",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 560,
"y": 320,
"wires": []
},
{
"id": "608b5d257f237585",
"type": "debug",
"z": "56df6ccc205c9952",
"name": "debug 9",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 840,
"y": 320,
"wires": []
},
{
"id": "83deb30e959514e8",
"type": "ui_group",
"name": "Default",
"tab": "7764fc736da8525b",
"order": 1,
"disp": true,
"width": 10,
"collapse": false,
"className": ""
},
{
"id": "52a64934d1309ded",
"type": "mqtt-broker",
"name": "",
"broker": "localhost",
"port": "1799",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"autoUnsubscribe": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
},
{
"id": "7764fc736da8525b",
"type": "ui_tab",
"name": "Home",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]
and this is the not working flow, sure is wrong the msg input parser....
[
{
"id": "51aa552725a63fcf",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "c13ba3d31aeb879f",
"type": "ui_template",
"z": "51aa552725a63fcf",
"group": "49834f0bef2169df",
"name": "Doso Week 0",
"order": 1,
"width": 0,
"height": 0,
"format": "<div>\n<input type=\"checkbox\" id=\"doso0Day0\" onchange=\"onChangeDoso0()\">Su\n<input type=\"checkbox\" id=\"doso0Day1\" onchange=\"onChangeDoso0()\">Mo\n<input type=\"checkbox\" id=\"doso0Day2\" onchange=\"onChangeDoso0()\">Tu \n<input type=\"checkbox\" id=\"doso0Day3\" onchange=\"onChangeDoso0()\">We \n<input type=\"checkbox\" id=\"doso0Day4\" onchange=\"onChangeDoso0()\">Th \n<input type=\"checkbox\" id=\"doso0Day5\" onchange=\"onChangeDoso0()\">Fr\n<input type=\"checkbox\" id=\"doso0Day6\" onchange=\"onChangeDoso0()\">Sa\n</div>\n<script>\n (function(scope) {\n scope.$watch('msg', function(msg) { \n DosoWeek0 = msg.payload;\n doso0();\n })\n})(scope);\n\nfunction doso0(){\n if (DosoWeek0 & 1)\n document.getElementById('doso0Day0').checked = true ;\n else\n document.getElementById('doso0Day0').checked = false ;\n\n if (DosoWeek0 & 2)\n document.getElementById('doso0Day1').checked = true ;\n else\n document.getElementById('doso0Day1').checked = false ;\n\n if (DosoWeek0 & 4)\n document.getElementById('doso0Day2').checked = true ;\n else\n document.getElementById('doso0Day2').checked = false ;\n\n if (DosoWeek0 & 8)\n document.getElementById('doso0Day3').checked = true ;\n else\n document.getElementById('doso0Day3').checked = false ;\n\n if (DosoWeek0 & 16)\n document.getElementById('doso0Day4').checked = true ;\n else\n document.getElementById('doso0Day4').checked = false ;\n\n if (DosoWeek0 & 32)\n document.getElementById('doso0Day5').checked = true ;\n else\n document.getElementById('doso0Day5').checked = false ;\n\n if (DosoWeek0 & 64)\n document.getElementById('doso0Day6').checked = true ;\n else\n document.getElementById('doso0Day6').checked = false ;\n };\n\nvar theScope = scope;\n\nfunction onChangeDoso0(){\n DosoWeek0 = 0;\n if (document.getElementById(\"doso0Day0\").checked == true)\n DosoWeek0 += 1;\n if (document.getElementById(\"doso0Day1\").checked == true)\n DosoWeek0 += 2; \n if (document.getElementById(\"doso0Day2\").checked == true)\n DosoWeek0 += 4;\n if (document.getElementById(\"doso0Day3\").checked == true)\n DosoWeek0 += 8;\n if (document.getElementById(\"doso0Day4\").checked == true)\n DosoWeek0 += 16;\n if (document.getElementById(\"doso0Day5\").checked == true)\n DosoWeek0 += 32;\n if (document.getElementById(\"doso0Day6\").checked == true)\n DosoWeek0 += 64; \n//then use where needed\ntheScope.send({payload:DosoWeek0}); \n}; \n</script>\n",
"storeOutMessages": false,
"fwdInMessages": false,
"resendOnRefresh": true,
"templateScope": "local",
"className": "",
"x": 660,
"y": 260,
"wires": [
[
"851e4c598beba3e4"
]
]
},
{
"id": "166dff9c3cc2ef6f",
"type": "mqtt in",
"z": "51aa552725a63fcf",
"name": "",
"topic": "doso/DosoWeek0",
"qos": "2",
"datatype": "auto-detect",
"broker": "52a64934d1309ded",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 420,
"y": 260,
"wires": [
[
"c13ba3d31aeb879f",
"130088f217f41736"
]
]
},
{
"id": "851e4c598beba3e4",
"type": "mqtt out",
"z": "51aa552725a63fcf",
"name": "",
"topic": "doso/DosoWeek0&",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "52a64934d1309ded",
"x": 890,
"y": 260,
"wires": []
},
{
"id": "f2f6b6504bc1a7a3",
"type": "ui_template",
"z": "51aa552725a63fcf",
"group": "49834f0bef2169df",
"name": "Doso Week 1",
"order": 2,
"width": 0,
"height": 0,
"format": "<div>\n<input type=\"checkbox\" id=\"doso1Day0\" onchange=\"onChangeDoso1()\">Su\n<input type=\"checkbox\" id=\"doso1Day1\" onchange=\"onChangeDoso1()\">Mo\n<input type=\"checkbox\" id=\"doso1Day2\" onchange=\"onChangeDoso1()\">Tu \n<input type=\"checkbox\" id=\"doso1Day3\" onchange=\"onChangeDoso1()\">We \n<input type=\"checkbox\" id=\"doso1Day4\" onchange=\"onChangeDoso1()\">Th \n<input type=\"checkbox\" id=\"doso1Day5\" onchange=\"onChangeDoso1()\">Fr\n<input type=\"checkbox\" id=\"doso1Day6\" onchange=\"onChangeDoso1()\">Sa\n</div>\n<script>\n function doso1() { \n if (DosoWeek1 & 1)\n document.getElementById('doso1Day0').checked = true ;\n else\n document.getElementById('doso1Day0').checked = false ;\n\n if (DosoWeek1 & 2)\n document.getElementById('doso1Day1').checked = true ;\n else\n document.getElementById('doso1Day1').checked = false ;\n\n if (DosoWeek1 & 4)\n document.getElementById('doso1Day2').checked = true ;\n else\n document.getElementById('doso1Day2').checked = false ;\n\n if (DosoWeek1 & 8)\n document.getElementById('doso1Day3').checked = true ;\n else\n document.getElementById('doso1Day3').checked = false ;\n\n if (DosoWeek1 & 16)\n document.getElementById('doso1Day4').checked = true ;\n else\n document.getElementById('doso1Day4').checked = false ;\n\n if (DosoWeek1 & 32)\n document.getElementById('doso1Day5').checked = true ;\n else\n document.getElementById('doso1Day5').checked = false ;\n\n if (DosoWeek1 & 64)\n document.getElementById('doso1Day6').checked = true ;\n else\n document.getElementById('doso1Day6').checked = false ;\n };\n\nfunction onChangeDoso1(){\n DosoWeek1 = 0;\n if (document.getElementById(\"doso1Day0\").checked == true)\n DosoWeek1 += 1;\n if (document.getElementById(\"doso1Day1\").checked == true)\n DosoWeek1 += 2; \n if (document.getElementById(\"doso1Day2\").checked == true)\n DosoWeek1 += 4;\n if (document.getElementById(\"doso1Day3\").checked == true)\n DosoWeek1 += 8;\n if (document.getElementById(\"doso1Day4\").checked == true)\n DosoWeek1 += 16;\n if (document.getElementById(\"doso1Day5\").checked == true)\n DosoWeek1 += 32;\n if (document.getElementById(\"doso1Day6\").checked == true)\n DosoWeek1 += 64; \n//then use where needed\ntheScope.send({payload:DosoWeek1}); \n}; \n</script>\n",
"storeOutMessages": false,
"fwdInMessages": false,
"resendOnRefresh": true,
"templateScope": "local",
"className": "",
"x": 660,
"y": 340,
"wires": [
[
"1dce844d9147f49d"
]
]
},
{
"id": "7c87ae4b7c1621a0",
"type": "mqtt in",
"z": "51aa552725a63fcf",
"name": "",
"topic": "doso/DosoWeek1",
"qos": "2",
"datatype": "auto-detect",
"broker": "52a64934d1309ded",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 420,
"y": 340,
"wires": [
[
"f2f6b6504bc1a7a3"
]
]
},
{
"id": "1dce844d9147f49d",
"type": "mqtt out",
"z": "51aa552725a63fcf",
"name": "",
"topic": "doso/DosoWeek1&",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "52a64934d1309ded",
"x": 890,
"y": 340,
"wires": []
},
{
"id": "479a0f6924dcb280",
"type": "ui_template",
"z": "51aa552725a63fcf",
"group": "49834f0bef2169df",
"name": "Doso Week 2",
"order": 31,
"width": 0,
"height": 0,
"format": "<div>\n<input type=\"checkbox\" id=\"doso2Day0\" onchange=\"onChangedoso2()\">Su\n<input type=\"checkbox\" id=\"doso2Day1\" onchange=\"onChangedoso2()\">Mo\n<input type=\"checkbox\" id=\"doso2Day2\" onchange=\"onChangedoso2()\">Tu \n<input type=\"checkbox\" id=\"doso2Day3\" onchange=\"onChangedoso2()\">We \n<input type=\"checkbox\" id=\"doso2Day4\" onchange=\"onChangedoso2()\">Th \n<input type=\"checkbox\" id=\"doso2Day5\" onchange=\"onChangedoso2()\">Fr\n<input type=\"checkbox\" id=\"doso2Day6\" onchange=\"onChangedoso2()\">Sa\n</div>\n<script>\n function doso2() {\n \n if (dosoWeek2 & 1)\n document.getElementById('doso2Day0').checked = true ;\n else\n document.getElementById('doso2Day0').checked = false ;\n\n if (dosoWeek2 & 2)\n document.getElementById('doso2Day1').checked = true ;\n else\n document.getElementById('doso2Day1').checked = false ;\n\n if (dosoWeek2 & 4)\n document.getElementById('doso2Day2').checked = true ;\n else\n document.getElementById('doso2Day2').checked = false ;\n\n if (dosoWeek2 & 8)\n document.getElementById('doso2Day3').checked = true ;\n else\n document.getElementById('doso2Day3').checked = false ;\n\n if (dosoWeek2 & 16)\n document.getElementById('doso2Day4').checked = true ;\n else\n document.getElementById('doso2Day4').checked = false ;\n\n if (dosoWeek2 & 32)\n document.getElementById('doso2Day5').checked = true ;\n else\n document.getElementById('doso2Day5').checked = false ;\n\n if (dosoWeek2 & 64)\n document.getElementById('doso2Day6').checked = true ;\n else\n document.getElementById('doso2Day6').checked = false ;\n };\n\nfunction onChangedoso2(){\n dosoWeek2 = 0;\n if (document.getElementById(\"doso2Day0\").checked == true)\n dosoWeek2 += 1;\n if (document.getElementById(\"doso2Day1\").checked == true)\n dosoWeek2 += 2; \n if (document.getElementById(\"doso2Day2\").checked == true)\n dosoWeek2 += 4;\n if (document.getElementById(\"doso2Day3\").checked == true)\n dosoWeek2 += 8;\n if (document.getElementById(\"doso2Day4\").checked == true)\n dosoWeek2 += 16;\n if (document.getElementById(\"doso2Day5\").checked == true)\n dosoWeek2 += 32;\n if (document.getElementById(\"doso2Day6\").checked == true)\n dosoWeek2 += 64; \n//then use where needed\ntheScope.send({payload:dosoWeek2}); \n}; \n</script>\n",
"storeOutMessages": false,
"fwdInMessages": false,
"resendOnRefresh": true,
"templateScope": "local",
"className": "",
"x": 660,
"y": 420,
"wires": [
[
"9eeef6ef22a92849"
]
]
},
{
"id": "ed9c218768992989",
"type": "mqtt in",
"z": "51aa552725a63fcf",
"name": "",
"topic": "doso/DosoWeek2",
"qos": "2",
"datatype": "auto-detect",
"broker": "52a64934d1309ded",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 420,
"y": 420,
"wires": [
[
"479a0f6924dcb280"
]
]
},
{
"id": "9eeef6ef22a92849",
"type": "mqtt out",
"z": "51aa552725a63fcf",
"name": "",
"topic": "doso/DosoWeek2&",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "52a64934d1309ded",
"x": 890,
"y": 420,
"wires": []
},
{
"id": "e8b993b725792309",
"type": "ui_template",
"z": "51aa552725a63fcf",
"group": "49834f0bef2169df",
"name": "Doso Week 3",
"order": 21,
"width": 0,
"height": 0,
"format": "<div>\n<input type=\"checkbox\" id=\"doso3Day0\" onchange=\"onChangedoso3()\">Su\n<input type=\"checkbox\" id=\"doso3Day1\" onchange=\"onChangedoso3()\">Mo\n<input type=\"checkbox\" id=\"doso3Day2\" onchange=\"onChangedoso3()\">Tu \n<input type=\"checkbox\" id=\"doso3Day3\" onchange=\"onChangedoso3()\">We \n<input type=\"checkbox\" id=\"doso3Day4\" onchange=\"onChangedoso3()\">Th \n<input type=\"checkbox\" id=\"doso3Day5\" onchange=\"onChangedoso3()\">Fr\n<input type=\"checkbox\" id=\"doso3Day6\" onchange=\"onChangedoso3()\">Sa\n</div>\n<script>\n function doso3() {\n \n if (dosoWeek3 & 1)\n document.getElementById('doso3Day0').checked = true ;\n else\n document.getElementById('doso3Day0').checked = false ;\n\n if (dosoWeek3 & 2)\n document.getElementById('doso3Day1').checked = true ;\n else\n document.getElementById('doso3Day1').checked = false ;\n\n if (dosoWeek3 & 4)\n document.getElementById('doso3Day2').checked = true ;\n else\n document.getElementById('doso3Day2').checked = false ;\n\n if (dosoWeek3 & 8)\n document.getElementById('doso3Day3').checked = true ;\n else\n document.getElementById('doso3Day3').checked = false ;\n\n if (dosoWeek3 & 16)\n document.getElementById('doso3Day4').checked = true ;\n else\n document.getElementById('doso3Day4').checked = false ;\n\n if (dosoWeek3 & 32)\n document.getElementById('doso3Day5').checked = true ;\n else\n document.getElementById('doso3Day5').checked = false ;\n\n if (dosoWeek3 & 64)\n document.getElementById('doso3Day6').checked = true ;\n else\n document.getElementById('doso3Day6').checked = false ;\n };\n\n\nfunction onChangedoso3(){\n dosoWeek3 = 0;\n if (document.getElementById(\"doso3Day0\").checked == true)\n dosoWeek3 += 1;\n if (document.getElementById(\"doso3Day1\").checked == true)\n dosoWeek3 += 2; \n if (document.getElementById(\"doso3Day2\").checked == true)\n dosoWeek3 += 4;\n if (document.getElementById(\"doso3Day3\").checked == true)\n dosoWeek3 += 8;\n if (document.getElementById(\"doso3Day4\").checked == true)\n dosoWeek3 += 16;\n if (document.getElementById(\"doso3Day5\").checked == true)\n dosoWeek3 += 32;\n if (document.getElementById(\"doso3Day6\").checked == true)\n dosoWeek3 += 64; \n//then use where needed\ntheScope.send({payload:dosoWeek3}); \n}; \n</script>\n",
"storeOutMessages": false,
"fwdInMessages": false,
"resendOnRefresh": true,
"templateScope": "local",
"className": "",
"x": 660,
"y": 500,
"wires": [
[
"1446a045cd150428"
]
]
},
{
"id": "91a459d095294460",
"type": "mqtt in",
"z": "51aa552725a63fcf",
"name": "",
"topic": "doso/DosoWeek3",
"qos": "2",
"datatype": "auto-detect",
"broker": "52a64934d1309ded",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 420,
"y": 500,
"wires": [
[
"e8b993b725792309"
]
]
},
{
"id": "1446a045cd150428",
"type": "mqtt out",
"z": "51aa552725a63fcf",
"name": "",
"topic": "doso/DosoWeek3&",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "52a64934d1309ded",
"x": 890,
"y": 500,
"wires": []
},
{
"id": "130088f217f41736",
"type": "debug",
"z": "51aa552725a63fcf",
"name": "debug 5",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 640,
"y": 180,
"wires": []
},
{
"id": "49834f0bef2169df",
"type": "ui_group",
"name": "Default",
"tab": "7764fc736da8525b",
"order": 1,
"disp": true,
"width": 10,
"collapse": false,
"className": ""
},
{
"id": "52a64934d1309ded",
"type": "mqtt-broker",
"name": "",
"broker": "localhost",
"port": "1799",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"autoUnsubscribe": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
},
{
"id": "7764fc736da8525b",
"type": "ui_tab",
"name": "Home",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]
thank