Skip to content

Instantly share code, notes, and snippets.

@notenoughtech
Created March 5, 2020 18:40
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 notenoughtech/929c5f6cc90a9126ebb6e7787e1fca45 to your computer and use it in GitHub Desktop.
Save notenoughtech/929c5f6cc90a9126ebb6e7787e1fca45 to your computer and use it in GitHub Desktop.
Smarter Light Switch (n+1 principle)

enter image description here This projects adds extra features to the spare gang in a smart switch. Using an n+1 formula I add options to automate more light sources in the bedroom, adding automatic shutdown what work with a connected projector, IKEA dimmer integration and more!

  • Complete instructions

Features:

  • 1st gang – control main lights
  • 2nd gang – control bedside lamp
  • Automatic Cinema Mode – when the projector is in use
  • Close curtains – when the projector is in use (pending)
  • IKEA Dimmer – control main & bedside light
  • IKEA Dimmer – override cinema mode
  • IKEA Dimmer – timed switch off
  • Alexa, Google Assistant integration

Requirements

  • node-red-contrib-ping
  • node-red-contrib-nora
  • node-red-alexa-home-skill

Consider these smart light switches

If you want to learn more about how to wire smart light switches, read this guide

Settings

  • timeout - time it takes to turn off the lights

More about me:

If you want to get the latest updates to this project you can follow me via your preferred social media:

And if you feeling like buying me a coffee or supporting me in a more continuous way:

I hope you have enjoyed the project!

