{"id":15163220,"url":"https://github.com/berg0162/s3-switch","last_synced_at":"2026-01-20T00:41:14.825Z","repository":{"id":190345065,"uuid":"682424901","full_name":"Berg0162/S3-Switch","owner":"Berg0162","description":"Smart Solar Surplus Switch","archived":false,"fork":false,"pushed_at":"2023-09-15T09:59:39.000Z","size":4212,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-08T08:19:49.674Z","etag":null,"topics":["esp32s3","esp8266","lilygo-tdisplay-s3","smart-switch","solar-energy","sonoff-basic","surplus"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Berg0162.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-08-24T06:28:34.000Z","updated_at":"2023-09-14T07:58:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"b507c12c-8604-4359-8847-7789a05f209f","html_url":"https://github.com/Berg0162/S3-Switch","commit_stats":{"total_commits":92,"total_committers":1,"mean_commits":92.0,"dds":0.0,"last_synced_commit":"b358c0aae54f2afdffd43e14b79808d281248acd"},"previous_names":["berg0162/s3-switch"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Berg0162%2FS3-Switch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Berg0162%2FS3-Switch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Berg0162%2FS3-Switch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Berg0162%2FS3-Switch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Berg0162","download_url":"https://codeload.github.com/Berg0162/S3-Switch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247801160,"owners_count":20998339,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["esp32s3","esp8266","lilygo-tdisplay-s3","smart-switch","solar-energy","sonoff-basic","surplus"],"created_at":"2024-09-27T02:21:29.689Z","updated_at":"2026-01-20T00:41:14.787Z","avatar_url":"https://github.com/Berg0162.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# S3-Switch \u0026nbsp;\u0026nbsp;Smart-Solar-Surplus-Switch\nIn Europe many households are equiped with modern meters (a.k.a. smart meters) for billing the energy consumption without human interference. These smart meters send readings to the energy supplier automatically but they also have a P1 port that gives you access to all measured energy data.\nThe present project uses a commercial device to read constantly this P1 port: [Homewizard P1 Meter](https://www.homewizard.com/p1-meter/). This P1 Meter is compatible with most modern meters in Europe.\u003c/br\u003e\n\nIt becomes even more interesting when your solar panels are involved in the energy equasion. The Homewizard P1 meter is able to monitor and record the energy management of the household at any moment in time. That includes the solar energy sent from the inverter back into the power grid with revenue grade accuracy. The total energy consumption is the basis of the utility bills from the energy supplier(s) every month. One wants a maximum benefit of the solar energy for good reasons!\u003c/br\u003e\n\nThe net power is the difference between the power the household is importing from and the power the inverter exports to the utility grid at any moment in time. When the net power is negative the export (solar production) exceeds the import of power and you might want to switch on extra electric appliances (like a battery charger, kitchen boiler or something else) to have maximum benefit of the solar surplus power. A smart switch with exactly that capabibilty would come in very handy! No doubt commercial parties (like [Homewizard](https://www.homewizard.com/energy-plus/)) offer this service but always at a recurring pricing model and a security compromise...\u003c/br\u003e\n\n## Homewizard WiFi P1 meter API \u003c/br\u003e\nHomewizard should be praised for their openness with respect to the well documentated access to the P1 Meter!\u003c/br\u003e\n[Get started with the Homewizard API](https://homewizard-energy-api.readthedocs.io/index.html)\u003c/br\u003e\n\nThe present project created 2 instances of a \u003cb\u003eSmart-Solar-Surplus-Switch\u003c/b\u003e that share most of the software but differ in the selected electronic components:\n## 1 S3-Switch with LilyGo ESP32S3 T-display\nThis board and ESP32S3 processor was selected for its excellent specifications and crisp display. Aside of gaining experience with the [TFT_eSPI](https://github.com/Bodmer/TFT_eSPI) library, creating a nice visual user interface was a dominant incentive. A lot of inspiration and practical knowledge was obtained by studying on Youtube: [the Volos Projects](https://www.youtube.com/c/VolosProjects). This ended up in a good working and visually attractive S3-Switch but definitively not the most cost-effective or simple solution to build! The solution works in the living space (as a \"green\" charging point) rather than hidden under the kitchen sink!\n\n## 2 S3-Switch with Sonoff Basic R2 (ESP8266)\nThe Sonoff was selected for its very low cost, ready for-the-purpose-package, is meant to be hacked and to upload/flash custom firmware. It ended up as the reliable S3-Switch workhorse that is tucked away aside the fuse box...\u003cbr\u003e\n\n## Arduino IDE 2.2\nThe present code is developed on Arduino IDE 2.2. Notice that you will need for each of these processors (\u003cb\u003eESP32S3\u003c/b\u003e and/or \u003cb\u003eESP8266\u003c/b\u003e) an Arduino IDE that is tailored for the specific type!\u003cbr\u003e\n\n# 1 S3-Switch with ESP32S3-T-display\n\n## 1.0 Before you start\nPlease follow the installation instructions for the [ESP32S3 T-display](https://github.com/Xinyuan-LilyGO/T-Display-S3)\u003cbr\u003e\nIf you select in the menu bar of Arduino IDE 2.2 \u003cb\u003eTools\u003c/b\u003e, the settings for the \u003cb\u003eESP32S3\u003c/b\u003e processor and the project are the following:\n\u003cp align=center\u003e\n\u003cimg src=\"https://github.com/Berg0162/s3-switch/blob/main/images/LilyGO_ESP32S3_Tools_Settings.png\" width=\"350\" height=\"400\" alt=\"S3-Switch\"\u003e\n\u003c/p\u003e\n\u003cbr clear=\"left\"\u003e\n\n## 1.1 Electronic Components \u003c/br\u003e\n### LilyGo ESP32S3 T-display\u003cbr\u003e\n\u003cimg src=\"https://github.com/Berg0162/s3-switch/blob/main/images/T-DISPLAY-S3.jpg\" align=\"left\" width=\"500\" height=\"500\" alt=\"S3-Switch\"\u003e\nLilyGo T-Display-S3 is an ESP32-S3 development board. It is equipped with a color 1.9\" LCD screen (170*320) and two programmable buttons. Communication with the display is using an I8080 interface. Its overall size has the same layout as the T-Display. The ESP32S3 allows for USB communication and can be programmed in the Arduino Integrated Development Environment (IDE).\u003cbr\u003e\n\nSee for specifications, installation and setup: [LilyGo ESP32S3 T-display](https://github.com/Xinyuan-LilyGO/T-Display-S3)\n\u003cbr clear=\"left\"\u003e\n\n### 5V Relay 1-Channel High-active or Low-active\u003c/br\u003e\n\u003cimg src=\"https://github.com/Berg0162/s3-switch/blob/main/images/relay high low active 1 channel-600x600h.jpg\" align=\"left\" width=\"200\" height=\"200\" alt=\"S3-Switch\"\u003e\n\nSpecifications:\u003cbr\u003e\n- Supply voltage: 5V DC\n- Signal voltage: 3.3-5V\n- Maximum voltage through relay: 250V AC or 110V DC\n- Resistive load: 10A (125V AC), 7A (240V AC) or 7A (28V DC)\n- Inductive load: 3A (120V AC) or 3A (28V DC)\n- Status led shows relay switched ON or OFF\n  \nPinout:\u003cbr\u003e\n- DC+: 5V supply voltage\n- DC-: Ground/GND\n- IN: Signal pin\n- NO: Relay normally open\n- COM: Relay common\n- NC: Relay normally closed\n\u003cbr clear=\"left\"\u003e\n\n### PCB Power supply\u003c/br\u003e\n\u003cimg src=\"https://github.com/Berg0162/s3-switch/blob/main/images/hi-link-pcb-power-supply-5vdc-1a-hlk-5m05-front-side-600x600.jpg\" align=\"left\" width=\"200\" height=\"200\" alt=\"S3-Switch\"\u003e \n\nSpecifications:\u003cbr\u003e\n- Input voltage (AC pins): 100 - 240V AC (recommended), 90 - 264V AC (maximum)\n- Output voltage (+Vo and -Vo pins): 5V DC\n- Maximum output current: 1000mA (continuous)\n- Voltage control:  ±0.2%\n- Load regulation:  ±0.5%\n- Exit ripple: \u003c70mV\n\u003cbr clear=\"left\"\u003e\n\n## 1.2 Circuitry and physical setup\u003c/br\u003e\n\u003cimg src=\"https://github.com/Berg0162/s3-switch/blob/main/images/Circuitry.jpg\" width=\"820\" height=\"461\" ALIGN=\"left\" alt=\"S3-Switch\"\u003e\n\u003cbr clear=\"left\"\u003e\n\n\u003e[!WARNING] \n\u003eSome components are connected to 220 Volt AC mains, you really need to know what you are doing since this can be potentially dangerous!\n\n\u003cimg src=\"https://github.com/Berg0162/s3-switch/blob/main/images/113236.jpg\" width=\"620\" height=\"440\" ALIGN=\"left\" alt=\"S3-Switch\"\u003e\u003c/br\u003e\n\u003cbr clear=\"left\"\u003e\n\n\u003cimg src=\"https://github.com/Berg0162/s3-switch/blob/main/images/093314.jpg\" width=\"492\" height=\"536\" ALIGN=\"left\" alt=\"S3-Switch\"\u003e\u003c/br\u003e\n\u003cbr clear=\"left\"\u003e\n\n## 1.3 Functionality\n\u003cimg src=\"https://github.com/Berg0162/s3-switch/blob/main/images/093440.jpg\" width=\"315\" height=\"453\" ALIGN=\"left\" alt=\"S3-Switch\"\u003e\n\n- Connects to your local WiFi network (you have to supply SSID and its Passphrase)\n- Will autodetect the Homewizard P1 Meter on the same network and connects to it. Every 5 seconds it will poll for new info.\n- Displays actual time retrieved from Internet\n- Displays Switch Status in addition to the Led status of the Relay board\n- Displays Net Power in digits and gauge presentation (surplus: green CCW and consumption: brown CW)\n- Switches the relay ON when Net Power reaches more than or equal -500 kW surplus (value of your choice)\n- Allows for 4 fixed clock switch moments (and duration) independent of Net Power level, visible in the display (red blocks)\n- Displays time intervals when the smart switch was activated (green ribbon)\n- Has a builtin simple webserver for local access to show status and edit remotely clock switch moments and duration\n- Point a browser to the local fixed IP address: \u003cb\u003e192.168.2.100\u003c/b\u003e or to: \u003cb\u003eesp32s3.local\u003c/b\u003e \n\u003cbr clear=\"left\"\u003e\n\n# 2 S3-Switch with Sonoff ESP8266\n\n## 2.0 Before you start\n\nPlease follow the installation instructions for the [ESP8266 processor](https://arduino-esp8266.readthedocs.io/en/latest/installing.html)\u003cbr\u003e\nIf you select in the menu bar of Arduino IDE 2.2 \u003cb\u003eTools\u003c/b\u003e, the settings for the \u003cb\u003eESP8266\u003c/b\u003e processor and the project are the following:\n\u003cp align=center\u003e\n\u003cimg src=\"https://github.com/Berg0162/s3-switch/blob/main/images/Sonoff_ESP8266_Tools_Settings.jpg\" width=\"500\" height=\"500\" alt=\"S3-Switch\"\u003e\n\u003c/p\u003e\n\u003cbr clear=\"left\"\u003e\n\n## 2.1 Electronic Components \u003c/br\u003e\n### Sonoff Basic R2\n\u003cimg src=\"https://github.com/Berg0162/s3-switch/blob/main/images/094905.jpg\" width=\"416\" height=\"554\" ALIGN=\"left\" alt=\"S3-Switch\"\u003e\u003c/br\u003e\nSpecifications:\u003cbr\u003e\n\n- Voltage range: 90-250V AC (50/60Hz)\n- Max current: 10A\n- Max. Power: 2200W\n- WiFi chip: ESP8266 or ESP8285\n- Dimensions: 91\\*43\\*25mm (l\\*b\\*h)\n- Wireless standard: 802.11 b/g/n\n- Security mechanism: WPA-PSK/WPA2-PSK\n- Working temperature: 0ºC-40ºC\n\nSee the following page for more information about this product: [Sonoff Basic R2 - WiFi Switch - ESP8266/ESP8285](https://sonoff.tech/product/diy-smart-switches/basicr2/)\n\u003cbr clear=\"left\"\u003e\n### CP2102 USB UART Board\u003cbr\u003e\n\nThe CP2102 USB UART Board (type A) is an accessory board that features the single-chip USB to UART bridge CP2102 onboard.\nThe board used in the project is from manufacturer: [Waveshare](https://www.waveshare.com/CP2102-USB-UART-Board-type-A.htm)\u003cbr\u003e\nThis board is only used to flash/upload new firmware to the Sonoff. It can afterwards be disconnected and will only serve again when you need to update the firmware.\n\n\u003cimg src=\"https://github.com/Berg0162/s3-switch/blob/main/images/FTDI.jpg\" width=\"259\" height=\"471\" ALIGN=\"left\" alt=\"S3-Switch\"\u003e\nCP2102 features:\u003cbr\u003e\n\n- Single-Chip USB to UART Data Transfer\n- No external resistors required, no external crystal required\n- On-chip power-on reset circuit and voltage regulator\n- Integrated 1024-Byte EEPROM\n\nVirtual COM Port Device Drivers\u003cbr\u003e\n- Windows 8/7/Vista/Server 2003/XP/2000\n- MAC OS-X/OS-9\n- Linux 2.40 or higher\n- USBXpress Direct Driver Support\n- Windows 7/Vista/Server 2003/XP/2000\n- Windows CE\n\u003cbr clear=\"left\"\u003e\n\nFeatures\u003cbr\u003e\n- Supports Mac, Linux, Android, WinCE, Windows 7/8/8.1/10/11...\n- Voltage output support: 5V or 3.3V \u003cb\u003e--\u003e Check for 3.3V setting!!!\u003c/b\u003e\n- Integrated USB protection device: SP0503\n- 3 LEDs: TXD LED, RXD LED, POWER LED\n- Pins accessible on pinheaders: TXD, RXD, RTS, CTS\n\n## 2.2 Functionality\n- Connects to your local WiFi network (you have to supply SSID and its Passphrase)\n- Will autodetect the Homewizard P1 Meter on the same network and connects to it. Every 5 seconds it will poll for new info.\n- Led will indicate switch status: blue blinking -\u003e connecting; blue continuous -\u003e AP mode; red continuous S3-Switch is ON\n- Switches the relay ON when Net Power reaches more than or equal -500 kW surplus (value of your choice)\n- Allows for 4 fixed clock switch moments (and duration) independent of Net Power level\n- Button allows for toggling the switch on or off\n- Has a builtin simple webserver for local access to show status and edit remotely fixed clock switch moments and duration\n- Point a browser to the local fixed IP address: \u003cb\u003e192.168.2.200\u003c/b\u003e or to: \u003cb\u003eesp8266.local\u003c/b\u003e\n\n## 2.3 Boot your Sonoff in Flashing Mode\u003cbr\u003e\nThe Internet is crowded with instructions on how to flash your code to a Sonoff device. [Search now.](https://www.google.com/search?q=flash+sonoff) One of the most detailed instructions you can find is \non [Random Nerd Tutorials](https://randomnerdtutorials.com/how-to-flash-a-custom-firmware-to-sonoff/). Study their tutorial to get acquainted with the technique!\n\n\u003cimg src=\"https://github.com/Berg0162/s3-switch/blob/main/images/095604.jpg\" width=\"356\" height=\"473\" ALIGN=\"left\" alt=\"S3-Switch\"\u003e\n\u003cimg src=\"https://github.com/Berg0162/s3-switch/blob/main/images/095604_detail.jpg\" width=\"426\" height=\"323\" ALIGN=\"left\" alt=\"S3-Switch\"\u003e\n\u003cbr clear=\"left\"\u003e\n\n## 2.4 Connection scheme and colors used in the project\u003cbr\u003e\n\u003cb\u003eCheck for 3.3V jumper setting on the Waveshare board!\u003c/b\u003e\n|Waveshare pins|SONOFF pins|Color|\n|--------------|--------------|--------------|\n|Vcc |3.3V|Red|\n|TxD |Rx|Orange|\n|RxD |Tx|Yellow|\n|Gnd |Gnd|Black|\n\n## 2.5 Entering the SSID and Password of your local WiFi network\nThe \u003cb\u003eSonoff S3-Switch\u003c/b\u003e supports Access Point mode (at startup) that allows you to use the S3-Switch to create a temporary WiFi network to connect. This is similar to WiFi connection sharing available on phones (a.k.a. hotspot). As with phones, the operation of a WiFi router is simulated: this is known as a Soft AP (for “software” WiFi access point). With Access Point mode one creates a private WiFi local area network wholly isolated from others.\nAt startup the S3-Switch checks for a \u003cb\u003evalid\u003c/b\u003e SSID and Passphrase to connect to your local WiFi network. If this check fails the S3-Switch starts Access Point mode to allow you to enter the credentials of the WiFi router of your choice and allows the Sonoff S3-Switch to connect to the local WiFi network. Most connected objects use this principle to connect to the home WiFi.\nAfter the valid SSID and Passphrase is checked this information is stored persistently and the S3-Switch will use these data, the next time it is powered or reset. Entering the SSID info is a one-time user action! \nIf the S3-Switch is in AP mode:\n- On your phone/tablet search for the open WiFi network with name: \u003cb\u003eESP8266-AP\u003c/b\u003e (NO password!)\n- Connect your phone to this hotspot\n- Point your browser to the fixed IP Address: \u003cb\u003e192.168.4.1\u003c/b\u003e\n- Your browser will show a form\n- Enter the SSID and Password. Press Submit button..\n- Receipt will be confirmed!\nIf all goes well, the S3-Switch now (always) connects to the local WiFi network of your choice!\n\n## 2.6 Sonoff S3-Switch remote access using the browser\u003cbr\u003e\nThe Sonoff S3-Switch can remotely be accessed by pointing the browser (on your desktop, tablet or smartphone) to a fixed host IP address: \u003cb\u003e192.168.2.200\u003c/b\u003e or to: \u003cb\u003eesp8266.local\u003c/b\u003e. The simple builtin web server will respond with a start page, that helps you select the different options.\u003cbr\u003e\n\n\u003cimg src=\"https://github.com/Berg0162/s3-switch/blob/main/images/Sonoff_01.jpg\" width=\"350\" height=\"380\" ALIGN=\"left\" alt=\"S3-Switch\"\u003e\n\u003cimg src=\"https://github.com/Berg0162/s3-switch/blob/main/images/Sonoff_02.jpg\" width=\"350\" height=\"380\" ALIGN=\"left\" alt=\"S3-Switch\"\u003e\n\u003cimg src=\"https://github.com/Berg0162/s3-switch/blob/main/images/Sonoff_03.jpg\" width=\"350\" height=\"380\" ALIGN=\"left\" alt=\"S3-Switch\"\u003e\n\u003cimg src=\"https://github.com/Berg0162/s3-switch/blob/main/images/Sonoff_04.jpg\" width=\"350\" height=\"380\" ALIGN=\"left\" alt=\"S3-Switch\"\u003e\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fberg0162%2Fs3-switch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fberg0162%2Fs3-switch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fberg0162%2Fs3-switch/lists"}