{"id":1303,"date":"2024-01-11T19:03:59","date_gmt":"2024-01-11T18:03:59","guid":{"rendered":"https:\/\/chochol.io\/?p=1303"},"modified":"2025-08-23T19:53:07","modified_gmt":"2025-08-23T17:53:07","slug":"home-assistant-installing-mirror-lighting-on-esphome","status":"publish","type":"post","link":"https:\/\/chochol.io\/en\/smart-home\/home-assistant-installing-mirror-lighting-on-esphome\/","title":{"rendered":"Home Assistant: Installing mirror lighting on ESPHome"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"1303\" class=\"elementor elementor-1303 elementor-1185\" data-elementor-post-type=\"post\">\n\t\t\t\t<div class=\"elementor-element elementor-element-436a1a6 e-flex e-con-boxed e-con e-parent\" data-id=\"436a1a6\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-13bbb85 elementor-toc--minimized-on-tablet elementor-widget elementor-widget-table-of-contents\" data-id=\"13bbb85\" data-element_type=\"widget\" data-e-type=\"widget\" data-settings=\"{&quot;exclude_headings_by_selector&quot;:[],&quot;no_headings_message&quot;:&quot;No headings were found on this page.&quot;,&quot;headings_by_tags&quot;:[&quot;h2&quot;,&quot;h3&quot;,&quot;h4&quot;,&quot;h5&quot;,&quot;h6&quot;],&quot;marker_view&quot;:&quot;numbers&quot;,&quot;minimize_box&quot;:&quot;yes&quot;,&quot;minimized_on&quot;:&quot;tablet&quot;,&quot;hierarchical_view&quot;:&quot;yes&quot;,&quot;min_height&quot;:{&quot;unit&quot;:&quot;px&quot;,&quot;size&quot;:&quot;&quot;,&quot;sizes&quot;:[]},&quot;min_height_tablet&quot;:{&quot;unit&quot;:&quot;px&quot;,&quot;size&quot;:&quot;&quot;,&quot;sizes&quot;:[]},&quot;min_height_mobile&quot;:{&quot;unit&quot;:&quot;px&quot;,&quot;size&quot;:&quot;&quot;,&quot;sizes&quot;:[]}}\" data-widget_type=\"table-of-contents.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-toc__header\">\n\t\t\t\t\t\t<div class=\"elementor-toc__header-title\">\n\t\t\t\tTable of contents\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t\t<div class=\"elementor-toc__toggle-button elementor-toc__toggle-button--expand\" role=\"button\" tabindex=\"0\" aria-controls=\"elementor-toc__13bbb85\" aria-expanded=\"true\" aria-label=\"Open table of contents\"><svg aria-hidden=\"true\" class=\"e-font-icon-svg e-fas-chevron-down\" viewBox=\"0 0 448 512\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"><path d=\"M207.029 381.476L12.686 187.132c-9.373-9.373-9.373-24.569 0-33.941l22.667-22.667c9.357-9.357 24.522-9.375 33.901-.04L224 284.505l154.745-154.021c9.379-9.335 24.544-9.317 33.901.04l22.667 22.667c9.373 9.373 9.373 24.569 0 33.941L240.971 381.476c-9.373 9.372-24.569 9.372-33.942 0z\"><\/path><\/svg><\/div>\n\t\t\t\t<div class=\"elementor-toc__toggle-button elementor-toc__toggle-button--collapse\" role=\"button\" tabindex=\"0\" aria-controls=\"elementor-toc__13bbb85\" aria-expanded=\"true\" aria-label=\"Close table of contents\"><svg aria-hidden=\"true\" class=\"e-font-icon-svg e-fas-chevron-up\" viewBox=\"0 0 448 512\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"><path d=\"M240.971 130.524l194.343 194.343c9.373 9.373 9.373 24.569 0 33.941l-22.667 22.667c-9.357 9.357-24.522 9.375-33.901.04L224 227.495 69.255 381.516c-9.379 9.335-24.544 9.317-33.901-.04l-22.667-22.667c-9.373-9.373-9.373-24.569 0-33.941L207.03 130.525c9.372-9.373 24.568-9.373 33.941-.001z\"><\/path><\/svg><\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<div id=\"elementor-toc__13bbb85\" class=\"elementor-toc__body\">\n\t\t\t<div class=\"elementor-toc__spinner-container\">\n\t\t\t\t<svg class=\"elementor-toc__spinner eicon-animation-spin e-font-icon-svg e-eicon-loading\" aria-hidden=\"true\" viewBox=\"0 0 1000 1000\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"><path d=\"M500 975V858C696 858 858 696 858 500S696 142 500 142 142 304 142 500H25C25 237 238 25 500 25S975 237 975 500 763 975 500 975Z\"><\/path><\/svg>\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6033dc1 elementor-widget elementor-widget-text-editor\" data-id=\"6033dc1\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h2>Hello!<\/h2><p>Today, I&#8217;ll walk you through the steps to create smart mirror lighting using an <a href=\"https:\/\/www.espressif.com\/en\/products\/socs\/esp8266\" target=\"_blank\" rel=\"noopener\">ESP8266<\/a> NodeMCU board with <a href=\"https:\/\/esphome.io\" target=\"_blank\" rel=\"noopener\">ESPHome<\/a> installed via <a href=\"https:\/\/www.home-assistant.io\" target=\"_blank\" rel=\"noopener\">Home Assistant<\/a>. This will not only improve the convenience of light in the bathroom, but will also open the door for applying this solution in different areas of the house. In order to be able to easily turn the light on and off while being at the mirror, we will use the Shelly i3 mounted push-button, with full light control functionality both locally and remotely.<\/p><h3>What is the ESP8266 NodeMCU?<\/h3><p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignleft wp-image-1241\" src=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/assets2F-LpXqB3J1BMD5s4OpYSg2F-LpXslUdklMPEtHLTfE22F-LpXt-jt9761qMH3KcKY2Fnodemcu-300x162.webp\" alt=\"ESP8266, board\" width=\"351\" height=\"190\" srcset=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/assets2F-LpXqB3J1BMD5s4OpYSg2F-LpXslUdklMPEtHLTfE22F-LpXt-jt9761qMH3KcKY2Fnodemcu-300x162.webp 300w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/assets2F-LpXqB3J1BMD5s4OpYSg2F-LpXslUdklMPEtHLTfE22F-LpXt-jt9761qMH3KcKY2Fnodemcu.webp 629w\" sizes=\"(max-width: 351px) 100vw, 351px\" \/><strong>ESP8266 NodeMCU<\/strong> is a popular development board with ESP8266 microcontroller, ideal for IoT projects. Equipped with a Wi-Fi module, it facilitates easy connection to the network. Includes USB-to-Serial Converter for easy programming and communication with USB port. It supports Arduino IDE, which makes programming easy. With a large number of GPIOs, it allows connecting various devices. It is popular for its simplicity and community support, making it an excellent choice for DIY IoT projects.<\/p><p>\u00a0<\/p><p>\u00a0<\/p><h3>What is ESPHome?<\/h3><p><img decoding=\"async\" class=\"alignleft wp-image-1243\" src=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/esphome-icon-2048x1579-htac8rfa-300x231.png\" alt=\"ESPHome, icon\" width=\"350\" height=\"270\" srcset=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/esphome-icon-2048x1579-htac8rfa-300x231.png 300w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/esphome-icon-2048x1579-htac8rfa-768x592.png 768w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/esphome-icon-2048x1579-htac8rfa-1024x790.png 1024w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/esphome-icon-2048x1579-htac8rfa-1536x1184.png 1536w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/esphome-icon-2048x1579-htac8rfa.png 2048w\" sizes=\"(max-width: 350px) 100vw, 350px\" \/><\/p><p><strong>ESPHome is an open-source software that allows programming and configuration of devices based on <strong>ESP8266<\/strong> and <strong>ESP32<\/strong> microcontrollers to integrate them into the <strong>Home Assistant<\/strong> platform.<\/strong> It is a tool designed to facilitate the creation of smart IoT devices that can be easily controlled and monitored via Home Assistant.<\/p><p>ESPHome&#8217;s main features include: configuration via YAML, integration with Home Assistant, support for various modules, as well as automation and smart features.<\/p><p>\u00a0<\/p><p>\u00a0<\/p><p>\u00a0<\/p><h2>Preparation<\/h2><p>Before diving into creating smart mirror lighting using the ESP8266 and ESPHome, it&#8217;s a good idea to prepare properly. Below you will find the key steps to get your project started:<\/p><h3>Required equipment and components<\/h3><p>Make sure you have all the necessary materials:<\/p><ul><li><a href=\"https:\/\/botland.com.pl\/moduly-wifi-esp8266\/8241-modul-wifi-esp8266-nodemcu-v3-5904422300630.html\" target=\"_blank\" rel=\"noopener\">ESP8266<\/a> NodeMCU board (or <a href=\"https:\/\/botland.com.pl\/moduly-wifi-i-bt-esp32\/8893-esp32-wifi-bt-42-platforma-z-modulem-esp-wroom-32-zgodny-z-esp32-devkit-5904422337438.html\" target=\"_blank\" rel=\"noopener\">ESP32<\/a>, if you opt for a newer model),<\/li><li><a href=\"https:\/\/botland.com.pl\/przekazniki-przekazniki-arduino\/8463-modul-przekaznika-1-kanal-styki-10a250vac-cewka-5v-5904422300517.html\" target=\"_blank\" rel=\"noopener\">Relay module 1 channel<\/a> &#8211; contacts 10A\/250VAC &#8211; coil 5V<\/li><li><a href=\"https:\/\/botland.com.pl\/shelly-automatyka-domowa\/23103-shelly-plus-i4-4-kanalowy-kontroler-scen-wifi--3800235265079.html\" target=\"_blank\" rel=\"noopener\">Shelly i4<\/a> \/ i3 or other push-button module,<\/li><li>Power source for the ESP8266 board (5V DC) and for the light fixture (230V AC),<\/li><li><a href=\"https:\/\/botland.com.pl\/920-kostki-elektryczne\" target=\"_blank\" rel=\"noopener\">Wire connectors<\/a>,<\/li><li>The light holder in which we will install the plate,<\/li><li>Connection wires for all components.<\/li><\/ul><h3>Installing ESPHome in Home Assistant<\/h3><ul><li><strong>Install ESPHome<\/strong> in your Home Assistant environment to easily configure and manage the ESP8266. Use the <a href=\"https:\/\/esphome.io\/guides\/getting_started_hassio#installing-esphome-dashboard\" target=\"_blank\" rel=\"noopener\">ESPHome documentation<\/a> and follow the instructions.<\/li><\/ul><h3>Preparation of workspace<\/h3><ul><li>Organize a workspace where you will assemble the system. Make sure you have access to tools and are comfortable working on the project.<\/li><\/ul><h3>Health and safety of working with electric voltage<\/h3><p style=\"text-align: left;\">Electrical safety is key when working with electricity. Here are some important recommendations:<\/p><ul><li><strong>Power Off:<\/strong> Before any work on the circuit, turn off the power supply to avoid electric shock.<\/li><li><strong>Appropriate Tools:<\/strong> Use tools that are insulated and designed for electrical work &#8211; they should meet appropriate safety standards.<\/li><li><strong>Experience:<\/strong> Electrical installation work requires experience. If you are unsure of your skills, it is advisable to enlist the help of an experienced person.<\/li><li><strong>Eye and Hand Protection:<\/strong> Wearing eye and hand protection is recommended, especially when soldering and handling connections.<\/li><li><strong>Check the Power Supply:<\/strong> Make sure you know where the main power supply is and that it is off before taking any action.<\/li><li><strong>Knowledge of the Electrical System:<\/strong> Always verify that you know how an electrical system works. <strong>Do not take action blindly.<\/strong><\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-51f1c7b elementor-alert-danger elementor-widget elementor-widget-alert\" data-id=\"51f1c7b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"alert.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-alert\" role=\"alert\">\n\n\t\t\t\t\t\t<span class=\"elementor-alert-title\">Warning<\/span>\n\t\t\t\n\t\t\t\t\t\t<span class=\"elementor-alert-description\"><p>Remember that tampering with electrical installations can be dangerous, and if you are unsure of your skills, it is always a good idea to consult an electrician or an electrical specialist. electrical installations.<\/p>\n<\/span>\n\t\t\t\n\t\t\t\t\t\t<button type=\"button\" class=\"elementor-alert-dismiss\" aria-label=\"Dismiss this alert.\">\n\t\t\t\t\t\t\t\t\t<span aria-hidden=\"true\">&times;<\/span>\n\t\t\t\t\t\t\t<\/button>\n\t\t\t\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f26748d elementor-widget elementor-widget-text-editor\" data-id=\"f26748d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h2>Step 1 &#8211; VLAN IoT<\/h2><p>As a security practice, I recommend setting up a separate network for IoT devices, separate from the main home network. For this purpose, it is worth using the <strong>VLAN<\/strong> (<a href=\"https:\/\/pl.wikipedia.org\/wiki\/Wirtualna_sie%C4%87_lokalna\" target=\"_blank\" rel=\"noopener\">Virtual Local Area Network<\/a>) function, which allows physical separation of devices, such as those based on ESPHome, from other devices in the home infrastructure.<\/p><h3>Benefits<\/h3><p>Creating a dedicated network for IoT devices offers several advantages:<\/p><ul><li><strong>Security:<\/strong> Separating IoT devices from the main network haelps minimize the potential risk of attacks. If an IoT device is possibly compromised, access to the main home network is difficult.<\/li><li><strong>Controlling Communications:<\/strong> Creating a separate network allows for more precise control over who communicates with IoT devices and how. You can define communication rules that only allow specific devices (for example, a server or virtual machine from Home Assistant) to interact with IoT devices.<\/li><li><strong>Network Traffic Optimization:<\/strong> Separating IoT device traffic from main network traffic can help optimize network performance.<\/li><\/ul><h3>Implementation<\/h3><p>To implement such separation, it is worth consulting the documentation and settings of the router. In the case of Home Assistant, using the appropriate firewall rules on the router, you can customize access to IoT devices. This approach introduces a layer of additional security to our smart home infrastructure.<\/p><h2>Step 2 &#8211; Install and configure firmware to work with Home Assistant<\/h2><p>Once the ESPHome add-on is running on the Home Assistant server, it&#8217;s time to move on to adding the first ESPHome-based device.<\/p><h3>Connecting to a computer<\/h3><ul><li><strong>Connect the board using a USB cable to your computer.<\/strong> It is important to use a USB cable with data transmission, as many cheap cables only provide power.<ul><li>To be sure of correct operation, I recommend using <strong>Chrome<\/strong> or <strong>Edge<\/strong> browser (there is a transfer of data transmission through the COM port to the browser using WebSerial).<\/li><\/ul><\/li><\/ul><h3>Home Assistant<\/h3><ul><li>After completing these steps, log in to <strong>Home Assistant<\/strong>,<\/li><\/ul><p><img decoding=\"async\" class=\"aligncenter size-full wp-image-1258\" src=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-12.19.37.png\" alt=\"Home Assistant, login screen\" width=\"565\" height=\"622\" srcset=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-12.19.37.png 565w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-12.19.37-273x300.png 273w\" sizes=\"(max-width: 565px) 100vw, 565px\" \/><\/p><ul><li>From the side panel, go to the <strong>ESPHome<\/strong> tab,<\/li><li>Then click <strong>New Device<\/strong>,<\/li><\/ul><p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1262\" src=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-12.30.16.png\" alt=\"ESPHome, Button New device\" width=\"180\" height=\"67\" \/><\/p><ul><li><p>After selecting the option to add a new device, we may encounter a browser incompatibility message, especially for browsers that do not support WebSerial. Alternatively, we may also encounter a message indicating that there is no secure connection (HTTPS) to the dashboard. In this situation, we can click <strong>Continue<\/strong> to continue the process of adding the device.<\/p><\/li><\/ul><p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1260\" src=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-12.28.56.png\" alt=\"ESPHome, New device\" width=\"399\" height=\"477\" srcset=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-12.28.56.png 399w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-12.28.56-251x300.png 251w\" sizes=\"(max-width: 399px) 100vw, 399px\" \/><\/p><ul><li>In the next window, we enter a <strong>name for our device<\/strong> (it can be a name or alias we created) and <strong>the details of our Wi-Fi network<\/strong>.<ul><li>Wi-Fi network entry is only necessary when adding a device for the first time. Subsequent ESPHome-based additions will not require this step.<\/li><\/ul><\/li><li>Then, for ESPHome to install the firmware on the ESP8266 board, click Connect.<\/li><\/ul><p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1264\" src=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-12.35.53.png\" alt=\"ESPHome, Installation\" width=\"381\" height=\"335\" srcset=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-12.35.53.png 381w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-12.35.53-300x264.png 300w\" sizes=\"(max-width: 381px) 100vw, 381px\" \/><\/p><ul><li>After a while, the browser will display a window for selecting a device for serial port communication. Find your device, whose name should include <strong>CP210x UART<\/strong>, and click <strong>Connect<\/strong>.<\/li><li>Then wait until the firmware is installed on the board.<\/li><\/ul><h3>Completion of the process<\/h3><p>After a successful installation, you should receive a message confirming the completion of the process. Your device will also appear on the dashboard with the description <strong>ONLINE<\/strong>. This means that the board has been correctly configured and is ready to proceed.<\/p><h2>Step 3 &#8211; Upload the code to control the light in ESPHome<\/h2><div>In this section, we will now upload the appropriate entries for controlling the switching on and off of lights. Copy the necessary code elements into your installation.<\/div>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c317908 elementor-widget elementor-widget-mdp-coder-elementor\" data-id=\"c317908\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"mdp-coder-elementor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t        <!-- Start Coder for Elementor WordPress Plugin -->\n        <div\n            id=\"mdp-coder-c317908\"\n            class=\"mdp-coder-elementor-box\"\n            data-theme=\"mdp-theme-material-dark\"\n            data-dark-theme=\"mdp-theme-material-dark\"\n        >\n            \n                <pre class=\"language-yaml line-numbers copy-to-clipboard\"data-line=\"32-47\"data-previewers=\"\"><code># bath-mirror v 1.0 #\nesphome:\n  name: esp01-bath-mirror\n  friendly_name: esp01-bath-mirror\n\nesp8266:\n  board: esp01_1m\n\n# Enable logging\nlogger:\n\n# Enable Home Assistant API\napi:\n  encryption:\n    key: &quot;TUTAJ B\u0118DZIE WYGENEROWANY KOD PRZEZ ESPHOME&quot;\n\nweb_server:\n  port: 80\n\nota:\n  password: &quot;TUTAJ POJAWI SI\u0118&nbsp;WYGENEROWANE HAS\u0141O PRZEZ ESPHOME&quot;\n\nwifi:\n  ssid: !secret wifi_ssid\n  password: !secret wifi_password\n\ncaptive_portal:\n\n# OD TEGO MIEJSCA MO\u017bESZ SKOPIOWA\u0106 ZAWARTO\u015a\u0106 #\n# Ca\u0142y kod za\u0142\u0105czy\u0142em pogl\u0105dowo jak powinien wygl\u0105da\u0107 #\n\noutput:\n  - platform: gpio\n    pin: \n      number: GPIO14\n      mode:\n        output: &quot;True&quot;\n        open_drain: &quot;True&quot; \n    id: relay_1\n    inverted: true\n\nlight:\n  - platform: binary\n    name: &quot;O\u015bwietlenie lustra&quot;\n    output: relay_1\n    restore_mode: ALWAYS_OFF\n    id: light_1    <\/code><\/pre>\n                    <\/div>\n                <script>\n            \"use strict\";\n\n            \/** Handler when the DOM is fully loaded. *\/\n            let callback_c317908 = function() {\n\n                \/** Set theme for coder widget. *\/\n                function setTheme() {\n\n                    \/** Foreach Code Widget. *\/\n                    let coderBoxes = document.querySelectorAll( '.mdp-coder-elementor-box' );\n\n                    for ( let coderBox of coderBoxes ) {\n\n                        let lightTheme = coderBox.dataset.theme;\n                        let darkTheme = coderBox.dataset.darkTheme;\n\n                        coderBox.className = '';\n                        if ( window.matchMedia && window.matchMedia( '(prefers-color-scheme: dark)' ).matches ) {\n\n                            coderBox.className = 'mdp-coder-elementor-box ' + darkTheme;\n\n                        } else {\n\n                            coderBox.className = 'mdp-coder-elementor-box ' + lightTheme;\n\n                        }\n\n                    }\n\n                }\n                setTheme();\n\n\n                \/** Watch for changes color-scheme. *\/\n                window.matchMedia(\"(prefers-color-scheme: dark)\").addListener( function() {\n                    setTheme();\n                } );\n\n                \n                if ( typeof Prism !== 'undefined' ) {\n\n                    Prism.plugins.autoloader.languages_path = 'https:\/\/chochol.io\/wp-content\/plugins\/coder-elementor\/js\/prism\/components\/';\n                    Prism.highlightAll();\n                    Prism.fileHighlight();\n\n                }\n\n                \n            };\n\n            if (\n                document.readyState === \"complete\" ||\n                ( document.readyState !== \"loading\" && !document.documentElement.doScroll )\n            ) {\n                callback_c317908();\n            } else {\n                document.addEventListener( \"DOMContentLoaded\", callback_c317908 );\n            }\n\n        <\/script>\n                <!-- End Coder for Elementor WordPress Plugin -->\n\n        \t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8cbae35 elementor-widget elementor-widget-text-editor\" data-id=\"8cbae35\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<ul><li>We are waiting for the software to be compiled and uploaded to the board. If the installation process is successful, you will see similar information about your device as in the attached screenshot.<\/li><\/ul><p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1280\" src=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-16.47.25-1.png\" alt=\"ESPHome, Logs information\" width=\"696\" height=\"720\" srcset=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-16.47.25-1.png 696w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-16.47.25-1-290x300.png 290w\" sizes=\"(max-width: 696px) 100vw, 696px\" \/><\/p><h2>Step 4 &#8211; Connect all components to the board and install the code on the board<\/h2>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-578306d elementor-widget elementor-widget-image\" data-id=\"578306d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Add-a-little-bit-of-body-text.png\" data-elementor-open-lightbox=\"yes\" data-elementor-lightbox-title=\"ESP8266 Lamp, Connection Diagram\" data-e-action-hash=\"#elementor-action%3Aaction%3Dlightbox%26settings%3DeyJpZCI6MTI3MSwidXJsIjoiaHR0cHM6XC9cL2Nob2Nob2wuaW9cL3dwLWNvbnRlbnRcL3VwbG9hZHNcLzIwMjRcLzAxXC9BZGQtYS1saXR0bGUtYml0LW9mLWJvZHktdGV4dC5wbmcifQ%3D%3D\">\n\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"432\" src=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Add-a-little-bit-of-body-text-768x432.png\" class=\"attachment-medium_large size-medium_large wp-image-1271\" alt=\"Wiring diagram: ESP8266 (GPIO14) drives 5V relay module; phase and neutral lamp connections to terminals\" srcset=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Add-a-little-bit-of-body-text-768x432.png 768w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Add-a-little-bit-of-body-text-300x169.png 300w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Add-a-little-bit-of-body-text-1024x576.png 1024w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Add-a-little-bit-of-body-text-1536x864.png 1536w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Add-a-little-bit-of-body-text.png 1920w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/>\t\t\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f2fd8f4 elementor-widget elementor-widget-text-editor\" data-id=\"f2fd8f4\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Remember to perform these activities with the highest standards of electrical safety. Ensure that all connections are properly secured and comply with local electrical codes.<\/p><ul><li><strong>Connect quick-connect electrical connectors:<\/strong><ul><li>Connect the phase and neutral wires to the quick-connect electrical connectors. These connectors will serve as a power distribution point. <strong>Note:<\/strong> Do not connect the connectors to the voltage yet.<\/li><\/ul><\/li><li><strong>Connect the power supply to the inverter:<\/strong><ul><li>From the quick-connectors, run power to the inverter, which converts the voltage from 230V AC to 5V DC. This step is essential because it provides the proper power supply for the ESP8266 board.<\/li><\/ul><\/li><li><strong>Powering the ESP8266 board:<\/strong><ul><li>From the ESP8266 board, lead the 5V DC power wires from the inverter. You can connect the board&#8217;s power supply to the microUSB connector.<\/li><li>Also run a communication wire from the ESP8266 to the relay, which will be used to control the lighting.<\/li><\/ul><\/li><li><strong>Connecting a light socket:<\/strong><ul><li>From the light fixture, lead the neutral wire to the quick-disconnect<\/li><\/ul><\/li><li><strong>Connecting the relay:<\/strong><ul><li>Route the phase wire from the quick-connect to the relay,<\/li><li>Connect the phase wire to the COM connector of the relay,<\/li><li>From the relay, from the NO connector, run a wire to the light fixture.<\/li><\/ul><\/li><li><strong>Make sure all connections are properly secured:<\/strong><ul><li>Check that the contacts of the plates do not touch the metal (possible) parts of the light fixture.<\/li><\/ul><\/li><li><strong>Connect the installation to the power supply:<\/strong><ul><li>Wait for the ESP8266 board to connect to your Wi-Fi network.<\/li><\/ul><\/li><\/ul><p>Now we will proceed to add the new device to the integration section of <strong>Home Assistant<\/strong>.<\/p><h2>Step 5 &#8211; Reverse proxy on Synology using Nginx Proxy Manager<\/h2><p>Do you use Synology and want to improve access to your Home Assistant server? Here&#8217;s a quick step-by-step guide on how to set up a login using a domain name and subdomain, such as ha.xyz.com, instead of entering an IP address. You can achieve all this with Docker Compose in the Portainer.<\/p><p>\ud83d\udc49 <a href=\"https:\/\/chochol.io\/en\/hardware\/synology-free-ports-80-443-for-nginx-proxy-manager\/\" target=\"_new\">Check out step 1 now<\/a> and get your environment ready for more improvements!<\/p><p>Thus, by using a domain name instead of an IP address, you simplify the process of logging into your Home Assistant server on Synology.<\/p><h2>Step 6 &#8211; Adding a device to Home Assistant<\/h2><ul><li>In the Home Assistant notification section, you should see that our home automation server has detected a new device,<\/li><li>Go to <strong>Settings<\/strong>, then to <strong>Integrations and Devices<\/strong>.<\/li><li>The new device will bear a blue border. <strong>We approve the new device for integration<\/strong>.<\/li><li><strong>Set the area<\/strong> where the device will be located. In our case, it will be the <strong>Bathroom<\/strong>.<\/li><li><strong>Congratulations!<\/strong> You have reached this stage, which means that you have successively gone through the configuration process. To check the operation of the new device, you can directly go to it and control the light from the Home Assistant. \ud83d\ude80<\/li><\/ul><p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1282\" src=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-17.09.34.png\" alt=\"Home Assistant, Device Control\" width=\"336\" height=\"338\" srcset=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-17.09.34.png 336w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-17.09.34-150x150.png 150w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-17.09.34-298x300.png 298w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-17.09.34-60x60.png 60w\" sizes=\"(max-width: 336px) 100vw, 336px\" \/><\/p><h2>Step 7 &#8211; Activate the light at the mirror with Shelly i3 \/ i4<\/h2><h3>The history of renovation: a lesson on lighting in the bathroom<\/h3><p>Often, when renovating our first apartment, we overlook certain aspects that may be important in the future. In my case, it was the lighting of the bathroom, where I had only two wires fed as two sections of lighting. The lighting in the bathroom was controlled by a button next to the door, which created some limitations.<\/p><p>The plan was to have a ceiling light, a light under the tub and a light by the mirror. The problem arose when the under bath and mirror lights were connected to one section, making it impossible to switch on the light over the bath and the ceiling light at the same time. This was due to the additional requirement to turn on the light above the mirror. Bravo me! \ud83d\ude05<\/p><p>The solution was found at the mirror, where there were two independent electrical wires with two boxes. They have become the key element for the light actuation configuration at the mirror, described below.<\/p><h3>Supporting lighting at the mirror with Shelly i3<\/h3><p>At this stage, I decided to simplify my life by configuring the light activation at the mirror with the Shelly i3 button. This allowed me to avoid juggling the app on my phone and instead start using the convenient button located right next to the mirror.<\/p><h3>Shelly i3 installation<\/h3><p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1284\" src=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/image-20220912-080340.png\" alt=\"Shelly i3, connection diagram\" width=\"500\" height=\"369\" srcset=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/image-20220912-080340.png 900w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/image-20220912-080340-300x222.png 300w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/image-20220912-080340-768x567.png 768w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/image-20220912-080340-110x80.png 110w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/p><ul><li>Install the Shelly i3 scene activator in the box based on the diagram included in the device manual,<\/li><li>Set the password, configure the descriptions on the device, and then connect the device to Home Assistant.<\/li><\/ul><p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1286\" src=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-17.30.43.png\" alt=\"Home Assistant, Shelly Bathroom\" width=\"800\" height=\"682\" srcset=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-17.30.43.png 1007w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-17.30.43-300x256.png 300w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-at-17.30.43-768x655.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p><h3>Setting up automation<\/h3><ul><li>Go to <strong>Settings<\/strong>, then <strong>Automations and Scenes<\/strong>,<\/li><li>In the lower right corner, click <strong>Create Automation<\/strong> and then <strong>Create New Automation<\/strong> (Start from the beginning with an empty automation),<\/li><li>The scheme should look as follows:<ul><li><strong>When:<\/strong><ul><li>Device: <strong>Button in the bathroom<\/strong> (or as we&#8217;ll call it, our tile from Shelly)<\/li><li>Trigger: <strong>the first button will be pressed one at a time<\/strong>.<\/li><\/ul><\/li><li><strong>Perform:<\/strong><ul><li>Device: <strong>Mirror lighting<\/strong> (or as we&#8217;ll call it, our ESP board)<\/li><li>Trigger: <strong>Toggle Mirror Lighting<\/strong><\/li><\/ul><\/li><\/ul><\/li><li>Save the automation, name it, for example: <strong>Bathroom, button 1<\/strong>.<\/li><li><strong>Done! \ud83d\ude80<\/strong><\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2e3ad46 elementor-widget elementor-widget-image\" data-id=\"2e3ad46\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t<figure class=\"wp-caption\">\n\t\t\t\t\t\t\t\t\t\t\t<a href=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/IMG_5491-scaled.jpeg\" data-elementor-open-lightbox=\"yes\" data-elementor-lightbox-title=\"Bathroom, button with Shelly i3\" data-e-action-hash=\"#elementor-action%3Aaction%3Dlightbox%26settings%3DeyJpZCI6MTI4OSwidXJsIjoiaHR0cHM6XC9cL2Nob2Nob2wuaW9cL3dwLWNvbnRlbnRcL3VwbG9hZHNcLzIwMjRcLzAxXC9JTUdfNTQ5MS1zY2FsZWQuanBlZyJ9\">\n\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"576\" src=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/IMG_5491-768x576.jpeg\" class=\"attachment-medium_large size-medium_large wp-image-1289\" alt=\"In-wall SIMON control panel with touch switch and socket cover, marked IP44, mounted on concrete wall\" srcset=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/IMG_5491-768x576.jpeg 768w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/IMG_5491-300x225.jpeg 300w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/IMG_5491-1024x768.jpeg 1024w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/IMG_5491-1536x1152.jpeg 1536w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/IMG_5491-2048x1536.jpeg 2048w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/>\t\t\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t\t\t\t<figcaption class=\"widget-image-caption wp-caption-text\">For frames and components for sockets and switches, I chose products from Kontakt Simon, 82 Detail series (white, wood base).<\/figcaption>\n\t\t\t\t\t\t\t\t\t\t<\/figure>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-095f810 elementor-widget elementor-widget-text-editor\" data-id=\"095f810\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h2>Read also<\/h2><ul><li><strong>Are you already using Authentik and Portainer?<\/strong> Learn how to set up single sign-on to easily and securely log in to Portainer. Read the simple <a href=\"https:\/\/chochol.io\/en\/software\/authentik-single-sign-on-configuration-for-portainer\/\">guide here<\/a> to make these applications more convenient to use.<\/li><li>Discover how easy it is to install the <strong>ADS-B receiver on a Raspberry Pi<\/strong> and start tracking flights in real time. Read <a href=\"https:\/\/chochol.io\/en\/hardware\/ads-b-receiver-installation-and-configuration-on-raspberry-pi\/\">here a simple guide<\/a> that will open up the fascinating world of sky observation!<\/li><li>Immerse yourself in the world of vehicle monitoring with <strong>Traccar on your Synology<\/strong>! <a href=\"https:\/\/chochol.io\/en\/software\/traccar-docker-installation-guide-on-synology\/\">A step-by-step guide<\/a> along with the use of Docker will enable you to install it quickly and efficiently. Track your vehicles, analyze the data and control the route.<\/li><\/ul><h2>Additional materials and information<\/h2><p>For further exploration and more information, I recommend checking out the links below. They are valuable sources that were used in the development of this guide.<\/p><ul><li>Getting Started with ESPHome and Home Assistant: <a href=\"https:\/\/esphome.io\/guides\/getting_started_hassio#installing-esphome-dashboard\" target=\"_blank\" rel=\"noopener\">https:\/\/esphome.io\/guides\/getting_started_hassio#installing-esphome-dashboard<\/a><\/li><\/ul><h4 class=\"p1\">How about Shelly or Sonoff in that case?<\/h4><p class=\"p1\">It is worth mentioning the ready-made solutions available on the market, such as <a href=\"https:\/\/www.shelly.com\/en\" target=\"_blank\" rel=\"noopener\"><span class=\"s1\">Shelly<\/span><\/a> or <a href=\"https:\/\/sonoff.tech\/\" target=\"_blank\" rel=\"noopener\"><span class=\"s1\">Sonoff<\/span><\/a>. These products offer simple integration, making them ideal for those looking for a quick and easy solution to smart lighting. Devices from them are available in different variants, allowing you to choose the best fit for your specific needs.<\/p><p class=\"p1\">Although my approach is based on DIY using ESP8266, it&#8217;s worth considering off-the-shelf products, especially if you want a quick implementation. The final choice depends on the user&#8217;s preferences, the complexity of the project and the degree of control expected over the functionality of the lighting. Many home automation enthusiasts will find benefits in both off-the-shelf products and microcontroller-based projects tailored to their own needs and creativity.<\/p><h4 class=\"p1\">Why ESP8266 and not ESP32?<\/h4><p class=\"p3\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1247 alignright\" src=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/1666364456Esp32_devkitc_v4-e1704993000544.png\" alt=\"ESP32, board\" width=\"401\" height=\"198\" srcset=\"https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/1666364456Esp32_devkitc_v4-e1704993000544.png 600w, https:\/\/chochol.io\/wp-content\/uploads\/2024\/01\/1666364456Esp32_devkitc_v4-e1704993000544-300x148.png 300w\" sizes=\"(max-width: 401px) 100vw, 401px\" \/>In choosing an ESP8266 board, it is not always only the technical parameters that determine the choice. In my case, <strong>the ESP8266 was on hand<\/strong>, which greatly accelerated the start of the project. However, it&#8217;s important to note that there&#8217;s nothing preventing you from using a newer board, such as the <a href=\"https:\/\/www.espressif.com\/en\/products\/socs\/esp32\" target=\"_blank\" rel=\"noopener\"><span class=\"s1\">ESP32<\/span><\/a>, if you have one on hand. The ESP32 offers <strong>more processing power, more I\/O pins<\/strong>, and additional features, which can be beneficial in more advanced projects. It is worth adjusting the choice of tile according to the specifics of the project and the availability of available resources. So the choice between the ESP8266 and newer models depends on individual needs, hardware availability and the range of functions we want to achieve in our project.<\/p><p class=\"p3\">While it&#8217;s true that we don&#8217;t need much computing power to light a mirror, it&#8217;s worth noting that the ESP32 offers more resources that can be useful for more complex projects. However, for simple applications such as our mirror lighting, the <strong>ESP8266 is an ideal choice<\/strong> &#8211; it is <strong>compact<\/strong>, <strong>economical<\/strong> and <strong>meets our specific requirements<\/strong>.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Set up simple mirror lighting with ESPHome in Home Assistant. Discover simple integration and control light with ease.<\/p>\n","protected":false},"author":1,"featured_media":1234,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[86],"tags":[136,138,139,135,141],"class_list":["post-1303","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-smart-home","tag-diy","tag-esphome","tag-home-assistant","tag-home-automation","tag-iot"],"_links":{"self":[{"href":"https:\/\/chochol.io\/en\/wp-json\/wp\/v2\/posts\/1303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chochol.io\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chochol.io\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chochol.io\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chochol.io\/en\/wp-json\/wp\/v2\/comments?post=1303"}],"version-history":[{"count":0,"href":"https:\/\/chochol.io\/en\/wp-json\/wp\/v2\/posts\/1303\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/chochol.io\/en\/wp-json\/wp\/v2\/media\/1234"}],"wp:attachment":[{"href":"https:\/\/chochol.io\/en\/wp-json\/wp\/v2\/media?parent=1303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chochol.io\/en\/wp-json\/wp\/v2\/categories?post=1303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chochol.io\/en\/wp-json\/wp\/v2\/tags?post=1303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}