{"id":1092,"date":"2018-07-14T21:54:41","date_gmt":"2018-07-14T20:54:41","guid":{"rendered":"http:\/\/EvertDekker.com\/?p=1092"},"modified":"2022-12-31T14:22:43","modified_gmt":"2022-12-31T13:22:43","slug":"iot-light-switch-with-mains-input","status":"publish","type":"post","link":"https:\/\/evertdekker.com\/wp\/?p=1092","title":{"rendered":"Iot light switch with mains input"},"content":{"rendered":"<hr \/>\n<p>IOT light switch with input for switch with mains.<\/p>\n<p>The idea is the same as the famous <a href=\"http:\/\/evertdekker.com\/?p=789\">Sonoff wifi switch<\/a> but this one has also an input for a 230V~ switch so you can still use your existing light switches.<br \/>\nMost of the light in my house is replaced with <a href=\"http:\/\/evertdekker.com\/?p=1002\">Sonoff touch switch<\/a> , however this is not possible everywhere. For example on the stair case we have what&#8217;s called a switching circuit (wisselschakelaar for the dutch readers) and due to the wiring it was not possible to replace them both with a Sonoff touch switch.<\/p>\n<p>To detect the present of the mains on the input I started with a simple schematic based around the <a href=\"https:\/\/www.vishay.com\/docs\/83608\/h11aa1.pdf\">H11AA1<\/a>\u00a0which you can find a lot on the net as mains or zero cross detector for Arduino. This worked flawless, see the photo of my experiment. With the CTR (current transfer ratio) of 20% it was necessary to have a current of at least 3.3mA through the led of the opto-coupler. With the used current limiter resistors of 2x33K this will dissipate 0.71W.<br \/>\nNot that much energy to &#8220;waste&#8221;, however depending on the state of the switching circuit and the Mqtt state this &#8220;wasting&#8221; can occur 24 hours a day, this can be done better.<br \/>\nSearching for an opto-coupler with a higher CTR should do the trick. The <a href=\"https:\/\/www.vishay.com\/docs\/83722\/sfh628a.pdf\">SFH6286-3<\/a> has a CTR of 100~320%, a led current of 1mA would be enough with this CTR ratio.\u00a0 2x110K Resistor will limit the current to 1mA and will dissipate 0.22W.<br \/>\nThat&#8217;s 0.5W less then before, that will save 4.36kWh per year maximum.<\/p>\n<p><strong>Note<\/strong>: All calculation done in this post where done for 230V~ 50Hz.<\/p>\n<p>The rest of the circuit is not that special. The Esp-01 is programmed with an <a href=\"http:\/\/evertdekker.com\/?p=1107\">external programmer<\/a> and then equiped with a OTA bootloader so programming is only needed to be done once (theoretically). To have enough room for the OTA bootloader and the sketch I have updated the memory from the esp-01 from 1MB to 4MB. That&#8217;s easy done with a hot air gun to replace the memory chip. 4Mb spi flash chips can be bought very cheap on ebay.<br \/>\nThe solid state relay will consume 6mA at 3.3V, this is broad within the max pin GPIO current of the ESP8266 so no transistor driver is needed.<\/p>\n<p>Because the Esp-01 doesn&#8217;t have that much IO pins available the RX and TX can also made be available as IO, to disconnect them from the uart use:<\/p>\n<pre class=\"brush: csharp; gutter: true\">pinMode(1, FUNCTION_3); \/\/GPIO 1 (TX) swap the pin to a GPIO.\r\npinMode(3, FUNCTION_3); \/\/GPIO 3 (RX) swap the pin to a GPIO.<\/pre>\n<p>You can still use the TX\/RX pin to program the ESP-01, but using them in your sketch is not possible anymore. To still have the possibility to debug I use a <a href=\"https:\/\/github.com\/JoaoLopesF\/RemoteDebug\">remote debug library<\/a> to debug over telnet.<\/p>\n<div class=\"n2_ss_slider_publish__option_code\" dir=\"ltr\" data-mode=\"id\"><\/div>\n<p>&nbsp;<\/p>\n<p>If you want to make your own, or use parts of the design here are\u00a0 the Altium Designer 16 files:<br \/>\n<div class=\"sdm_download_button_box_default\"><div class=\"sdm_download_link\"><a href=\"https:\/\/evertdekker.com\/wp\/?sdm_process_download=1&download_id=1146\" class=\"sdm_download darkblue\" title=\"iotLightSwitch\" >Download Now!<\/a><\/div><\/div> <div class=\"sdm_download_count\"><span class=\"sdm_count_number\">2495<\/span><span class=\"sdm_count_string\"> Downloads<\/span><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>IOT light switch with input for switch with mains. The idea is the same as the famous Sonoff wifi switch but this one has also an input for a 230V~ switch so you can still use your existing light switches. Most of the light in my house is replaced with Sonoff touch switch , however [&#8230;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[128],"tags":[185,180,129,133,183,188,187,184,186],"class_list":["post-1092","post","type-post","status-publish","format-standard","hentry","category-esp8266","tag-4mb","tag-esp01","tag-esp8266","tag-iot","tag-iot-lightswitch","tag-mains-detector","tag-switching-circuit","tag-telnet-debug","tag-wisselschakelaar"],"_links":{"self":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1092","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1092"}],"version-history":[{"count":36,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1092\/revisions"}],"predecessor-version":[{"id":1648,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1092\/revisions\/1648"}],"wp:attachment":[{"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/evertdekker.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}