Skip to content

Instantly share code, notes, and snippets.

@MatsA
Created January 3, 2021 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatsA/a7275d98ec43c0c43cbe278bd8602ed5 to your computer and use it in GitHub Desktop.
Save MatsA/a7275d98ec43c0c43cbe278bd8602ed5 to your computer and use it in GitHub Desktop.
NodeRed flow switching a Shelly 1. Included Wilhelm SK instruktions
[{"id":"3113b544.8ff882","type":"tab","label":"Signalk & Shelly & WSK","disabled":false,"info":""},{"id":"3a0b4910.ac2df6","type":"debug","z":"3113b544.8ff882","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":690,"y":500,"wires":[]},{"id":"68ac6e9e.e86d","type":"signalk-put-handler","z":"3113b544.8ff882","name":"","path":"electrical.switches.anchorLight.state","x":330,"y":500,"wires":[["3a0b4910.ac2df6","98f13e8a.d877d8"]]},{"id":"b501dbf4.3b32f","type":"inject","z":"3113b544.8ff882","name":"ON","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":110,"y":500,"wires":[["98f13e8a.d877d8"]]},{"id":"98f13e8a.d877d8","type":"function","z":"3113b544.8ff882","name":"Turn ON/OFF","func":"// Input from WSK or Inject nodes \n\nswitch(msg.payload) {\n case 1:\n msg.payload = \"turn=on\";\n break;\n case 0:\n msg.payload = \"turn=off\";\n break;\n default:\n return msg [null];\n}\n\nmsg.url= \"http://shelly1-E098068D8750/relay/0\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":310,"y":560,"wires":[["7efcaeda.9f5858"]]},{"id":"7efcaeda.9f5858","type":"http request","z":"3113b544.8ff882","name":"","method":"POST","ret":"obj","url":"","tls":"","x":510,"y":560,"wires":[["759dac95.791454"]]},{"id":"759dac95.791454","type":"debug","z":"3113b544.8ff882","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":560,"wires":[]},{"id":"8c59a332.bb1a3","type":"inject","z":"3113b544.8ff882","name":"OFF","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":110,"y":560,"wires":[["98f13e8a.d877d8"]]},{"id":"e242d0e2.073818","type":"function","z":"3113b544.8ff882","name":"Get Shelly sts","func":"// Get status\n\nmsg.url= \"http://shelly1-E098068D8750/status\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":340,"y":100,"wires":[["f878e470.52cad8"]]},{"id":"f878e470.52cad8","type":"http request","z":"3113b544.8ff882","name":"","method":"POST","ret":"obj","paytoqs":false,"url":"","tls":"","persist":false,"proxy":"","authType":"","x":530,"y":100,"wires":[["3cb8df6a.6fefa8"]]},{"id":"7810d5c1.774d04","type":"comment","z":"3113b544.8ff882","name":"Initializing the flow, getting the switch status","info":"","x":200,"y":40,"wires":[]},{"id":"3cb8df6a.6fefa8","type":"function","z":"3113b544.8ff882","name":"Set state","func":"// ison = true, relay on\n\nif (msg.payload.relays[0].ison) {\n msg.payload = 1;\n}\nelse{\n msg.payload = 0;\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":140,"y":160,"wires":[["c30ecb2c.cd8bd8"]]},{"id":"9e684d08.e6b25","type":"signalk-send-pathvalue","z":"3113b544.8ff882","name":"","source":"","x":670,"y":160,"wires":[]},{"id":"ade92eaa.86143","type":"function","z":"3113b544.8ff882","name":"Get settings","func":"// Get settings\nmsg.url= \"http://shelly1-E098068D8750/settings\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":310,"y":680,"wires":[["8b3a1ea0.f9238"]]},{"id":"8b3a1ea0.f9238","type":"http request","z":"3113b544.8ff882","name":"","method":"POST","ret":"obj","url":"","tls":"","x":510,"y":680,"wires":[["74dd64eb.6f35ec"]]},{"id":"afbb85f7.c4f94","type":"inject","z":"3113b544.8ff882","name":"","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"","vt":"string"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":680,"wires":[["ade92eaa.86143"]]},{"id":"74dd64eb.6f35ec","type":"debug","z":"3113b544.8ff882","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":670,"y":680,"wires":[]},{"id":"c143c508.cd1f88","type":"http in","z":"3113b544.8ff882","name":"Sense Shelly sts","url":"/shelly/:sts","method":"get","upload":false,"swaggerDoc":"","x":120,"y":280,"wires":[["8137510e.02587"]]},{"id":"d8561336.ce6af8","type":"change","z":"3113b544.8ff882","name":"Set Headers","rules":[{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.content-type","pt":"msg","to":"application/json","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":960,"wires":[[]]},{"id":"c84c990b.b060a8","type":"http response","z":"3113b544.8ff882","name":"http resp.","statusCode":"","headers":{},"x":500,"y":280,"wires":[]},{"id":"8137510e.02587","type":"function","z":"3113b544.8ff882","name":"Get Shelly sts","func":"// Get feedback from Shelly sts 0/1\n\nmsg.payload = parseInt(msg.req.params.sts);\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":320,"y":280,"wires":[["c84c990b.b060a8","c30ecb2c.cd8bd8"]]},{"id":"941282f0.8d3a5","type":"comment","z":"3113b544.8ff882","name":"End node sensing switch output change","info":"","x":200,"y":220,"wires":[]},{"id":"88b4edab.8aea3","type":"inject","z":"3113b544.8ff882","name":"Sense interval","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"1","topic":"","payload":"","payloadType":"date","x":140,"y":100,"wires":[["e242d0e2.073818"]]},{"id":"8ce65066.62972","type":"ui_template","z":"3113b544.8ff882","group":"1ccdafdb.391ce","name":"Button template","order":3,"width":"6","height":"6","format":"<style>\n .filled { height: 100%; }\n .rounded {border-radius: 35px;}\n .bigfont {font-size: 28px;}\n .bold {font-weight: bold;}\n .bordercolor {border-color: white;}\n .borderstyle {border-style: solid;}\n .borderwidth {border-width:10px;}\n</style>\n<md-button \n\tclass=\"filled rounded bigfont bold bordercolor borderstyle borderwidth\"\n\tstyle=\"{{'background-color:'+ msg.background}}\"\n\tng-click=\"send({payload: 'toggle'})\">\n\tAnchor <br/> Light\n</md-button>","storeOutMessages":false,"fwdInMessages":false,"templateScope":"local","x":680,"y":360,"wires":[["584d0fb4.c715"]]},{"id":"584d0fb4.c715","type":"function","z":"3113b544.8ff882","name":"","func":"\nif (msg.payload == \"toggle\")\n \n if (flow.get(\"shellySts\")== 1){\n \n msg.payload = 0\n msg.background = \"lime\"\n } else\n {\n \n msg.payload = 1\n msg.background = \"red\"\n }\nelse {\n return msg[null]\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":100,"y":360,"wires":[["8ce65066.62972","98f13e8a.d877d8"]]},{"id":"c30ecb2c.cd8bd8","type":"function","z":"3113b544.8ff882","name":"Set context, color","func":"\nflow.set(\"shellySts\", msg.payload)\n\nif (msg.payload == 0){\n \n msg.background = \"red\"\n}\nelse {\n \n msg.background = \"lime\" \n}\n\nmsg.topic = \"electrical.switches.anchorLight.state\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":430,"y":160,"wires":[["9e684d08.e6b25","8ce65066.62972"]]},{"id":"70a758c9.5432e8","type":"comment","z":"3113b544.8ff882","name":"Setting the Shelly 1 to ON/OFF","info":"","x":170,"y":440,"wires":[]},{"id":"f3dcfbb7.1e6678","type":"comment","z":"3113b544.8ff882","name":"Manually getting the settings from Shelly 1","info":"","x":210,"y":620,"wires":[]},{"id":"1ccdafdb.391ce","type":"ui_group","name":"Col 1","tab":"ac49f9b.83db808","order":1,"disp":false,"width":"6","collapse":false},{"id":"ac49f9b.83db808","type":"ui_tab","name":"Switch","icon":"dashboard","order":3,"disabled":false,"hidden":false}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment