Home Automation Using the Sonoff S26 Smart Socket
The most common devices around your home may not have smart capabilities and sometimes, you might simply want to switch them ON/OFF at predetermined times. In this post, we take at one popular solution that uses the Sonoff S26 smart socket that is based on the ESP8266.
Since it does not work with ESPHome out of the box, we will take it apart, flash new firmware to it and configure it within ESPHome. From there, you will be able to push future updates wirelessly, using the OTA feature.
Step 1: Watch the Video
Take a moment to watch the video above as it goes over the entire process and also shows you why it is better for you to use an off the shelf module like the Sonoff S26 instead of building your own – mainly for safety reasons.
Step 2: Enable ESPHome Compatibility
In order to make it compatible with ESPHome, we need to update its firmware. We first need to obtain this firmware which is also called a binary file so open up ESPHome and start by creating a new node. Give it a useful name, select the default board option which is “Generic ESP8266 (for example Sonoff)”, and finally, add your WiFi details to complete the setup.
Next up, add the following line to the configuration file, as seen in the image.
You can also use the following link to view the complete configuration, as shown in the video:
Once done, use the wiring diagram to connect a 3.3V USB to serial converter to the PCB. Please make sure the USB to serial converter is set to 3.3V or else you will damage the ESP8266 chip.
You then need to press and hold the switch on the PCB while you connect the USB to serial converter to your computer. Make sure the LED on the PCB does not flash, if it does, then you need to unplug the USB to serial converter power, press and hold the switch down and try again.
Finally, you need to open up the ESPHome flasher tool, select the serial port, binary file and then flash it to the board. Give it a minute to complete and once done, restart the board by disconnecting the power from the USB to serial converter and then plugging it back again. The board will now connect to your WiFi network and you will be able to view its status as being online under ESPHome. Any future updates will be able to be made using OTA updates.
Step 3: Add Support for Relay & Button
Now that the S26 is showing up in ESPHome, we need to add support for the relay and control button. This can be done by updating its configuration.
Use the link above to view the final configuration and copy the last section from “binary_sensor” onwards. Paste it in the node configuration file and then hit the upload button to update the node wirelessly. It will automatically update it and the node will then be back up online again after a few seconds. You can now disconnect the USB to serial converter from the PCB and close everything together so that we can test it with mains power.
Step 4: Add Controls
The final step is adding the control entities to the dashboard. Navigate to Configuration->Integrations and click the node name that you had given. Now, click the device that shows up to view all the entities that it contains.
Click the button at the bottom to add all the entities to the dashboard, which is also called Lovelace. Follow the on-screen instructions to complete this and you are good to go.
Connect a suitable device to the unit and then use the dashboard to control it. You can also press the button on the S26 module to manually control the device as needed.