[{"id":"e39fd8a5.62d5c8","type":"tab","label":"Smarter Light Switch (n+1 principle)","disabled":false,"info":"\n![enter image description here](https://notenoughtech.com/wp-content/uploads/2020/03/maxresdefault-1.jpg)\nThis projects adds extra features to the spare gang in a smart switch. Using an n+1 formula I add options to automate more light sources in the bedroom, adding automatic shutdown what work with a connected projector, IKEA dimmer integration and more!\n\n - [Complete instructions]([https://notenoughtech.com/home-automation/creating-a-smarter-light-switch/](https://notenoughtech.com/home-automation/creating-a-smarter-light-switch/)\n\n**Features**:\n- **1st gang** – control main lights\n- **2nd gang** – control bedside lamp\n- **Automatic Cinema Mode** – when the projector is in use\n- **Close curtains** – when the projector is in use (**pending**)\n- **IKEA Dimmer** – control main & bedside light\n- **IKEA Dimmer** – override cinema mode\n- **IKEA Dimmer** – timed switch off\n- **Alexa**, **Google Assistant** integration\n\n## Requirements\n\n - node-red-contrib-ping\n - node-red-contrib-nora\n - node-red-alexa-home-skill\n\nConsider these smart light switches\n\n- [**1-3 Gang Zigbee Click N SmartThings**](http://bit.ly/3caVgC0)\n- **[1-3 Gang Zigbee Click LN Alexa/Google](http://bit.ly/2SYh4cm)**\n- **[1-3 Gang WiFi Touch N Alexa/Google](http://bit.ly/3a4pTHo)**\n- **[1-3 Gang Zigbee Touch no wires Alexa/Google](http://bit.ly/2Tupzv5)**\n- **[1-3 Gang Zigbee Touch N Alexa/Google](http://bit.ly/2VqIBVA)**\n- **[IKEA Dimmer](https://www.ikea.com/gb/en/p/tradfri-wireless-dimmer-white-00468432/)**\n \n If you want to learn more about how to wire smart light switches, read [this guide]([https://notenoughtech.com/home-automation/using-smart-light-switches/](https://notenoughtech.com/home-automation/using-smart-light-switches/))\n\n\n# Settings\n\n - **timeout** - time it takes to turn off the lights\n \n ## More about me:\n\nIf you want to get the latest updates to this project you can follow me via your preferred social media:\n\n- [Facebook](https://www.facebook.com/NotEnoughTECH/)\n- [Twitter](https://twitter.com/NotEnoughTECH)\n- [Instagram](https://www.instagram.com/notenoughtech/)\n- [YouTube](https://www.youtube.com/user/Polepositionpage)\n\nAnd if you feeling like buying me a coffee or supporting me in a more continuous way:\n\n- [Paypal](https://www.paypal.me/notenoughtech)\n- [Patreon](https://www.patreon.com/NotEnoughTECH)\n\nI hope you have enjoyed the project!\n\n "},{"id":"5a2dd908.054d28","type":"mqtt in","z":"e39fd8a5.62d5c8","name":"Wall Switch Gang 2 (Main Light)","topic":"tasmota/stat/POWER2","qos":"0","datatype":"auto","broker":"6e117ba5.8026e4","x":190,"y":160,"wires":[["96d6652b.0e36f8"]]},{"id":"a09fce93.96b89","type":"mqtt out","z":"e39fd8a5.62d5c8","name":"Main","topic":"tasmota/cmnd/POWER2","qos":"","retain":"","broker":"6e117ba5.8026e4","x":770,"y":740,"wires":[]},{"id":"27f739a3.b6e126","type":"mqtt in","z":"e39fd8a5.62d5c8","name":"Ikea Blue","topic":"zigbee2mqtt/IKEA_blue","qos":"0","datatype":"json","broker":"6e117ba5.8026e4","x":120,"y":340,"wires":[["93ad6a11.2495a8"]]},{"id":"93ad6a11.2495a8","type":"switch","z":"e39fd8a5.62d5c8","name":"","property":"payload.click","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"},{"t":"eq","v":"brightness_up","vt":"str"},{"t":"eq","v":"brightness_down","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":290,"y":340,"wires":[["86f86a36.5e5d48"],["6c23ee7f.4b96b"],["27ae66ff.45e59a"],["5609e243.642ccc"]]},{"id":"86f86a36.5e5d48","type":"function","z":"e39fd8a5.62d5c8","name":"lamp toggle","func":"var x = flow.get(\"bedroom_lamp\");\n\nif(x === false){\n msg.payload = true;\n flow.set(\"bedroom_lamp\", true);\n flow.set(\"bedroom_lamp_override\", true);\n return msg;\n}\nelse{\n msg.payload = false;\n flow.set(\"bedroom_lamp\", false);\n flow.set(\"bedroom_lamp_override\", true);\n return msg;\n}\n\n\n","outputs":1,"noerr":0,"x":550,"y":300,"wires":[["fc873e2a.c1afe"]]},{"id":"6c23ee7f.4b96b","type":"function","z":"e39fd8a5.62d5c8","name":"main toggle","func":"var x = flow.get(\"bedroom_main\");\n\nif(x === false){\n msg.payload = true;\n flow.set(\"bedroom_main\", true);\n flow.set(\"bedroom_lamp_override\", true);\n return msg;\n}\nelse{\n msg.payload = false;\n flow.set(\"bedroom_main\", false);\n flow.set(\"bedroom_lamp_override\", true);\n return msg;\n}","outputs":1,"noerr":0,"x":550,"y":340,"wires":[["5f683c3c.b9a524"]]},{"id":"5299c748.7d6c38","type":"ping","z":"e39fd8a5.62d5c8","name":"Projector","host":"192.168.1.111","timer":"7","x":120,"y":720,"wires":[["1d456466.2eacfc"]]},{"id":"5fc90001.ae746","type":"switch","z":"e39fd8a5.62d5c8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"false"},{"t":"gt","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":720,"wires":[[],["8179080d.d404d8"]]},{"id":"8179080d.d404d8","type":"change","z":"e39fd8a5.62d5c8","name":"lamp","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":720,"wires":[["a09fce93.96b89","53366367.9f9b9c"]]},{"id":"110842ea.255d4d","type":"function","z":"e39fd8a5.62d5c8","name":"Main","func":"var main = msg.payload;\nflow.set(\"bedroom_main\", main);\n\n\n\n\n\n","outputs":1,"noerr":0,"x":570,"y":160,"wires":[[]]},{"id":"27ae66ff.45e59a","type":"function","z":"e39fd8a5.62d5c8","name":"Lamp override","func":"msg.payload = true;\nflow.set(\"bedroom_lamp\", true);\nflow.set(\"bedroom_lamp_override\", false);\nreturn msg;\n\n","outputs":1,"noerr":0,"x":560,"y":400,"wires":[["fc873e2a.c1afe"]]},{"id":"c6858d6d.e48d3","type":"comment","z":"e39fd8a5.62d5c8","name":"Update","info":"","x":110,"y":60,"wires":[]},{"id":"aa80c24.f271f4","type":"comment","z":"e39fd8a5.62d5c8","name":"Toggle","info":"","x":770,"y":660,"wires":[]},{"id":"96d6652b.0e36f8","type":"change","z":"e39fd8a5.62d5c8","name":"to bool","rules":[{"t":"change","p":"payload","pt":"msg","from":"ON","fromt":"str","to":"true","tot":"bool"},{"t":"change","p":"payload","pt":"msg","from":"OFF","fromt":"str","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":160,"wires":[["110842ea.255d4d"]]},{"id":"5609e243.642ccc","type":"function","z":"e39fd8a5.62d5c8","name":"Lamp Timer","func":"var seconds = Date.now();\nvar timeout = flow.get(\"timeout\");\nvar timer = (timeout * 60000) + seconds;\nflow.set(\"timer_state\", true);\nflow.set(\"timer\", timer);\nmsg.payload = timeout;\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":520,"wires":[[]]},{"id":"e28b67e9.2ae728","type":"inject","z":"e39fd8a5.62d5c8","name":"Timeout 10 min","topic":"","payload":"10","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":520,"wires":[["59dcd042.671ce"]]},{"id":"59dcd042.671ce","type":"change","z":"e39fd8a5.62d5c8","name":"","rules":[{"t":"set","p":"timeout","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":520,"wires":[[]]},{"id":"e727237a.a6a4e","type":"inject","z":"e39fd8a5.62d5c8","name":"","topic":"","payload":"","payloadType":"date","repeat":"60","crontab":"","once":true,"onceDelay":0.1,"x":150,"y":560,"wires":[["e6955885.fc79c8"]]},{"id":"e6955885.fc79c8","type":"function","z":"e39fd8a5.62d5c8","name":"Watch timer","func":"var timer = flow.get(\"timer_state\");\nvar now = msg.payload;\n\nif(timer === true){\n if(now > timer){\n msg.payload = false;\n flow.set(\"timer\", 0);\n flow.set(\"timer_state\", false);\n flow.set(\"bedroom_lamp_override\", true);\n return msg;\n }\n}\n","outputs":1,"noerr":0,"x":550,"y":560,"wires":[["14cde229.d1a90e","4bf190cf.c43c7"]]},{"id":"e88e22.868201e","type":"comment","z":"e39fd8a5.62d5c8","name":"Timer","info":"","x":110,"y":480,"wires":[]},{"id":"6cae8b0c.25d214","type":"alexa-home","z":"e39fd8a5.62d5c8","conf":"","device":"93437","acknoledge":true,"name":"","topic":"","x":130,"y":1020,"wires":[["fd9cf50e.4aae48"]]},{"id":"628f4c9a.d5e284","type":"nora-light","z":"e39fd8a5.62d5c8","devicename":"Lamp","lightcolor":false,"brightnesscontrol":false,"turnonwhenbrightnesschanges":false,"passthru":true,"statepayload":true,"brightnessoverride":"","roomhint":"Bedroom","name":"","nora":"911d2cee.7ada3","topic":"","onvalue":"true","onvalueType":"bool","offvalue":"false","offvalueType":"bool","x":110,"y":880,"wires":[["527851df.0f44a"]]},{"id":"3cc4a7a2.b437b8","type":"alexa-home","z":"e39fd8a5.62d5c8","conf":"","device":"93438","acknoledge":true,"name":"","topic":"","x":130,"y":920,"wires":[["527851df.0f44a"]]},{"id":"1017c2fb.fcb24d","type":"nora-light","z":"e39fd8a5.62d5c8","devicename":"Main","lightcolor":false,"brightnesscontrol":false,"turnonwhenbrightnesschanges":false,"passthru":true,"statepayload":true,"brightnessoverride":"","roomhint":"Bedroom","name":"","nora":"911d2cee.7ada3","topic":"","onvalue":"true","onvalueType":"bool","offvalue":"false","offvalueType":"bool","x":110,"y":980,"wires":[["fd9cf50e.4aae48"]]},{"id":"fd9cf50e.4aae48","type":"mqtt out","z":"e39fd8a5.62d5c8","name":"Wall Switch Gang 2 (Main)","topic":"tasmota/cmnd/POWER2","qos":"","retain":"","broker":"6e117ba5.8026e4","x":420,"y":940,"wires":[]},{"id":"206a33c.4bdc6cc","type":"comment","z":"e39fd8a5.62d5c8","name":"Smart Assistant","info":"","x":140,"y":840,"wires":[]},{"id":"1d456466.2eacfc","type":"switch","z":"e39fd8a5.62d5c8","name":"","property":"bedroom_lamp_override","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":290,"y":720,"wires":[["5fc90001.ae746"]]},{"id":"deac7a86.4fedc8","type":"mqtt in","z":"e39fd8a5.62d5c8","name":"Wall Switch Gang 1 (Lamp)","topic":"tasmota/stat/POWER1","qos":"0","datatype":"auto","broker":"6e117ba5.8026e4","x":170,"y":100,"wires":[["ce1e330a.d681c"]]},{"id":"3be42a4c.ba8e36","type":"function","z":"e39fd8a5.62d5c8","name":"Lamp","func":"var lamp = msg.payload;\nflow.set(\"bedroom_lamp\", lamp);\nmsg.payload = lamp;\nreturn msg;\n\n\n\n\n\n","outputs":1,"noerr":0,"x":570,"y":100,"wires":[["5f7c8136.a663d"]]},{"id":"ce1e330a.d681c","type":"change","z":"e39fd8a5.62d5c8","name":"to bool","rules":[{"t":"change","p":"payload","pt":"msg","from":"ON","fromt":"str","to":"true","tot":"bool"},{"t":"change","p":"payload","pt":"msg","from":"OFF","fromt":"str","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":100,"wires":[["3be42a4c.ba8e36"]]},{"id":"3af2c48c.db2a5c","type":"comment","z":"e39fd8a5.62d5c8","name":"projector auto-off","info":"","x":120,"y":680,"wires":[]},{"id":"53636bf1.173b24","type":"comment","z":"e39fd8a5.62d5c8","name":"IKEA Dimmer","info":"","x":130,"y":300,"wires":[]},{"id":"6ce8f139.e7691","type":"comment","z":"e39fd8a5.62d5c8","name":"Extra Gang","info":"","x":790,"y":60,"wires":[]},{"id":"527851df.0f44a","type":"mqtt out","z":"e39fd8a5.62d5c8","name":"Wall Switch Gang 1 (Lamp)","topic":"tasmota/cmnd/POWER1","qos":"","retain":"","broker":"6e117ba5.8026e4","x":420,"y":900,"wires":[]},{"id":"53366367.9f9b9c","type":"mqtt out","z":"e39fd8a5.62d5c8","name":"Wall Switch Gang 1 (Lamp)","topic":"tasmota/cmnd/POWER1","qos":"","retain":"","broker":"6e117ba5.8026e4","x":840,"y":700,"wires":[]},{"id":"14cde229.d1a90e","type":"mqtt out","z":"e39fd8a5.62d5c8","name":"Main","topic":"tasmota/cmnd/POWER2","qos":"","retain":"","broker":"6e117ba5.8026e4","x":770,"y":580,"wires":[]},{"id":"76cf50de.763eb","type":"comment","z":"e39fd8a5.62d5c8","name":"Toggle","info":"","x":770,"y":500,"wires":[]},{"id":"5f7c8136.a663d","type":"mqtt out","z":"e39fd8a5.62d5c8","name":"Smart Socket Control","topic":"/bedroom/cmnd/POWER","qos":"0","retain":"","broker":"6e117ba5.8026e4","x":840,"y":100,"wires":[]},{"id":"5f683c3c.b9a524","type":"mqtt out","z":"e39fd8a5.62d5c8","name":"Main","topic":"tasmota/cmnd/POWER2","qos":"","retain":"","broker":"6e117ba5.8026e4","x":770,"y":340,"wires":[]},{"id":"47638547.0de82c","type":"comment","z":"e39fd8a5.62d5c8","name":"Toggle","info":"","x":770,"y":260,"wires":[]},{"id":"fc873e2a.c1afe","type":"mqtt out","z":"e39fd8a5.62d5c8","name":"Wall Switch Gang 1 (Lamp)","topic":"tasmota/cmnd/POWER1","qos":"","retain":"","broker":"6e117ba5.8026e4","x":840,"y":300,"wires":[]},{"id":"4bf190cf.c43c7","type":"mqtt out","z":"e39fd8a5.62d5c8","name":"Wall Switch Gang 1 (Lamp)","topic":"tasmota/cmnd/POWER1","qos":"","retain":"","broker":"6e117ba5.8026e4","x":840,"y":540,"wires":[]},{"id":"6e117ba5.8026e4","type":"mqtt-broker","z":"","name":"MQTT","broker":"automation.local","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"911d2cee.7ada3","type":"nora-config","z":"","name":"NORA","group":"","notify":false}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment