Advertisement
Guest User

example

a guest
Dec 28th, 2022
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 7.94 KB | None | 0 0
  1. [{"id":"7c19e9cd2fe7e8d3","type":"function","z":"9522bbe913e8d405","name":"Switch case","func":"var inputSwitch = msg.topic;\nvar entityID = \"default\";\nvar actionButton = \"default\"\nvar select = true; // true for standard action, false for scene activation\ninputSwitch = inputSwitch.substring(inputSwitch.indexOf(\"/\")+1, inputSwitch.indexOf(\"/\",8));\nswitch(inputSwitch) {\n    case \"tasmota_bagno\":\n        if (msg.payload.Button1 !== undefined) {\n            entityID = \"light.luce_3cr\";\n            actionButton = msg.payload.Button1.Action;\n            select = true;\n            //msg = { \"entity_id\": \"light.luce_3cr\", \"action\": msg.payload.Button1.Action };\n            break;\n        }\n        if (msg.payload.Button2 !== undefined) {\n            return null;\n            //to be defined\n        }\n        if (msg.payload.Button3 !== undefined) {\n            entityID = \"light.luci_camera\";\n            actionButton = msg.payload.Button3.Action;\n            select = true;\n            //msg = { \"entity_id\": \"light.luci_camera\", \"action\": msg.payload.Button3.Action };\n            break;\n        }\n        if (msg.payload.Button4 !== undefined) {\n            entityID = \"light.luci_salotto\";\n            actionButton = msg.payload.Button4.Action;\n            select = true;\n            //msg = { \"entity_id\": \"light.luci_salotto\", \"action\": msg.payload.Button4.Action };\n            break;\n        }\n        node.warn(\"tasmota_bagno:something went wrong\");\n        break;\n    case \"tasmota_salotto\":\n        if (msg.payload.Button1 !== undefined) {\n            entityID = \"light.luci_salotto\";\n            actionButton = msg.payload.Button1.Action;\n            select = true;\n            //msg = { \"entity_id\": \"light.luci_salotto\", \"action\": msg.payload.Button1.Action };\n            //msg[\"entity_id\"] = \"light.luce_1cm\";\n            break;\n        }\n        if (msg.payload.Button2 !== undefined) {\n            entityID = \"light.luci_salotto\";\n            actionButton = msg.payload.Button2.Action;\n            select = false;\n            //msg = { \"entity_id\": \"scene.salotto_relax\", \"action\": msg.payload.Button2.Action }; \n            break;\n        }\n        node.warn(\"tasmota_salotto:something went wrong\");\n        break;\n    case \"tasmota_camera\":\n        if (msg.payload.Button1 !== undefined) {\n            entityID = \"light.luci_camera\";\n            actionButton = msg.payload.Button1.Action;\n            select = true;\n            //msg = { \"entity_id\": \"light.luci_camera\", \"action\": msg.payload.Button1.Action};\n            //msg[\"entity_id\"] = \"light.luce_1cm\";\n            break; \n        }\n        if (msg.payload.Button2 !== undefined) {\n            entityID = \"light.luci_camera\";\n            actionButton = msg.payload.Button2.Action;\n            select = false;\n            //msg = { \"entity_id\": \"scene.camera_relax\", \"action\": msg.payload.Button2.Action };\n            break; \n        }\n        node.warn(\"tasmota_camera:something went wrong\");\n        break;\n    case \"tasmota_cucina\":\n        if (msg.payload.Button1 !== undefined) {\n            entityID = \"light.luci_cucina\";\n            actionButton = msg.payload.Button1.Action;\n            select = true;\n            //msg = { \"entity_id\": \"light.luci_cucina\", \"action\": msg.payload.Button1.Action };\n            //msg[\"entity_id\"] = \"light.luce_1cm\";\n            break;\n        }\n        if (msg.payload.Button2 !== undefined) {\n            entityID = \"light.luci_cucina\";\n            actionButton = msg.payload.Button2.Action;\n            select = false;\n            //msg = { \"entity_id\": \"scene.cucina_relax\", \"action\": msg.payload.Button2.Action };\n            break;\n        }\n        node.warn(\"tasmota_cucina:something went wrong\");\n        break;\n    case \"tasmota_bagno_servizi\":\n        if (msg.payload.Button1 !== undefined) {\n            entityID = \"light.luce_2cr\";\n            actionButton = msg.payload.Button1.Action;\n            select = true;\n            //msg = { \"entity_id\": \"light.luce_2cr\", \"action\": msg.payload.Button1.Action };\n            //msg[\"entity_id\"] = \"light.luce_1cm\";\n            break;\n        }\n        if (msg.payload.Button2 !== undefined) {\n            entityID = \"light.bagno_servizi\";\n            actionButton = msg.payload.Button2.Action;\n            select = true;\n            //msg = { \"entity_id\": \"light.bagno_servizi\", \"action\": msg.payload.Button2.Action };\n            break;\n        }\n        node.warn(\"tasmota_bagno_servizi:something went wrong\");\n        break;\n    case \"tasmota_wc\":\n        if (msg.payload.Button1 !== undefined) {\n            entityID = \"light.luce_wc\";\n            actionButton = msg.payload.Button1.Action;\n            select = true;\n            //msg = { \"entity_id\": \"light.luce_wc\", \"action\": msg.payload.Button1.Action };\n            //msg[\"entity_id\"] = \"light.luce_1cm\";\n            break;\n        }\n        if (msg.payload.Button2 !== undefined) {\n            return null;\n            //to be defined\n        }\n        node.warn(\"tasmota_wc:something went wrong\");\n        break;\n    case \"tasmota_ingresso\":\n        if (msg.payload.Button1 !== undefined) {\n            entityID = \"light.luce_1cr\";\n            actionButton = msg.payload.Button1.Action;\n            select = true;\n            //msg = { \"entity_id\": \"light.luce_1cr\", \"action\": msg.payload.Button1.Action };\n            //msg[\"entity_id\"] = \"light.luce_1cm\";\n            break;\n        }\n        if (msg.payload.Button2 !== undefined) {\n            return null;\n            //to be defined\n        }\n        node.warn(\"tasmota_ingresso:something went wrong\");\n        break;\n}\nreturn msg =\n{\n    \"payload\": {\n        \"action\": actionButton,\n        \"typeofaction\": select,\n        \"data\": {\n            \"entity_id\": entityID\n        }\n    }\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":310,"y":840,"wires":[["23d72e38bc3254d4"]]},{"id":"23d72e38bc3254d4","type":"api-current-state","z":"9522bbe913e8d405","name":"Check status light","server":"5f04c7c3.35aa98","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"{{payload.data.entity_id}}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":510,"y":840,"wires":[["b2311ffe41a0477c","be85a5f77c6233bd"]]},{"id":"7b2a2a654a1388b5","type":"mqtt in","z":"9522bbe913e8d405","name":"","topic":"stat/+/RESULT","qos":"2","datatype":"auto-detect","broker":"a3fb535a1424f3bc","nl":false,"rap":true,"rh":0,"inputs":0,"x":140,"y":840,"wires":[["7c19e9cd2fe7e8d3"]]},{"id":"be85a5f77c6233bd","type":"flogger","z":"9522bbe913e8d405","name":"","logfile":"logfile2","inputchoice":"fullmsg","inputobject":"payload","inputobjectType":"msg","inputmoustache":"Recieved payload {{payload}} and topic {{topic}}","loglevel":"ERROR","logconfig":"8534e23c.037bc","sendpane":"","x":630,"y":740,"wires":[[]]},{"id":"5f04c7c3.35aa98","type":"server","name":"Home Assistant","addon":true},{"id":"a3fb535a1424f3bc","type":"mqtt-broker","name":"Mqtt Broker","broker":"10.10.10.181","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""},{"id":"8534e23c.037bc","type":"config-log","logname":"standard-logging","logdir":"/config/logs","stamp":"local","logstyle":"plain","logrotate":true,"logcompress":true,"logrotatecount":"5","logsize":"100"}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement