Morning/evening and day/night smart socket

This project is to make a combined morning/evening and day/night timer from a commercial dual smart socket . I am using the Elworks CLY809M-GE dual smart socket, equivalent to the Nedis WIFIP141FWT. The modifications include hardware changes and the use of a piece of home made software. One of the dual socket outputs works as a morning/evening timer and the second output works as a day/night timer. The software includes a fixed table for the daily sunrise/sunset time values specifically for the geo location of our home. The scheduling for Output #1 takes place like this:

The time values for start and end are set up via the embedded webpage for the dual socket. The scheduling for Output #2 working as a day timer takes place like this:

The add.min option (0..60 minutes) is to extend the ON period to include a bit extra time ahead of dawn and after dusk !. ½ the value of add.min is subtracted from sunrise, and ½ the value of add.min is added to sunset. The selection af day/night and the time value for add.min is set up via the embedded webpage for the dual socket. The scheduling for Output #2 working as a night timer takes place like this:

The add.min option (0..60 minutes) is to extend the ON period to include a bit extra time ahead of dusk and after dawn !. ½ the value of add.min is added to sunrise, and ½ the value of add.min is subtracted from sunset. The selection af day/night and the time value for add.min is set up via the embedded webpage for the dual socket.

After an initial setup via wifi, the time scheduling continues, even though the wifi drops out . This feature is not applicable to a Tuya or Home assistant solution, as far as I know.

Pros: +No cloud connection. +Builtin sunrise/sunset time tables. +Setup via the dual socket embedded webpage.

Cons: -Wifi is needed for setup. -After a mains power-out, an internet connection is needed via wifi to request the NTP (Network Time Protocol).

The CPU/wifi module is to be replaced and to do this, the housing need to opened. Use a set of wood clamps and a knife to part separate the bottom and top parts:

Next step is to separate the PCB from the bottom part. I used a solder gun a solder wick to remove solder from neutral wire connection close to the PCB, and the connections for the mains pins, live and neutral :

The Tuya CB2S CPU/wifi module is the blue PCB with the QR code on the left image above. In case you want to keep the Tuya CB2S module for use with Home assistant via MQTT, you can flash the module with the Tasmota a-like OpenBK firmware. I made a description here: Elektroda-Elworks .

However, for this project , the CB2S module is removed and is the ESP8685-wroom-03 module will be used instead.

The ESP8685-wroom-03 module needs 5 connections to be flashed with firmware: 3V3, GND, RX, TX and IO9. I used the ESP 01S programmer to provide power, RX and TX. IO9 is a flash-enable pin , and is put to GND during the few seconds it takes to connect the programmer to the PC USB port ahead of flashing.

As RX, TX and IO9 are connected via small solder pads on the modules rear side, I soldered 3 wires to the solder pads before mounting the ESP8685-wroom-03 into the dual socket PCB. Here is the module  soldered in place with the 5 wires to be connected to the programmer:

I made the software with Arduino IDE , that includes a lot of libraries and it can flash the binary files directly to the target. The ESP8685-wroom-03 module has the powerful ESP32-C3 CPU/wifi unit onboard, so this one is selected in the Arduino IDE. The ESP32 libraries for Arduino must downloaded first.! Due to the wiring, the port speed for the serial flashing is set to 115200 bps.:

The software for this project include a captive portal to setup the wifi parameters for the LAN , a small DNS service ( so you dont need to remember the IP address ).   After a successful flashing, the wires on rear side ( IO9, RX, TX ) must be removed.

To setup the wifi SSID and password for the local LAN: Connect 3V3 and GND to the red and black flash wires to power the PCB. The blue LED at the setup button blinks, press the setup button for a few seconds, and the blue LED now makes short blinks to indicate an active captive portal:

Use the admin page of your LAN router to lookup the DCHP IP address of the dual socket, or goto the URL: http://altan_timer.local:8058 (the mDNS name and http_Port is defined in the software). The small embedded webpage will show up:

Doing the setup once, the scheduling will take place even though the wifi drops out or disappears.

Last is to remove the 3V3 and GND wires, mount the PCB to bottom housing part, and to solder the mains supply pins ( Live, neutral and earth ) back in place and finally glue the bottom and top parts. I used super glue to fix the parts together: