Combined Alexa Flow

I have a single flow that mimic alexa instead of many single flows . I’ll try to explain. it.

[{"id":"8612386267fb8ebd","type":"subflow","name":"termometer","info":"","category":"","in":[{"x":40,"y":80,"wires":[{"id":"3c413979ba48a904"}]}],"out":[{"x":540,"y":80,"wires":[{"id":"e119aadfe2c3e6ee","port":0}]}],"env":[],"meta":{},"color":"#E6E0F8"},{"id":"3c413979ba48a904","type":"function","z":"8612386267fb8ebd","name":"termometro","func":"var msg1 = JSON.parse(JSON.stringify(msg));\nvar l = global.get('th-'+msg.payload.deviceroom,'ram');\nvar e = global.get('th-terrazzo','ram');\n\nif(msg.payload.deviceroom!=\"terrazzo\"){\n    txt = \"La temperatura della stanza \"+msg.payload.deviceroom+\" è di \"+l.temperature+ \" gradi. La temperatura esterna è di \"+e.temperature+ \" gradi.\";\n}else{\n    txt = \"La temperatura della stanza \"+msg.payload.deviceroom+\" è di \"+l.temperature+ \" gradi.\";\n}\nmsg1.payload.text=txt;\n\nreturn msg1","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":190,"y":80,"wires":[["e119aadfe2c3e6ee"]]},{"id":"e119aadfe2c3e6ee","type":"subflow:7c9a43c75a8b561e","z":"8612386267fb8ebd","name":"","x":390,"y":80,"wires":[[]]},{"id":"405b554ae2b18a0c","type":"subflow","name":"TIMING","info":"","category":"","in":[{"x":60,"y":100,"wires":[{"id":"62bec12e4905ce1b"}]}],"out":[{"x":455,"y":75,"wires":[{"id":"fdc198c8e7ebe137","port":0}]},{"x":455,"y":135,"wires":[{"id":"b8027df6a0358258","port":0}]}],"env":[],"meta":{},"color":"#DDAA99"},{"id":"62bec12e4905ce1b","type":"function","z":"405b554ae2b18a0c","name":"timing","func":"tot=0\n\ntoggle={\"on\":\"off\",\"off\":\"on\"};\nvar msg1 = JSON.parse(JSON.stringify(msg));\nvar msg2 = JSON.parse(JSON.stringify(msg));\n\nconst messages = new Array(node.outputCount)\n\n//PAYLOAD CLEANUP \n//SHELLY\nif(\"turn\" in msg.payload){\n    msg2.payload={\"turn\":msg.payload.command};\n//Z2M\n}else if (\"state\" in msg.payload){\n    msg2.payload={\"state\":msg.payload.command};\n//MULTIPOINT DEVICE\n}else if (\"state_l1\" in msg.payload){\n    msg2.payload={\"state_l1\":msg.payload.command};\n}else if (\"state_l2\" in msg.payload){\n    msg2.payload={\"state_l2\":msg.payload.command};\n}else if (\"state_l3\" in msg.payload){\n    msg2.payload={\"state_l3\":msg.payload.command};\n}else if (\"state_l4\" in msg.payload){\n    msg2.payload={\"state_l4\":msg.payload.command};\n}else if (\"state_l5\" in msg.payload){\n    msg2.payload={\"state_l5\":msg.payload.command};\n}\n\nif (\"delay\" in msg){\n    tot+=msg.delay;\n}\nmessages[0]=msg1;\n\nif (\"duration\" in msg){\n    if (msg.duration>0){\n        tot+=msg.duration\n        msg2.delay=tot;\n        if(\"turn\" in msg.payload){\n            msg2.payload.turn=toggle[msg.payload.command] ?? null;\n        }else if (\"state\" in msg.payload){\n            msg2.payload.state=toggle[msg.payload.command] ?? null;\n        }else if (\"state_l1\" in msg.payload){\n            msg2.payload.state_l1=toggle[msg.payload.command] ?? null;\n        }else if (\"state_l2\" in msg.payload){\n            msg2.payload.state_l2=toggle[msg.payload.command] ?? null;\n        }else if (\"state_l3\" in msg.payload){\n            msg2.payload.state_l3=toggle[msg.payload.command] ?? null;\n        }else if (\"state_l4\" in msg.payload){\n            msg2.payload.state_l4=toggle[msg.payload.command] ?? null;\n        }else if (\"state_l5\" in msg.payload){\n            msg2.payload.state_l5=toggle[msg.payload.command] ?? null;\n        }else if (\"command\" in msg){\n            msg2.command=toggle[msg.payload.command] ?? null;\n        }\n    messages[1]=msg2;\n    }\n}\n\nreturn messages;","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":170,"y":100,"wires":[["fdc198c8e7ebe137"],["b8027df6a0358258"]]},{"id":"fdc198c8e7ebe137","type":"delay","z":"405b554ae2b18a0c","name":"delay","pauseType":"delayv","timeout":"0","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":310,"y":75,"wires":[[]]},{"id":"b8027df6a0358258","type":"delay","z":"405b554ae2b18a0c","name":"duration","pauseType":"delayv","timeout":"0","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":315,"y":135,"wires":[[]]},{"id":"7c9a43c75a8b561e","type":"subflow","name":"echodispatch","info":"","category":"","in":[{"x":200,"y":160,"wires":[{"id":"53b566b98c4c7ee3"}]}],"out":[{"x":940,"y":160,"wires":[{"id":"792fd2603bfbacb4","port":0},{"id":"1f25b31de744cb75","port":0},{"id":"3fdc295d54afc7eb","port":0},{"id":"fed05e07cf397247","port":0},{"id":"3044c45efb375bf8","port":0}]}],"env":[],"meta":{},"color":"#DDAA99"},{"id":"53b566b98c4c7ee3","type":"switch","z":"7c9a43c75a8b561e","name":"DISPATCH BY ECHOROOM ATTRIB","property":"payload.echoroom","propertyType":"msg","rules":[{"t":"eq","v":"salotto","vt":"str"},{"t":"eq","v":"letto","vt":"str"},{"t":"eq","v":"iacopo","vt":"str"},{"t":"eq","v":"cucina","vt":"str"},{"t":"eq","v":"all","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":430,"y":160,"wires":[["792fd2603bfbacb4"],["1f25b31de744cb75"],["3fdc295d54afc7eb"],["fed05e07cf397247"],["3044c45efb375bf8"]]},{"id":"fed05e07cf397247","type":"alexa-remote-routine","z":"7c9a43c75a8b561e","name":"ECHO CUCINA","account":"43e3d520acb8e4da","routineNode":{"type":"speak","payload":{"type":"regular","text":{"type":"msg","value":"payload.text"},"devices":["G070RQ1383750U0F"]}},"x":740,"y":200,"wires":[[]]},{"id":"792fd2603bfbacb4","type":"alexa-remote-routine","z":"7c9a43c75a8b561e","name":"ECHO SALOTTO","account":"43e3d520acb8e4da","routineNode":{"type":"speak","payload":{"type":"regular","text":{"type":"msg","value":"payload.text"},"devices":["G2A1A603046409EF"]}},"x":750,"y":80,"wires":[[]]},{"id":"1f25b31de744cb75","type":"alexa-remote-routine","z":"7c9a43c75a8b561e","name":"ECHO LETTO","account":"43e3d520acb8e4da","routineNode":{"type":"speak","payload":{"type":"regular","text":{"type":"msg","value":"payload.text"},"devices":["G090P308817202WQ"]}},"x":740,"y":120,"wires":[[]]},{"id":"3fdc295d54afc7eb","type":"alexa-remote-routine","z":"7c9a43c75a8b561e","name":"ECHO IACOPO","account":"43e3d520acb8e4da","routineNode":{"type":"speak","payload":{"type":"regular","text":{"type":"msg","value":"payload.text"},"devices":["G090U509915108N8"]}},"x":740,"y":160,"wires":[[]]},{"id":"3044c45efb375bf8","type":"alexa-remote-routine","z":"7c9a43c75a8b561e","name":"ALL ECHOES","account":"43e3d520acb8e4da","routineNode":{"type":"speak","payload":{"type":"regular","text":{"type":"msg","value":"payload.text"},"devices":["c63676a598fc4bea933f537344a0cd64"]}},"x":740,"y":240,"wires":[[]]},{"id":"3621caaf27071cb3","type":"tab","label":"ALEXA V2","disabled":false,"info":"","env":[]},{"id":"bf8470b4e2cbb6ea","type":"group","z":"3621caaf27071cb3","name":"SET TEMPERATURE GLOBAL VARIABLES","style":{"label":true,"fill":"#ffffbf","fill-opacity":"0.4"},"nodes":["d3438956b0435574","ab19925ceba7371c","2cc8814ec9e44c12","64fcebebc13337a9","2d7185495ee154a5","da4c4b801554b181","a4242963f9d57b32","9a85792e16e1ebd8","74fa596ab17664dd","81d3644af6e2b8d2","97ea89da07edf407","d1155173e1c433ac","e4470e2756b33cfe","891f623b2655a6b1"],"x":994,"y":99,"w":392,"h":322},{"id":"5e83e55563514106","type":"group","z":"3621caaf27071cb3","name":"REQUIREMENTS","style":{"label":true},"nodes":["2b442d64865ed992","7d33fcbbbc19d73c","ab3045c0b9ae2aee","6ef273c94e310a23"],"x":634,"y":99,"w":332,"h":202},{"id":"88963da3a19d59ec","type":"group","z":"3621caaf27071cb3","name":"ROOMS","style":{"label":true},"nodes":["b5549676840cf84b","bf084ae92e46fc2c","fada52c9eb5cb206","d18676e6d051d107","96a711f265668f37","416fd876895e7ab6","e6db0c817bac695f","1feb5cb0161165e9","efe169ca58f23995","4cc442a91b307983","8384bebe487fd675","8a7612ce8ae429a7"],"x":1474,"y":161.5,"w":312,"h":939.5},{"id":"f7bfdd52a4ebf8c1","type":"junction","z":"3621caaf27071cb3","x":1880,"y":320,"wires":[["1b12c2ed3cea6074"]]},{"id":"aaf7073163b4a053","type":"junction","z":"3621caaf27071cb3","x":1880,"y":540,"wires":[["934e95fad8754deb"]]},{"id":"1d715f1bd8ec6ef2","type":"junction","z":"3621caaf27071cb3","x":1880,"y":620,"wires":[["16607394678c0075"]]},{"id":"e68e3105111b5b89","type":"junction","z":"3621caaf27071cb3","x":1880,"y":820,"wires":[["9ad8b0898a1efbd0"]]},{"id":"4eef4ab745610907","type":"junction","z":"3621caaf27071cb3","x":1880,"y":900,"wires":[["d565111257df36f9"]]},{"id":"f471de663f05f17e","type":"junction","z":"3621caaf27071cb3","x":1880,"y":1020,"wires":[["3fd1e2ac75cdbc83"]]},{"id":"8a7612ce8ae429a7","type":"junction","z":"3621caaf27071cb3","g":"88963da3a19d59ec","x":1500,"y":640,"wires":[["bf084ae92e46fc2c","fada52c9eb5cb206","b5549676840cf84b","d18676e6d051d107","96a711f265668f37","efe169ca58f23995","4cc442a91b307983","416fd876895e7ab6","e6db0c817bac695f","1feb5cb0161165e9","8384bebe487fd675"]]},{"id":"9d04c1a4e4012ccf","type":"function","z":"3621caaf27071cb3","name":"A - ECHO INFO & PARSING","func":"cmd={};\ncmd[\"accendi\"]=\"on\";\ncmd[\"spegni\"]=\"off\";\ncmd[\"apri\"]=\"on\";\ncmd[\"chiudi\"]=\"off\";\ncmd[\"appiccia\"]=\"on\";\ncmd[\"stuta\"]=\"off\";\ncmd[\"temperatura\"]=\"temperatura\";\n\nrooms={};\nrooms[\"salotto\"]=\"salotto\";\nrooms[\"cucina\"]=\"cucina\";\nrooms[\"jacopo\"]=\"jacopo\";\nrooms[\"letto\"]=\"letto\";\nrooms[\"stanzino\"]=\"stanzino\";\nrooms[\"ingresso\"]=\"ingresso\";\nrooms[\"corridoio\"]=\"corridoio\";\nrooms[\"doccia\"]=\"doccia\";\nrooms[\"bagno\"]=\"bagno\";\nrooms[\"matteo\"]=\"matteo\";\nrooms[\"terrazzo\"]=\"terrazzo\";\nrooms[\"armadio\"]=\"corridoio\";\n\nsyn={};\nsyn[\"sinistra\"]=\"sinistro\";\nsyn[\"salone\"]=\"salotto\";\nsyn[\"chiudi\"]=\"spegni\";\nsyn[\"destra\"]=\"destro\";\nsyn[\"muro\"]=\"applique\";\nsyn[\"divano\"]=\"applique\";\nsyn[\"televisore\"]=\"televisione\";\nsyn[\"tele\"]=\"televisione\";\nsyn[\"tv\"]=\"televisione\";\nsyn[\"terrazza\"]=\"terrazzo\";\nsyn[\"esterna\"]=\"terrazzo\";\n\nmsg1={payload:{summary:\"\",echoroom:\"\",echoid:\"\",command:\"\",deviceid:\"\",deviceroom:\"\",delaylist:{},durationlist:{}}};\nmsg2={payload:{summary:\"\",echoroom:\"\",echoid:\"\",command:\"\",deviceid:\"\",deviceroom:\"\",delaylist:{},durationlist:{}}};\nmsg3={payload:{summary:\"\",echoroom:\"\",echoid:\"\",command:\"\",deviceid:\"\",deviceroom:\"\",delaylist:{},durationlist:{}}};\nconst messages = new Array(node.outputCount)\n\nstopwords=/\\b(il|lo|la|i|gli|le|del|della|dello|in|nello|nel|di|un|una)\\b\\s*/gi;  \nmsg.payload.description.summary=msg.payload.description.summary.replace(stopwords,\"\").trim();\n\nif (msg.payload.data.utteranceType != \"DEVICE_ARBITRATION\" && msg.payload.data.utteranceType !=null){\n\n    msg1.payload.summary = msg.payload.description.summary;\n    msg2.payload.summary = msg.payload.description.summary;\n\n    ms1=/^(\\w+)\\s*(\\w+)\\s*(\\w+)*$/\n    m = msg1.payload.summary.match(ms1);\n    \n    if (msg.payload.deviceSerialNumber == \"<echo serial number>\"){\n        msg1.payload.echoroom=\"salotto\";\n        msg1.payload.echoid=\"<echo serial number>\";\n    }else if (msg.payload.deviceSerialNumber == \"<echo serial number>\"){\n        msg1.payload.echoroom=\"cucina\";\n        msg1.payload.echoid=\"<echo serial number>\";\n    }else if (msg.payload.deviceSerialNumber == \"<echo serial number>\"){\n        msg1.payload.echoroom=\"iacopo\";\n        msg1.payload.echoid=\"<echo serial number>\";\n    }else if (msg.payload.deviceSerialNumber == \"<echo serial number>\"){\n        msg1.payload.echoroom=\"letto\";\n        msg1.payload.echoid=\"<echo serial number>\";\n    }else{\n        msg1.payload=\"Ricevuta richiesta da device Echo non identificato \"+msg.payload.deviceSerialNumber;\n        messages[3]=msg1;\n        return messages;\n    }\n    \n    //A - IT IS A COMMAND? \n    if (msg.payload.data.domain==\"HomeAutomation\" || m[1] in cmd){\n        \n        m[2] = (m[2] in syn) ? syn[m[2]] : m[2];\n\n        msg1.payload.command=(m[1] in cmd) ? cmd[m[1]] : m[1];\n        if (msg1.payload.command==null){\n            msg2.payload.text=\"Non capisco cosa vuol dire \"+m[1];\n            messages[2]=msg2;\n            return messages;\n        }else{\n            // COMMANDS WITHOUT ROOMS AND DEVICES (PLAIN COMMANDS)\n            // alexa filters this type of voice interaction!\n            if (m[2]==null){\n                if (m[1] in cmd){\n                    msg1.payload.deviceroom=msg.payload.echoroom;\n                    msg1.payload.deviceid=\"all\";\n                    msg1.payload.command=cmd[m[1]];\n                    messages[0]=msg1;\n                }\n            // COMMANDS WITH IMPLICIT/EXPLICIT ROOMS OR DEVICES m[3]!=null\n            }else if (m[3]==null){\n                //e.g. accendi salotto (explicit room, implicit device)\n                if (m[2] in rooms){\n                    msg1.payload.deviceroom=rooms[m[2]];\n                    msg1.payload.deviceid=\"all\";\n                    messages[0]=msg1;\n                //e.g accendi tutto (implicit room, implicit device)\n                }else if (m[2]==\"tutto\"){\n                    msg1.payload.deviceroom=msg1.payload.echoroom;\n                    msg1.payload.deviceid=\"all\";\n                    messages[0]=msg1;\n                //e.g. accendi tavolo (implicit room, explicit device)\n                }else{\n                    msg1.payload.deviceroom=msg1.payload.echoroom;\n                    msg1.payload.deviceid=m[2];\n                    messages[0]=msg1;\n                }\n                //COMMAND \"TEMPERATURE ROOM\"\n                if (msg1.payload.command==\"temperatura\"){\n                    if (m[2] in rooms){\n                        msg1.payload.deviceid=m[2];\n                        messages[0]=msg1;\n                    }\n                }\n            // COMMANDS WITH EXPLICIT ROOMS AND DEVICES m[3]!=null)\n            }else{\n                msg1.payload.deviceroom = m[3];\n                msg1.payload.deviceid = m[2];\n                messages[0]=msg1;\n            }\n        }  \n    \n    //B - ELSE IT IS A ROUTINE\n    }else if(msg.payload.data.domain==\"Routines\"){\n        msg1.payload.command=\"routine\";\n        messages[1]=msg1;\n\n    //C - UNMANAGED TYPE\n    }else{\n        return;\n    }\n    return messages;\n}\n","outputs":4,"noerr":0,"initialize":"","finalize":"","libs":[],"x":660,"y":640,"wires":[["3b9c67b816e2f1d0","6d21d7ae9d527025"],["69255428f8037b1b"],["37f7c1b0a5f41ddf"],["282bddce3cf82765"]]},{"id":"9d49351b207fbe06","type":"alexa-remote-event","z":"3621caaf27071cb3","name":"","account":"43e3d520acb8e4da","event":"ws-device-activity","x":375,"y":640,"wires":[["9d04c1a4e4012ccf","1cdc78b4b7d89660"]]},{"id":"3b9c67b816e2f1d0","type":"switch","z":"3621caaf27071cb3","name":"C - DISPATCH BY DEVICEROOM","property":"payload.deviceroom","propertyType":"msg","rules":[{"t":"eq","v":"salotto","vt":"str"},{"t":"eq","v":"cucina","vt":"str"},{"t":"eq","v":"letto","vt":"str"},{"t":"eq","v":"jacopo","vt":"str"},{"t":"eq","v":"ingresso","vt":"str"},{"t":"eq","v":"stanzino","vt":"str"},{"t":"eq","v":"corridoio","vt":"str"},{"t":"eq","v":"doccia","vt":"str"},{"t":"eq","v":"bagno","vt":"str"},{"t":"eq","v":"matteo","vt":"str"},{"t":"eq","v":"terrazzo","vt":"str"},{"t":"eq","v":"all","vt":"str"}],"checkall":"true","repair":false,"outputs":12,"x":1220,"y":620,"wires":[["bf084ae92e46fc2c"],["fada52c9eb5cb206"],["b5549676840cf84b"],["d18676e6d051d107"],["96a711f265668f37"],["efe169ca58f23995"],["4cc442a91b307983"],["416fd876895e7ab6"],["e6db0c817bac695f"],["1feb5cb0161165e9"],["8384bebe487fd675"],["8a7612ce8ae429a7"]]},{"id":"b5549676840cf84b","type":"function","z":"3621caaf27071cb3","g":"88963da3a19d59ec","name":"LETTO","func":"var msg1 = JSON.parse(JSON.stringify(msg));\nvar msg2 = JSON.parse(JSON.stringify(msg));\nvar msg3 = JSON.parse(JSON.stringify(msg));\nconst messages = new Array(node.outputCount)\n\nif (msg.payload.summary!=\"\"){\n\n    if (msg.payload.deviceid==\"luce\"){\n        msg1.delay   = msg.payload.delaylist[\"luce\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"luce\"] ?? 0;\n        msg1.payload.turn = msg.payload.command;\n        msg1.payload.relay = 0;\n        messages[0] = msg1;\n\n    }else if(msg.payload.deviceid==\"comodino\"){\n        msg1.delay   = msg.payload.delaylist[\"comodino\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"comodino\"] ?? 0;\n        msg1.payload.state = msg.payload.command;\n        messages[1] = msg1;\n\n    }else if(msg.payload.deviceid==\"all\"){\n        \n        msg1.delay   = msg.payload.delaylist[\"luce\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"luce\"] ?? 0;\n        msg1.payload.turn = msg.payload.command;\n        msg1.payload.relay = 0;\n        messages[0] = msg1;\n\n        msg2.delay   = msg.payload.delaylist[\"comodino\"] ?? 0;\n        msg2.duration= msg.payload.durationlist[\"comodino\"] ?? 0;\n        msg2.payload={\"state\":msg.payload.command};\n        messages[1] = msg2;\n\n    }else if(msg.payload.command==\"temperatura\"){\n        messages[2] = msg;\n    }\n    return messages;\n}\n","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1680,"y":500,"wires":[["a37e2932ed788527"],["9e1811a7bbe85d78"],["aaf7073163b4a053"]]},{"id":"bf084ae92e46fc2c","type":"function","z":"3621caaf27071cb3","g":"88963da3a19d59ec","name":"SALOTTO","func":"var msg1 = JSON.parse(JSON.stringify(msg));\nvar msg2 = JSON.parse(JSON.stringify(msg));\nvar msg3 = JSON.parse(JSON.stringify(msg));\nvar msg4 = JSON.parse(JSON.stringify(msg));\nvar msg5 = JSON.parse(JSON.stringify(msg));\nvar msg6 = JSON.parse(JSON.stringify(msg));\nvar msg6 = JSON.parse(JSON.stringify(msg));\nvar msg7 = JSON.parse(JSON.stringify(msg));\nvar msg8 = JSON.parse(JSON.stringify(msg));\n\nconst messages = new Array(node.outputCount)\n\nif (msg.payload.summary!=\"\"){\n    \n    if (msg.payload.deviceid==\"tavolo\"){\n        msg1.delay   = msg.payload.delaylist[\"tavolo\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"tavolo\"] ?? 0;\n        msg1.payload.turn = msg.payload.command;\n        msg1.payload.relay = 0;\n        messages[0] = msg1;\n\n    }else if(msg.payload.deviceid==\"lampada\"){\n        msg1.delay   = msg.payload.delaylist[\"lampada\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"lampada\"] ?? 0;\n        msg1.payload={\"state\":msg.payload.command};\n        messages[1] = msg1;\n    \n    }else if (msg.payload.deviceid==\"muro\"  || msg.payload.deviceid==\"applique\" || msg.payload.deviceid==\"divano\"){\n        msg1.delay   = msg.payload.delaylist[\"muro\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"muro\"] ?? 0;\n        msg1.payload.turn = msg.payload.command;\n        msg1.payload.relay = 0;\n        messages[2] = msg1;\n\n        msg2.delay   = msg.payload.delaylist[\"muro\"] ?? 0;\n        msg2.duration= msg.payload.durationlist[\"muro\"] ?? 0;\n        msg2.payload.turn = msg.payload.command;\n        msg2.payload.relay = 1;\n        messages[3] = msg2;\n\n    }else if(msg.payload.deviceid==\"destro\"){\n        msg1.delay   = msg.payload.delaylist[\"destro\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"destro\"] ?? 0;\n        msg1.payload.turn = msg.payload.command;\n        msg1.payload.relay = 0;\n        messages[2] = msg1;\n        \n    }else if(msg.payload.deviceid==\"televisione\"){\n        msg1.delay   = msg.payload.delaylist[\"televisione\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"televisione\"] ?? 0;\n        msg1.command = msg.payload.command;\n        msg1.payload.state_l2 = msg.payload.command;\n        messages[4] = msg1;\n\n    }else if(msg.payload.deviceid==\"console\"){\n        msg1.delay   = msg.payload.delaylist[\"console\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"console\"] ?? 0;\n        msg1.command = msg.payload.command;\n        msg1.payload.state_l3 = msg.payload.command;\n        messages[4] = msg1;\n\n    }else if(msg.payload.deviceid==\"amplificatore\"){\n        msg1.delay   = msg.payload.delaylist[\"amplificatore\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"amplificatore\"] ?? 0;\n        msg1.command = msg.payload.command;\n        msg1.payload.state_l4 = msg.payload.command;\n        messages[4] = msg1;\n        \n    }else if(msg.payload.deviceid==\"sinistro\"){\n        msg1.delay   = msg.payload.delaylist[\"sinistro\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"sinistro\"] ?? 0;\n        msg1.payload.turn = msg.payload.command;\n        msg1.payload.relay = 1;\n        messages[3] = msg1;\n\n    }else if(msg.payload.deviceid==\"all\"){\n        //tavolo\n        msg1.delay   = msg.payload.delaylist[\"tavolo\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"tavolo\"] ?? 0;\n        msg1.payload.turn = msg.payload.command;\n        msg1.payload.relay = 0;\n        messages[0] = msg1;\n        //lampada\n        msg2.delay   = msg.payload.delaylist[\"lampada\"] ?? 0;\n        msg2.duration= msg.payload.durationlist[\"lampada\"] ?? 0;\n        msg2.payload.state = msg.payload.command;\n        messages[1] = msg2;\n        //muro\n        msg3.delay   = msg.payload.delaylist[\"destro\"] ?? 0;\n        msg3.duration= msg.payload.durationlist[\"destro\"] ?? 0;\n        msg3.payload.turn = msg.payload.command;\n        msg3.payload.relay = 0;\n        msg4.delay   = msg.payload.delaylist[\"sinistro\"] ?? 0;\n        msg4.duration= msg.payload.durationlist[\"sinistro\"] ?? 0;\n        msg4.payload.turn = msg.payload.command;\n        msg4.payload.relay = 1;\n        messages[2] = [msg3,msg4];\n        //powerstrip endpoints:\n        //1-empty socket\n        msg5.delay   = msg.payload.delaylist[\"libero\"] ?? 0;\n        msg5.duration= msg.payload.durationlist[\"libero\"] ?? 0;\n        msg5.command = msg.payload.command;\n        msg5.payload.state_l1 = msg.payload.command;\n        //2-televisione\n        msg6.delay   = msg.payload.delaylist[\"televisione\"] ?? 0;\n        msg6.duration= msg.payload.durationlist[\"televisione\"] ?? 0;\n        msg6.command = msg.payload.command;\n        msg6.payload.state_l2 = msg.payload.command;\n        //3-console\n        msg7.delay   = msg.payload.delaylist[\"console\"] ?? 0;\n        msg7.duration= msg.payload.durationlist[\"console\"] ?? 0;\n        msg7.command = msg.payload.command;\n        msg7.payload.state_l3 = msg.payload.command;\n        //4-amplificatore\n        msg8.delay   = msg.payload.delaylist[\"amplificatore\"] ?? 0;\n        msg8.duration= msg.payload.durationlist[\"amplificatore\"] ?? 0;\n        msg8.command = msg.payload.command;\n        msg8.payload.state_l4 = msg.payload.command;\n        messages[4] = [msg5,msg6,msg7,msg8];\n        //@what's about luce balcone?\n\n    }else if(msg.payload.command==\"temperatura\"){\n        messages[5] = msg1;\n\n    }else if(msg.payload.deviceid==\"balcone\"){\n        msg1.delay   = msg.payload.delaylist[\"balcone\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"balcone\"] ?? 0;\n        msg1.payload={\"state\":msg.payload.command};\n        messages[6] = msg1;\n\n    }\n    return messages;\n}","outputs":7,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1690,"y":240,"wires":[["338ad4fc67f1704a"],["1a068b58737ae119"],["2d7b024314758333"],[],["0cee8ed79289b223"],["f7bfdd52a4ebf8c1"],["1b7f0d6bedf07b2d"]]},{"id":"fada52c9eb5cb206","type":"function","z":"3621caaf27071cb3","g":"88963da3a19d59ec","name":"CUCINA","func":"var msg1 = JSON.parse(JSON.stringify(msg));\nconst\nmessages = new Array(node.outputCount)\n\nif (msg.payload.summary!=\"\"){\n    if (msg.payload.deviceid==\"luce\" || msg.payload.deviceid==\"all\"){\n        msg1.delay   = msg.payload.delaylist[\"luce\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"luce\"] ?? 0;\n        msg1.payload={\"state\":msg.payload.command};\n        messages[0] = msg1;\n    }\n    return messages;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1680,"y":420,"wires":[["28d226ba4769df53"]]},{"id":"d18676e6d051d107","type":"function","z":"3621caaf27071cb3","g":"88963da3a19d59ec","name":"IACOPO","func":"var msg1 = JSON.parse(JSON.stringify(msg));\nvar msg2 = JSON.parse(JSON.stringify(msg));\nconst messages = new Array(node.outputCount)\n\nif (msg.payload.summary!=\"\"){\n    if (msg.payload.deviceid==\"luce\" || msg.payload.deviceid==\"all\"){\n        msg1.delay   = msg.payload.delaylist[\"luce\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"luce\"] ?? 0;\n        msg1.payload.turn = msg.payload.command;\n        msg1.payload.relay = 0;\n        messages[0] = msg1;\n    }else if(msg.payload.command==\"temperatura\"){\n        messages[1] = msg2;\n    }\n    return messages;\n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1680,"y":600,"wires":[["738cbb8294f0cd39"],["1d715f1bd8ec6ef2"]]},{"id":"96a711f265668f37","type":"function","z":"3621caaf27071cb3","g":"88963da3a19d59ec","name":"INGRESSO","func":"var msg1 = JSON.parse(JSON.stringify(msg));\nconst messages = new Array(node.outputCount)\n\nif (msg.payload.summary!=\"\"){\n    if (msg.payload.deviceid==\"luce\" || msg.payload.deviceid==\"all\"){\n        msg1.delay   = msg.payload.delaylist[\"luce\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"luce\"] ?? 0;\n        msg1.payload.turn = msg.payload.command;\n        msg1.payload.relay = 0;\n        messages[0] = msg1;\n    }\n}\nreturn messages;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1690,"y":660,"wires":[["710a43c962318524"]]},{"id":"416fd876895e7ab6","type":"function","z":"3621caaf27071cb3","g":"88963da3a19d59ec","name":"DOCCIA","func":"var msg1 = JSON.parse(JSON.stringify(msg));\nvar msg2 = JSON.parse(JSON.stringify(msg));\nvar msg3 = JSON.parse(JSON.stringify(msg));\nconst messages = new Array(node.outputCount)\n\nif (msg.payload.summary!=\"\"){\n    if (msg.payload.deviceid==\"luce\"){\n        msg1.delay   = msg.payload.delaylist[\"luce\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"luce\"] ?? 0;\n        msg1.payload.turn = msg.payload.command;\n        msg1.payload.relay = 1;\n        messages[0] = msg1;\n    }else if(msg.payload.deviceid==\"specchio\"){\n        msg2.delay   = msg.payload.delaylist[\"specchio\"] ?? 0;\n        msg2.duration= msg.payload.durationlist[\"specchio\"] ?? 0;\n        msg2.payload.turn = msg.payload.command;\n        msg2.payload.relay = 0;\n        messages[0] = msg2;\n    }else if(msg.payload.deviceid==\"all\"){\n        msg1.delay   = msg.payload.delaylist[\"luce\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"luce\"] ?? 0;\n        msg1.payload.turn = msg.payload.command;\n        msg1.payload.relay = 1;\n        messages[0] = [msg1,msg2];\n\n        msg2.delay   = msg.payload.delaylist[\"specchio\"] ?? 0;\n        msg2.duration= msg.payload.durationlist[\"specchio\"] ?? 0;\n        msg2.payload.turn = msg.payload.command;\n        msg2.payload.relay = 0;\n\n        messages[0] = [msg1,msg2];\n    }else if(msg.payload.command==\"temperatura\"){\n        messages[1] = msg;\n    }\n    return messages;\n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1680,"y":880,"wires":[["53b38737e5aaac54"],["4eef4ab745610907"]]},{"id":"e6db0c817bac695f","type":"function","z":"3621caaf27071cb3","g":"88963da3a19d59ec","name":"BAGNO","func":"var msg1 = JSON.parse(JSON.stringify(msg));\nvar msg2 = JSON.parse(JSON.stringify(msg));\nconst messages = new Array(node.outputCount)\n\nif (msg.payload.summary!=\"\"){\n    if (msg.payload.deviceid==\"luce\"){\n        msg1.delay   = msg.payload.delaylist[\"luce\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"luce\"] ?? 0;\n        msg1.payload.turn = msg.payload.command;\n        msg1.payload.relay = 0;\n        messages[0] = msg1;\n    }else if(msg.payload.deviceid==\"specchio\"){\n        msg1.delay   = msg.payload.delaylist[\"specchio\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"specchio\"] ?? 0;\n        msg1.payload.turn = msg.payload.command;\n        msg1.payload.relay = 1;\n        messages[0] = msg1;\n    }else if(msg.payload.deviceid==\"all\"){\n        msg1.delay   = msg.payload.delaylist[\"luce\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"luce\"] ?? 0;\n        msg1.payload.turn = msg.payload.command;\n        msg1.payload.relay = 0;\n        //\n        msg2.delay   = msg.payload.delaylist[\"specchio\"] ?? 0;\n        msg2.duration= msg.payload.durationlist[\"specchio\"] ?? 0;\n        msg2.payload.turn = msg.payload.command;\n        msg2.payload.relay = 1;\n\n        messages[0] = [msg1,msg2];\n    }\n}\nreturn messages;","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1680,"y":940,"wires":[["a93c4e075c57780b"],[]]},{"id":"1feb5cb0161165e9","type":"function","z":"3621caaf27071cb3","g":"88963da3a19d59ec","name":"MATTEO","func":"var msg1 = JSON.parse(JSON.stringify(msg));\nconst messages = new Array(node.outputCount)\n\nif (msg.payload.summary!=\"\"){\n    if (msg.payload.deviceid==\"luce\" || msg.payload.deviceid==\"all\"){\n        msg1.delay   = msg.payload.delaylist[\"luce\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"luce\"] ?? 0;\n        msg1.payload.turn = msg.payload.command;\n        msg1.payload.relay = 0;\n        messages[0] = msg1;\n    }else if(msg.payload.command==\"temperatura\"){\n        messages[1] = msg;\n    }\n}\nreturn messages;","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1680,"y":1000,"wires":[["f0bd3852d6db9385"],["f471de663f05f17e"]]},{"id":"efe169ca58f23995","type":"function","z":"3621caaf27071cb3","g":"88963da3a19d59ec","name":"STANZINO","func":"var msg1 = JSON.parse(JSON.stringify(msg));\nconst messages = new Array(node.outputCount)\n\nif (msg.payload.summary!=\"\"){\n    if (msg.payload.deviceid==\"luce\" || msg.payload.deviceid==\"all\"){\n        msg1.delay   = msg.payload.delaylist[\"luce\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"luce\"] ?? 0;\n        msg1.payload.turn = msg.payload.command;\n        msg1.payload.relay = 0;\n        messages[0] = msg1;\n    }\n}\nreturn messages;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1690,"y":700,"wires":[["e6064d71707de868"]]},{"id":"4cc442a91b307983","type":"function","z":"3621caaf27071cb3","g":"88963da3a19d59ec","name":"CORRIDOIO","func":"var msg1 = JSON.parse(JSON.stringify(msg));\nvar msg2 = JSON.parse(JSON.stringify(msg));\nvar msg3 = JSON.parse(JSON.stringify(msg));\nconst messages = new Array(node.outputCount)\n\nif (msg.payload.summary!=\"\"){\n    if (msg.payload.deviceid==\"luce\" || msg.payload.deviceid==\"all\"){\n\n        msg1.payload.turn = msg.payload.command;\n        msg1.payload.relay=0;\n        msg1.delay   = msg.payload.delaylist[\"corridoio\"] ?? 0;\n        msg1.duration= msg.payload.durationlist[\"corridoio\"] ?? 0;\n\n        msg2.payload.turn = msg.payload.command;\n        msg2.payload.relay=0;\n        msg2.delay   = msg.payload.delaylist[\"corridoio\"] ?? 0;\n        msg2.duration= msg.payload.durationlist[\"corridoio\"] ?? 0;\n        messages[0]=msg1;\n        messages[1]=msg2;\n    }else if(msg.payload.command==\"temperatura\"){\n        msg3.payload.deviceroom='armadio'\n        messages[2]=msg3;\n    }\n    return messages;\n}","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1690,"y":780,"wires":[["8bca1fc5eb44e276"],["d5bf74e6418a2e27"],["e68e3105111b5b89"]]},{"id":"69255428f8037b1b","type":"function","z":"3621caaf27071cb3","name":"B - ROUTINES","func":"var msg1 = JSON.parse(JSON.stringify(msg));\nconst messages = new Array(node.outputCount)\n\nif (msg.payload.summary!=\"\"){\n    \n    if (msg.payload.summary==\"buonanotte\"){\n\n        msg1.payload.command=\"off\";\n        msg1.payload.deviceroom=\"salotto\";\n        msg1.payload.deviceid=\"all\";\n        msg1.payload.delaylist={\"lampada\":20000};\n//        msg1.payload.durationlist={};\n\n        msg2.payload.command=\"on\";\n        msg2.payload.deviceroom=\"corridoio\";\n        messages[0]=[msg1];\n        msg2.payload.deviceid=\"all\";\n        msg2.payload.text=\"\";\n//        msg2.payload.delaylist={};\n        msg2.payload.durationlist={\"corridoio\":40000};\n        messages[0]=[msg1,msg2];\n\n        msg3.payload.text=\"Spengo la lampada tra 20 secondi. Ho acceso il corridoio\"\n        messages[1]=msg3;\n\n    }else if (msg.payload.summary==\"spegni casa\"){\n        msg1.payload.command=\"off\";\n        msg1.payload.deviceroom=\"all\";\n        msg1.payload.deviceid=\"all\";\n        msg1.payload.text=\"Ho spento tutte le luci di casa. Arrivederci.\"\n        messages[0]=[msg1];\n\n    }else if (msg.payload.summary==\"accendi muro\"){\n        msg1.payload.command=\"on\";\n        msg1.payload.deviceroom=\"salotto\";\n        msg1.payload.deviceid=\"muro\";\n//        msg1.payload.delaylist={};\n//        msg1.payload.durationlist={};\n        messages[0]=[msg1];\n\n    }else if (msg.payload.summary==\"prepara televisione\"){\n        msg1.payload.command=\"on\";\n        msg1.payload.deviceroom=\"salotto\";\n        msg1.payload.deviceid=\"televisione\";\n//        msg1.payload.delaylist={};\n//        msg1.payload.durationlist={};\n        messages[0]=[msg1];\n\n    } else{\n        msg1.payload.text=\"Routine sconosciuta \"+msg1.payload.summary;\n        messages[1]=msg1;\n    }\n    return messages;\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":940,"y":700,"wires":[["3b9c67b816e2f1d0","4433d4e656100b49"],["9b9fc4543acf0d38"]]},{"id":"6d21d7ae9d527025","type":"debug","z":"3621caaf27071cb3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":910,"y":500,"wires":[]},{"id":"27e7e08338adc491","type":"catch","z":"3621caaf27071cb3","name":"","scope":["9d04c1a4e4012ccf"],"uncaught":false,"x":330,"y":720,"wires":[["f417d5d76b12b98a"]]},{"id":"f417d5d76b12b98a","type":"debug","z":"3621caaf27071cb3","name":"debug 5","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":500,"y":720,"wires":[]},{"id":"e8e72877cc5129d4","type":"vsh-virtual-device","z":"3621caaf27071cb3","name":"lampada","topic":"test","connection":"6b19ce663089c7f6","template":"SWITCH","passthrough":false,"diff":false,"filter":false,"filterTopic":false,"x":400,"y":1120,"wires":[[]]},{"id":"00c81879d75a041d","type":"vsh-virtual-device","z":"3621caaf27071cb3","name":"tavolo","topic":"test","connection":"6b19ce663089c7f6","template":"SWITCH","passthrough":false,"diff":false,"filter":false,"filterTopic":false,"x":530,"y":1120,"wires":[[]]},{"id":"3ab5e9f78f978c2b","type":"vsh-virtual-device","z":"3621caaf27071cb3","name":"sinistro","topic":"test","connection":"6b19ce663089c7f6","template":"SWITCH","passthrough":false,"diff":false,"filter":false,"filterTopic":false,"x":780,"y":1120,"wires":[[]]},{"id":"db7656107824c0ca","type":"vsh-virtual-device","z":"3621caaf27071cb3","name":"destro","topic":"test","connection":"6b19ce663089c7f6","template":"SWITCH","passthrough":false,"diff":false,"filter":false,"filterTopic":false,"x":650,"y":1120,"wires":[[]]},{"id":"5e4f4ab55c2e9013","type":"vsh-virtual-device","z":"3621caaf27071cb3","name":"doccia","topic":"test","connection":"6b19ce663089c7f6","template":"SWITCH","passthrough":false,"diff":false,"filter":false,"filterTopic":false,"x":1030,"y":1120,"wires":[[]]},{"id":"a52d14f1e592453f","type":"vsh-virtual-device","z":"3621caaf27071cb3","name":"luce","topic":"test","connection":"6b19ce663089c7f6","template":"SWITCH","passthrough":false,"diff":false,"filter":false,"filterTopic":false,"x":270,"y":1120,"wires":[[]]},{"id":"55ef8398b6e865cf","type":"comment","z":"3621caaf27071cb3","name":"ALEXA DEVICE PLACEHOLDERS, TO AVOID ALEXA \"DEVICE NOT FOUND\" MESSAGES","info":"","x":540,"y":1080,"wires":[]},{"id":"d3438956b0435574","type":"zigbee2mqtt-in","z":"3621caaf27071cb3","g":"bf8470b4e2cbb6ea","name":"TH07-TERRAZZO","server":"411e2b8e9bdac70b","friendly_name":"TH07-TERRAZZO (WSDCGQ11LM)","device_id":"0x00158d000418e5b7","state":"0","outputAtStartup":true,"filterChanges":false,"enableMultiple":false,"x":1110,"y":140,"wires":[["2d7185495ee154a5"]]},{"id":"ab19925ceba7371c","type":"zigbee2mqtt-in","z":"3621caaf27071cb3","g":"bf8470b4e2cbb6ea","name":"TH01-LETTO","server":"411e2b8e9bdac70b","friendly_name":"TH01-LETTO (WSDCGQ11LM)","device_id":"0x00158d00025ee652","state":"0","outputAtStartup":true,"filterChanges":false,"enableMultiple":false,"x":1090,"y":180,"wires":[["da4c4b801554b181"]]},{"id":"2cc8814ec9e44c12","type":"zigbee2mqtt-in","z":"3621caaf27071cb3","g":"bf8470b4e2cbb6ea","name":"TH03-SALOTTO","server":"411e2b8e9bdac70b","friendly_name":"TH03-SALOTTO (WSDCGQ11LM)","device_id":"0x00158d0002d7f3b7","state":"0","outputAtStartup":true,"filterChanges":false,"enableMultiple":false,"x":1100,"y":220,"wires":[["a4242963f9d57b32"]]},{"id":"64fcebebc13337a9","type":"zigbee2mqtt-in","z":"3621caaf27071cb3","g":"bf8470b4e2cbb6ea","name":"TH05-ARMADIO","server":"411e2b8e9bdac70b","friendly_name":"TH05-MOBILE (WSDCGQ11LM)","device_id":"0x00158d0003d42986","state":"0","outputAtStartup":true,"filterChanges":false,"enableMultiple":false,"x":1100,"y":260,"wires":[["9a85792e16e1ebd8"]]},{"id":"2d7185495ee154a5","type":"change","z":"3621caaf27071cb3","g":"bf8470b4e2cbb6ea","name":"set global","rules":[{"t":"set","p":"#:(ram)::th-terrazzo","pt":"global","to":"msg.payload","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1300,"y":140,"wires":[[]]},{"id":"da4c4b801554b181","type":"change","z":"3621caaf27071cb3","g":"bf8470b4e2cbb6ea","name":"set global","rules":[{"t":"set","p":"#:(ram)::th-letto","pt":"global","to":"msg.payload","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1300,"y":180,"wires":[[]]},{"id":"a4242963f9d57b32","type":"change","z":"3621caaf27071cb3","g":"bf8470b4e2cbb6ea","name":"set global","rules":[{"t":"set","p":"#:(ram)::th-salotto","pt":"global","to":"msg.payload","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1300,"y":220,"wires":[[]]},{"id":"9a85792e16e1ebd8","type":"change","z":"3621caaf27071cb3","g":"bf8470b4e2cbb6ea","name":"set global","rules":[{"t":"set","p":"#:(ram)::th-armadio","pt":"global","to":"msg.payload","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1300,"y":260,"wires":[[]]},{"id":"74fa596ab17664dd","type":"zigbee2mqtt-in","z":"3621caaf27071cb3","g":"bf8470b4e2cbb6ea","name":"TH02-JACOPO","server":"411e2b8e9bdac70b","friendly_name":"TH02-IACOPO (WSDCGQ11LM)","device_id":"0x00158d0004184d95","state":"0","outputAtStartup":true,"filterChanges":false,"enableMultiple":false,"x":1100,"y":300,"wires":[["81d3644af6e2b8d2"]]},{"id":"81d3644af6e2b8d2","type":"change","z":"3621caaf27071cb3","g":"bf8470b4e2cbb6ea","name":"set global","rules":[{"t":"set","p":"#:(ram)::th-jacopo","pt":"global","to":"msg.payload","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1300,"y":300,"wires":[[]]},{"id":"97ea89da07edf407","type":"zigbee2mqtt-in","z":"3621caaf27071cb3","g":"bf8470b4e2cbb6ea","name":"TH04-MATTEO","server":"411e2b8e9bdac70b","friendly_name":"TH04-MATTEO (WSDCGQ11LM)","device_id":"0x00158d0002d7f31f","state":"0","outputAtStartup":true,"filterChanges":false,"enableMultiple":false,"x":1100,"y":340,"wires":[["d1155173e1c433ac"]]},{"id":"d1155173e1c433ac","type":"change","z":"3621caaf27071cb3","g":"bf8470b4e2cbb6ea","name":"set global","rules":[{"t":"set","p":"#:(ram)::th-matteo","pt":"global","to":"msg.payload","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1300,"y":340,"wires":[[]]},{"id":"e4470e2756b33cfe","type":"change","z":"3621caaf27071cb3","g":"bf8470b4e2cbb6ea","name":"set global","rules":[{"t":"set","p":"#:(ram)::th-doccia","pt":"global","to":"msg.payload","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1300,"y":380,"wires":[[]]},{"id":"891f623b2655a6b1","type":"zigbee2mqtt-in","z":"3621caaf27071cb3","g":"bf8470b4e2cbb6ea","name":"TH06-DOCCIA","server":"411e2b8e9bdac70b","friendly_name":"TH06-DOCCIA (WSDCGQ11LM)","device_id":"0x00158d0002fb4b3e","state":"0","outputAtStartup":true,"filterChanges":false,"enableMultiple":false,"x":1100,"y":380,"wires":[["e4470e2756b33cfe"]]},{"id":"8384bebe487fd675","type":"function","z":"3621caaf27071cb3","g":"88963da3a19d59ec","name":"TERRAZZO","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1690,"y":1060,"wires":[["5ed95a8b7bc69e57"]]},{"id":"1cdc78b4b7d89660","type":"debug","z":"3621caaf27071cb3","name":"debug 6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":600,"y":500,"wires":[]},{"id":"9b9fc4543acf0d38","type":"subflow:7c9a43c75a8b561e","z":"3621caaf27071cb3","name":"","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":1170,"y":780,"wires":[[]]},{"id":"37f7c1b0a5f41ddf","type":"subflow:7c9a43c75a8b561e","z":"3621caaf27071cb3","name":"","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":930,"y":780,"wires":[[]]},{"id":"4433d4e656100b49","type":"debug","z":"3621caaf27071cb3","name":"debug 7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1160,"y":500,"wires":[]},{"id":"282bddce3cf82765","type":"link call","z":"3621caaf27071cb3","name":"","links":["1d07503ca126e626"],"linkType":"static","timeout":"30","x":920,"y":820,"wires":[[]]},{"id":"8bca1fc5eb44e276","type":"subflow:405b554ae2b18a0c","z":"3621caaf27071cb3","name":"","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":1940,"y":740,"wires":[["c6f4f7047a8dc562"],["c6f4f7047a8dc562"]]},{"id":"d5bf74e6418a2e27","type":"subflow:405b554ae2b18a0c","z":"3621caaf27071cb3","name":"","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":1940,"y":780,"wires":[["baad3181cb46dc73"],["baad3181cb46dc73"]]},{"id":"338ad4fc67f1704a","type":"subflow:405b554ae2b18a0c","z":"3621caaf27071cb3","name":"","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":1940,"y":120,"wires":[["7cd923d79b1c617a"],["7cd923d79b1c617a"]]},{"id":"1a068b58737ae119","type":"subflow:405b554ae2b18a0c","z":"3621caaf27071cb3","name":"","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":1940,"y":160,"wires":[["58236775ba922f76"],["58236775ba922f76"]]},{"id":"2d7b024314758333","type":"subflow:405b554ae2b18a0c","z":"3621caaf27071cb3","name":"","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":1940,"y":220,"wires":[["c690887626781754"],["c690887626781754"]]},{"id":"28d226ba4769df53","type":"subflow:405b554ae2b18a0c","z":"3621caaf27071cb3","name":"","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":1940,"y":420,"wires":[["06f6a1ef2428bf33"],["06f6a1ef2428bf33"]]},{"id":"738cbb8294f0cd39","type":"subflow:405b554ae2b18a0c","z":"3621caaf27071cb3","name":"","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":1940,"y":580,"wires":[["096a1d5714d11495"],["096a1d5714d11495"]]},{"id":"710a43c962318524","type":"subflow:405b554ae2b18a0c","z":"3621caaf27071cb3","name":"","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":1940,"y":660,"wires":[["cfc085dc60e968e6"],["cfc085dc60e968e6"]]},{"id":"e6064d71707de868","type":"subflow:405b554ae2b18a0c","z":"3621caaf27071cb3","name":"","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":1940,"y":700,"wires":[["c1f12752126ec237"],["c1f12752126ec237"]]},{"id":"f0bd3852d6db9385","type":"subflow:405b554ae2b18a0c","z":"3621caaf27071cb3","name":"","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":1940,"y":980,"wires":[["2e28027b1a32c7d7"],["2e28027b1a32c7d7"]]},{"id":"a93c4e075c57780b","type":"subflow:405b554ae2b18a0c","z":"3621caaf27071cb3","name":"","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":1940,"y":940,"wires":[["fe8a7052182f4be5"],["fe8a7052182f4be5"]]},{"id":"53b38737e5aaac54","type":"subflow:405b554ae2b18a0c","z":"3621caaf27071cb3","name":"","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":1940,"y":860,"wires":[["1c6510ef5f075b4c"],["1c6510ef5f075b4c"]]},{"id":"a37e2932ed788527","type":"subflow:405b554ae2b18a0c","z":"3621caaf27071cb3","name":"","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":1940,"y":460,"wires":[["a88d2192d4ac5302"],["a88d2192d4ac5302"]]},{"id":"9e1811a7bbe85d78","type":"subflow:405b554ae2b18a0c","z":"3621caaf27071cb3","name":"","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":1940,"y":500,"wires":[["2458fe43909d2c71"],["2458fe43909d2c71"]]},{"id":"0cee8ed79289b223","type":"subflow:405b554ae2b18a0c","z":"3621caaf27071cb3","name":"","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":1940,"y":280,"wires":[["3b9f7c3eb17268ea"],["3b9f7c3eb17268ea"]]},{"id":"1b12c2ed3cea6074","type":"subflow:8612386267fb8ebd","z":"3621caaf27071cb3","name":"","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":2110,"y":320,"wires":[[]]},{"id":"934e95fad8754deb","type":"subflow:8612386267fb8ebd","z":"3621caaf27071cb3","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":2110,"y":540,"wires":[[]]},{"id":"16607394678c0075","type":"subflow:8612386267fb8ebd","z":"3621caaf27071cb3","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":2110,"y":620,"wires":[[]]},{"id":"9ad8b0898a1efbd0","type":"subflow:8612386267fb8ebd","z":"3621caaf27071cb3","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":2110,"y":820,"wires":[[]]},{"id":"d565111257df36f9","type":"subflow:8612386267fb8ebd","z":"3621caaf27071cb3","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":2110,"y":900,"wires":[[]]},{"id":"3fd1e2ac75cdbc83","type":"subflow:8612386267fb8ebd","z":"3621caaf27071cb3","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":2110,"y":1020,"wires":[[]]},{"id":"5ed95a8b7bc69e57","type":"subflow:8612386267fb8ebd","z":"3621caaf27071cb3","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":2110,"y":1060,"wires":[[]]},{"id":"a88d2192d4ac5302","type":"shelly-gen1","z":"3621caaf27071cb3","hostname":"192.168.1.59","description":"luce LETTO","pollinginterval":5000,"pollstatus":false,"getstatusoncommand":true,"devicetype":"Relay","outputs":1,"rgbwmode":"color","x":2110,"y":460,"wires":[[]]},{"id":"7cd923d79b1c617a","type":"shelly-gen1","z":"3621caaf27071cb3","hostname":"192.168.1.56","description":"luce TAVOLO","pollinginterval":5000,"pollstatus":false,"getstatusoncommand":true,"devicetype":"Relay","outputs":1,"rgbwmode":"color","x":2120,"y":120,"wires":[[]]},{"id":"c690887626781754","type":"shelly-gen1","z":"3621caaf27071cb3","hostname":"192.168.1.57","description":"luce MURO","pollinginterval":5000,"pollstatus":false,"getstatusoncommand":true,"devicetype":"Relay","outputs":1,"rgbwmode":"color","x":2110,"y":220,"wires":[[]]},{"id":"096a1d5714d11495","type":"shelly-gen1","z":"3621caaf27071cb3","hostname":"192.168.1.52","description":"luce IACOPO","pollinginterval":5000,"pollstatus":false,"getstatusoncommand":true,"devicetype":"Relay","outputs":1,"rgbwmode":"color","x":2120,"y":580,"wires":[[]]},{"id":"cfc085dc60e968e6","type":"shelly-gen1","z":"3621caaf27071cb3","hostname":"192.168.1.62","description":"luce INGRESSO","pollinginterval":5000,"pollstatus":false,"getstatusoncommand":true,"devicetype":"Relay","outputs":1,"rgbwmode":"color","x":2120,"y":660,"wires":[[]]},{"id":"1c6510ef5f075b4c","type":"shelly-gen1","z":"3621caaf27071cb3","hostname":"192.168.1.50","description":"luce DOCCIA","pollinginterval":5000,"pollstatus":false,"getstatusoncommand":true,"devicetype":"Relay","outputs":1,"rgbwmode":"color","x":2120,"y":860,"wires":[[]]},{"id":"fe8a7052182f4be5","type":"shelly-gen1","z":"3621caaf27071cb3","hostname":"192.168.1.51","description":"luce BAGNO","pollinginterval":5000,"pollstatus":false,"getstatusoncommand":true,"devicetype":"Relay","outputs":1,"rgbwmode":"color","x":2110,"y":940,"wires":[[]]},{"id":"2e28027b1a32c7d7","type":"shelly-gen1","z":"3621caaf27071cb3","hostname":"192.168.1.53","description":"luce MATTEO","pollinginterval":5000,"pollstatus":false,"getstatusoncommand":true,"devicetype":"Relay","outputs":1,"rgbwmode":"color","x":2120,"y":980,"wires":[[]]},{"id":"c1f12752126ec237","type":"shelly-gen1","z":"3621caaf27071cb3","hostname":"192.168.1.58","description":"luce STANZINO","pollinginterval":5000,"pollstatus":false,"getstatusoncommand":true,"devicetype":"Relay","outputs":1,"rgbwmode":"color","x":2120,"y":700,"wires":[[]]},{"id":"c6f4f7047a8dc562","type":"shelly-gen1","z":"3621caaf27071cb3","hostname":"192.168.1.60","description":"luce CORRIDOIO-INGRESSO","pollinginterval":5000,"pollstatus":false,"getstatusoncommand":true,"devicetype":"Relay","outputs":1,"rgbwmode":"color","x":2170,"y":740,"wires":[[]]},{"id":"baad3181cb46dc73","type":"shelly-gen1","z":"3621caaf27071cb3","hostname":"192.168.1.61","description":"luce CORRIDOIO-LETTO","pollinginterval":5000,"pollstatus":false,"getstatusoncommand":true,"devicetype":"Relay","outputs":1,"rgbwmode":"color","x":2150,"y":780,"wires":[[]]},{"id":"2458fe43909d2c71","type":"zigbee2mqtt-out","z":"3621caaf27071cb3","name":"PL01-LETTO","server":"411e2b8e9bdac70b","friendly_name":"PL01-LETTO (SP 120)","device_id":"0x00158d00032aaa89","command":"state","commandType":"z2m_cmd","payload":"payload","payloadType":"msg","optionsValue":"","optionsType":"nothing","x":2110,"y":500,"wires":[]},{"id":"58236775ba922f76","type":"zigbee2mqtt-out","z":"3621caaf27071cb3","name":"PL02-SALOTTO","server":"411e2b8e9bdac70b","friendly_name":"PL02-SALOTTO (SP 120)","device_id":"0x00158d0003279f5e","command":"state","commandType":"z2m_cmd","payload":"payload","payloadType":"msg","optionsValue":"","optionsType":"nothing","x":2120,"y":160,"wires":[]},{"id":"06f6a1ef2428bf33","type":"zigbee2mqtt-out","z":"3621caaf27071cb3","name":"SW05-CUCINA","server":"411e2b8e9bdac70b","friendly_name":"SW05-CUCINA (K4003C/L4003C/N4003C/NT4003C)","device_id":"0x000474000113e511","command":"state","commandType":"z2m_cmd","payload":"payload","payloadType":"msg","optionsValue":"","optionsType":"nothing","x":2120,"y":420,"wires":[]},{"id":"9ce43b4b18a3035e","type":"zigbee2mqtt-out","z":"3621caaf27071cb3","name":"SW13-SALOTTO-BALCONE","server":"411e2b8e9bdac70b","friendly_name":"SW13-SALOTTO-BALCONE (K4003C/L4003C/N4003C/NT4003C)","device_id":"0x000474000117706b","command":"state","commandType":"z2m_cmd","payload":"payload","payloadType":"msg","optionsValue":"","optionsType":"nothing","x":2160,"y":360,"wires":[]},{"id":"1b7f0d6bedf07b2d","type":"subflow:405b554ae2b18a0c","z":"3621caaf27071cb3","name":"","env":[{"name":"coredash_grid","value":"","type":"str"}],"x":1940,"y":360,"wires":[["9ce43b4b18a3035e"],["9ce43b4b18a3035e"]]},{"id":"2b442d64865ed992","type":"comment","z":"3621caaf27071cb3","g":"5e83e55563514106","name":"node-red-contrib-virtual-smart-home ","info":"","x":800,"y":140,"wires":[]},{"id":"7d33fcbbbc19d73c","type":"comment","z":"3621caaf27071cb3","g":"5e83e55563514106","name":"node-red-contrib-alexa-remote-event","info":"","x":800,"y":180,"wires":[]},{"id":"ab3045c0b9ae2aee","type":"comment","z":"3621caaf27071cb3","g":"5e83e55563514106","name":"node-red-contrib-zigbee2mqtt-in","info":"","x":790,"y":220,"wires":[]},{"id":"6ef273c94e310a23","type":"comment","z":"3621caaf27071cb3","g":"5e83e55563514106","name":"node-red-contrib-shelly : shelly-gen1","info":"","x":800,"y":260,"wires":[]},{"id":"3b9f7c3eb17268ea","type":"zigbee2mqtt-out","z":"3621caaf27071cb3","name":"PS01-SALOTTO-LIBRERIA","server":"411e2b8e9bdac70b","friendly_name":"PS01-SALOTTO-LIBRERIA (TS0115)","device_id":"0xbc33acfffe077bb2","command":"state","commandType":"z2m_cmd","payload":"payload","payloadType":"msg","optionsValue":"","optionsType":"nothing","x":2160,"y":280,"wires":[]},{"id":"2768e0b03ce2cb46","type":"vsh-virtual-device","z":"3621caaf27071cb3","name":"cucina","topic":"test","connection":"6b19ce663089c7f6","template":"SWITCH","passthrough":false,"diff":false,"filter":false,"filterTopic":false,"x":910,"y":1120,"wires":[[]]},{"id":"43e3d520acb8e4da","type":"alexa-remote-account","name":"alexa","authMethod":"proxy","proxyOwnIp":"192.168.1.165","proxyPort":"3456","cookieFile":"/data/node-red/alexafile","refreshInterval":"2","alexaServiceHost":"alexa.amazon.it","amazonPage":"amazon.it","acceptLanguage":"it-IT","onKeywordInLanguage":"on","userAgent":"","useWsMqtt":"on","autoInit":"on"},{"id":"6b19ce663089c7f6","type":"vsh-connection","name":"vhs-connection","port":"8883","accessTokenExpiry":"1661967233266","debug":false,"backendUrl":"https://kfd5m4a21f.execute-api.eu-west-1.amazonaws.com/dev","lwaClientId":"amzn1.application-oa2-client.3f1bb07133854b078261ad43f2484c18"},{"id":"411e2b8e9bdac70b","type":"zigbee2mqtt-server","name":"CORE","host":"10.10.2.1","mqtt_port":"1883","mqtt_username":"","mqtt_password":"","mqtt_qos":"0","tls":"","usetls":false,"base_topic":"zigbee2mqtt"}]

The “on device activity” node receives a complex data structure(when you prompt Alexa) containing all the information regarding the activated echo device.

A - The “echo info & parsing” node:

  • identifies which echo device produced the message and the room where it resides, same for target endpoint device, eliminating any eventual message coming from neighbor echos
  • prepare the text for parsing (substitution of synonyms, elimination of stopwords)
  • parses the received STT string and extracts the intention (for example the action to be performed) and the entities (the objects on which to apply the action) to distinguish if it is a command or a routine
  • produces a message containing all the information necessary to carry out what is necessary. If it is a command, it passes it to node C for execution, if not, it sends it to node B

B - Node B “subroutines”:

  • recognizes the subroutine and creates as many messages as there are commands (actions) that make up the routine, and sends them all to node C for ezecution. The messages has a compact format containing the name of the room, of the device and the command to execute, delay and duration of the action (delay and duration will be successively processed by TIMING nodes)

C - node C “dispatch by deviceroom”

  • it simply sends the received messages in the various rooms (msg.payload.deviceroom) where the endpoint devices are located. The option value “all” broadcast a message to all the rooms (e.g. “close home”).

the “ROOMS” nodes:

  • In each room new messages are formatted to perform the elementary actions and then sent to the individual endpoint devices

subflows:

  • the TIMING subflow allows you to start the action after a delay of X seconds (the value of X contained in the received message) and to determine the duration Y of the action, if a time window is defined.
[{"id":"405b554ae2b18a0c","type":"subflow","name":"TIMING","info":"","category":"","in":[{"x":60,"y":100,"wires":[{"id":"62bec12e4905ce1b"}]}],"out":[{"x":455,"y":75,"wires":[{"id":"fdc198c8e7ebe137","port":0}]},{"x":455,"y":135,"wires":[{"id":"b8027df6a0358258","port":0}]}],"env":[],"meta":{},"color":"#DDAA99"},{"id":"62bec12e4905ce1b","type":"function","z":"405b554ae2b18a0c","name":"timing","func":"tot=0\n\ntoggle={\"on\":\"off\",\"off\":\"on\"};\nvar msg1 = JSON.parse(JSON.stringify(msg));\nvar msg2 = JSON.parse(JSON.stringify(msg));\n\nconst messages = new Array(node.outputCount)\n\n//PAYLOAD CLEANUP \n//SHELLY\nif(\"turn\" in msg.payload){\n    msg2.payload={\"turn\":msg.payload.command};\n//Z2M\n}else if (\"state\" in msg.payload){\n    msg2.payload={\"state\":msg.payload.command};\n//HE DOES'NT NEED ANY CLEANUP AS IT RELAY ON MSG.COMMAND\n}\n\nif (\"delay\" in msg){\n    tot+=msg.delay;\n}\nmessages[0]=msg1;\n\nif (\"duration\" in msg){\n    if (msg.duration>0){\n        tot+=msg.duration\n        msg2.delay=tot;\n        if(\"turn\" in msg.payload){\n            msg2.payload.turn=toggle[msg.payload.command] ?? null;\n        }else if (\"state\" in msg.payload){\n            msg2.payload.state=toggle[msg.payload.command] ?? null;\n        }else if (\"command\" in msg){\n            msg2.command=toggle[msg.payload.command] ?? null;\n        }\n    messages[1]=msg2;\n    }\n}\n\nreturn messages;","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":170,"y":100,"wires":[["fdc198c8e7ebe137"],["b8027df6a0358258"]]},{"id":"fdc198c8e7ebe137","type":"delay","z":"405b554ae2b18a0c","name":"delay","pauseType":"delayv","timeout":"0","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":310,"y":75,"wires":[[]]},{"id":"b8027df6a0358258","type":"delay","z":"405b554ae2b18a0c","name":"duration","pauseType":"delayv","timeout":"0","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":315,"y":135,"wires":[[]]}]
  • the TERMOMETER sublow gets termometer’s values from global variables (ram based) and formats the vocal messages
[{"id":"7c9a43c75a8b561e","type":"subflow","name":"echodispatch","info":"","category":"","in":[{"x":200,"y":160,"wires":[{"id":"53b566b98c4c7ee3"}]}],"out":[{"x":940,"y":160,"wires":[{"id":"792fd2603bfbacb4","port":0},{"id":"1f25b31de744cb75","port":0},{"id":"3fdc295d54afc7eb","port":0},{"id":"fed05e07cf397247","port":0},{"id":"3044c45efb375bf8","port":0}]}],"env":[],"meta":{},"color":"#DDAA99"},{"id":"53b566b98c4c7ee3","type":"switch","z":"7c9a43c75a8b561e","name":"DISPATCH BY ECHOROOM ATTRIB","property":"payload.echoroom","propertyType":"msg","rules":[{"t":"eq","v":"salotto","vt":"str"},{"t":"eq","v":"letto","vt":"str"},{"t":"eq","v":"iacopo","vt":"str"},{"t":"eq","v":"cucina","vt":"str"},{"t":"eq","v":"all","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":430,"y":160,"wires":[["792fd2603bfbacb4"],["1f25b31de744cb75"],["3fdc295d54afc7eb"],["fed05e07cf397247"],["3044c45efb375bf8"]]},{"id":"fed05e07cf397247","type":"alexa-remote-routine","z":"7c9a43c75a8b561e","name":"ECHO CUCINA","account":"43e3d520acb8e4da","routineNode":{"type":"speak","payload":{"type":"regular","text":{"type":"msg","value":"payload.text"},"devices":["G070RQ1383750U0F"]}},"x":740,"y":200,"wires":[[]]},{"id":"792fd2603bfbacb4","type":"alexa-remote-routine","z":"7c9a43c75a8b561e","name":"ECHO SALOTTO","account":"43e3d520acb8e4da","routineNode":{"type":"speak","payload":{"type":"regular","text":{"type":"msg","value":"payload.text"},"devices":["G2A1A603046409EF"]}},"x":750,"y":80,"wires":[[]]},{"id":"1f25b31de744cb75","type":"alexa-remote-routine","z":"7c9a43c75a8b561e","name":"ECHO LETTO","account":"43e3d520acb8e4da","routineNode":{"type":"speak","payload":{"type":"regular","text":{"type":"msg","value":"payload.text"},"devices":["G090P308817202WQ"]}},"x":740,"y":120,"wires":[[]]},{"id":"3fdc295d54afc7eb","type":"alexa-remote-routine","z":"7c9a43c75a8b561e","name":"ECHO IACOPO","account":"43e3d520acb8e4da","routineNode":{"type":"speak","payload":{"type":"regular","text":{"type":"msg","value":"payload.text"},"devices":["G090U509915108N8"]}},"x":740,"y":160,"wires":[[]]},{"id":"3044c45efb375bf8","type":"alexa-remote-routine","z":"7c9a43c75a8b561e","name":"ALL ECHOES","account":"43e3d520acb8e4da","routineNode":{"type":"speak","payload":{"type":"regular","text":{"type":"msg","value":"payload.text"},"devices":["c63676a598fc4bea933f537344a0cd64"]}},"x":740,"y":240,"wires":[[]]},{"id":"43e3d520acb8e4da","type":"alexa-remote-account","name":"alexa","authMethod":"proxy","proxyOwnIp":"192.168.1.165","proxyPort":"3456","cookieFile":"/data/node-red/alexafile","refreshInterval":"2","alexaServiceHost":"alexa.amazon.it","amazonPage":"amazon.it","acceptLanguage":"it-IT","onKeywordInLanguage":"on","userAgent":"","useWsMqtt":"on","autoInit":"on"},{"id":"8612386267fb8ebd","type":"subflow","name":"termometer","info":"","category":"","in":[{"x":40,"y":80,"wires":[{"id":"3c413979ba48a904"}]}],"out":[{"x":540,"y":80,"wires":[{"id":"e119aadfe2c3e6ee","port":0}]}],"env":[],"meta":{},"color":"#E6E0F8"},{"id":"3c413979ba48a904","type":"function","z":"8612386267fb8ebd","name":"termometro","func":"var msg1 = JSON.parse(JSON.stringify(msg));\nvar l = global.get('th-'+msg.payload.deviceroom,'ram');\nvar e = global.get('th-terrazzo','ram');\n\nif(msg.payload.deviceroom!=\"terrazzo\"){\n    txt = \"La temperatura della stanza \"+msg.payload.deviceroom+\" è di \"+l.temperature+ \" gradi. La temperatura esterna è di \"+e.temperature+ \" gradi.\";\n}else{\n    txt = \"La temperatura della stanza \"+msg.payload.deviceroom+\" è di \"+l.temperature+ \" gradi.\";\n}\nmsg1.payload.text=txt;\n\nreturn msg1","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":190,"y":80,"wires":[["e119aadfe2c3e6ee"]]},{"id":"e119aadfe2c3e6ee","type":"subflow:7c9a43c75a8b561e","z":"8612386267fb8ebd","name":"","x":390,"y":80,"wires":[[]]}]

there are other things among which:

  • sensor nodes store latest values in global variables
  • messages to pushover and/or echoes are managed by a subflow

I hope I was clear. If you need details on any point let me know.

EDIT: 24/09/2022 added some comments to the code and obscurated some reserved info (as echo serial #)

5 Likes

Wow thanks, @roberto! This is definitely a step beyond my current NR skills. Will take me some time to work through everything… hope I can replicate my own version of it. :eyes:

well … it is a work in progress. Consider I never wrote a line of code in javascript before this flow (ok, my long C experience helped a lot… :slight_smile: ) , and I’m sure it should be “cleaned” and “smartened”.

1 Like