Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/berg0162/s3-switch
Smart Solar Surplus Switch
https://github.com/berg0162/s3-switch
esp32s3 esp8266 lilygo-tdisplay-s3 smart-switch solar-energy sonoff-basic surplus
Last synced: about 2 months ago
JSON representation
Smart Solar Surplus Switch
- Host: GitHub
- URL: https://github.com/berg0162/s3-switch
- Owner: Berg0162
- License: gpl-3.0
- Created: 2023-08-24T06:28:34.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-15T09:59:39.000Z (over 1 year ago)
- Last Synced: 2024-12-21T20:40:39.910Z (about 2 months ago)
- Topics: esp32s3, esp8266, lilygo-tdisplay-s3, smart-switch, solar-energy, sonoff-basic, surplus
- Language: C
- Homepage:
- Size: 4.02 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# S3-Switch Smart-Solar-Surplus-Switch
In 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.
The 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.It 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!
The 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...
## Homewizard WiFi P1 meter API
Homewizard should be praised for their openness with respect to the well documentated access to the P1 Meter!
[Get started with the Homewizard API](https://homewizard-energy-api.readthedocs.io/index.html)The present project created 2 instances of a Smart-Solar-Surplus-Switch that share most of the software but differ in the selected electronic components:
## 1 S3-Switch with LilyGo ESP32S3 T-display
This 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!## 2 S3-Switch with Sonoff Basic R2 (ESP8266)
The 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...## Arduino IDE 2.2
The present code is developed on Arduino IDE 2.2. Notice that you will need for each of these processors (ESP32S3 and/or ESP8266) an Arduino IDE that is tailored for the specific type!# 1 S3-Switch with ESP32S3-T-display
## 1.0 Before you start
Please follow the installation instructions for the [ESP32S3 T-display](https://github.com/Xinyuan-LilyGO/T-Display-S3)
If you select in the menu bar of Arduino IDE 2.2 Tools, the settings for the ESP32S3 processor and the project are the following:
![]()
## 1.1 Electronic Components
### LilyGo ESP32S3 T-display
![]()
LilyGo 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).See for specifications, installation and setup: [LilyGo ESP32S3 T-display](https://github.com/Xinyuan-LilyGO/T-Display-S3)
### 5V Relay 1-Channel High-active or Low-active
Specifications:
- Supply voltage: 5V DC
- Signal voltage: 3.3-5V
- Maximum voltage through relay: 250V AC or 110V DC
- Resistive load: 10A (125V AC), 7A (240V AC) or 7A (28V DC)
- Inductive load: 3A (120V AC) or 3A (28V DC)
- Status led shows relay switched ON or OFF
Pinout:
- DC+: 5V supply voltage
- DC-: Ground/GND
- IN: Signal pin
- NO: Relay normally open
- COM: Relay common
- NC: Relay normally closed### PCB Power supply
![]()
Specifications:
- Input voltage (AC pins): 100 - 240V AC (recommended), 90 - 264V AC (maximum)
- Output voltage (+Vo and -Vo pins): 5V DC
- Maximum output current: 1000mA (continuous)
- Voltage control: ±0.2%
- Load regulation: ±0.5%
- Exit ripple: <70mV## 1.2 Circuitry and physical setup
![]()
>[!WARNING]
>Some components are connected to 220 Volt AC mains, you really need to know what you are doing since this can be potentially dangerous!
![]()
![]()
## 1.3 Functionality
- Connects to your local WiFi network (you have to supply SSID and its Passphrase)
- Will autodetect the Homewizard P1 Meter on the same network and connects to it. Every 5 seconds it will poll for new info.
- Displays actual time retrieved from Internet
- Displays Switch Status in addition to the Led status of the Relay board
- Displays Net Power in digits and gauge presentation (surplus: green CCW and consumption: brown CW)
- Switches the relay ON when Net Power reaches more than or equal -500 kW surplus (value of your choice)
- Allows for 4 fixed clock switch moments (and duration) independent of Net Power level, visible in the display (red blocks)
- Displays time intervals when the smart switch was activated (green ribbon)
- Has a builtin simple webserver for local access to show status and edit remotely clock switch moments and duration
- Point a browser to the local fixed IP address: 192.168.2.100 or to: esp32s3.local# 2 S3-Switch with Sonoff ESP8266
## 2.0 Before you start
Please follow the installation instructions for the [ESP8266 processor](https://arduino-esp8266.readthedocs.io/en/latest/installing.html)
If you select in the menu bar of Arduino IDE 2.2 Tools, the settings for the ESP8266 processor and the project are the following:
![]()
## 2.1 Electronic Components
### Sonoff Basic R2![]()
Specifications:- Voltage range: 90-250V AC (50/60Hz)
- Max current: 10A
- Max. Power: 2200W
- WiFi chip: ESP8266 or ESP8285
- Dimensions: 91\*43\*25mm (l\*b\*h)
- Wireless standard: 802.11 b/g/n
- Security mechanism: WPA-PSK/WPA2-PSK
- Working temperature: 0ºC-40ºCSee the following page for more information about this product: [Sonoff Basic R2 - WiFi Switch - ESP8266/ESP8285](https://sonoff.tech/product/diy-smart-switches/basicr2/)
### CP2102 USB UART BoardThe CP2102 USB UART Board (type A) is an accessory board that features the single-chip USB to UART bridge CP2102 onboard.
The board used in the project is from manufacturer: [Waveshare](https://www.waveshare.com/CP2102-USB-UART-Board-type-A.htm)
This 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.
![]()
CP2102 features:- Single-Chip USB to UART Data Transfer
- No external resistors required, no external crystal required
- On-chip power-on reset circuit and voltage regulator
- Integrated 1024-Byte EEPROMVirtual COM Port Device Drivers
- Windows 8/7/Vista/Server 2003/XP/2000
- MAC OS-X/OS-9
- Linux 2.40 or higher
- USBXpress Direct Driver Support
- Windows 7/Vista/Server 2003/XP/2000
- Windows CEFeatures
- Supports Mac, Linux, Android, WinCE, Windows 7/8/8.1/10/11...
- Voltage output support: 5V or 3.3V --> Check for 3.3V setting!!!
- Integrated USB protection device: SP0503
- 3 LEDs: TXD LED, RXD LED, POWER LED
- Pins accessible on pinheaders: TXD, RXD, RTS, CTS## 2.2 Functionality
- Connects to your local WiFi network (you have to supply SSID and its Passphrase)
- Will autodetect the Homewizard P1 Meter on the same network and connects to it. Every 5 seconds it will poll for new info.
- Led will indicate switch status: blue blinking -> connecting; blue continuous -> AP mode; red continuous S3-Switch is ON
- Switches the relay ON when Net Power reaches more than or equal -500 kW surplus (value of your choice)
- Allows for 4 fixed clock switch moments (and duration) independent of Net Power level
- Button allows for toggling the switch on or off
- Has a builtin simple webserver for local access to show status and edit remotely fixed clock switch moments and duration
- Point a browser to the local fixed IP address: 192.168.2.200 or to: esp8266.local## 2.3 Boot your Sonoff in Flashing Mode
The 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
on [Random Nerd Tutorials](https://randomnerdtutorials.com/how-to-flash-a-custom-firmware-to-sonoff/). Study their tutorial to get acquainted with the technique!
![]()
![]()
## 2.4 Connection scheme and colors used in the project
Check for 3.3V jumper setting on the Waveshare board!
|Waveshare pins|SONOFF pins|Color|
|--------------|--------------|--------------|
|Vcc |3.3V|Red|
|TxD |Rx|Orange|
|RxD |Tx|Yellow|
|Gnd |Gnd|Black|## 2.5 Entering the SSID and Password of your local WiFi network
The Sonoff S3-Switch 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.
At startup the S3-Switch checks for a valid 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.
After 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!
If the S3-Switch is in AP mode:
- On your phone/tablet search for the open WiFi network with name: ESP8266-AP (NO password!)
- Connect your phone to this hotspot
- Point your browser to the fixed IP Address: 192.168.4.1
- Your browser will show a form
- Enter the SSID and Password. Press Submit button..
- Receipt will be confirmed!
If all goes well, the S3-Switch now (always) connects to the local WiFi network of your choice!## 2.6 Sonoff S3-Switch remote access using the browser
The Sonoff S3-Switch can remotely be accessed by pointing the browser (on your desktop, tablet or smartphone) to a fixed host IP address: 192.168.2.200 or to: esp8266.local. The simple builtin web server will respond with a start page, that helps you select the different options.
![]()
![]()
![]()