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. 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) offer this service but always at a recurring pricing model and a security compromise...
Homewizard should be praised for their openness with respect to the well documentated access to the P1 Meter!
Get started with the Homewizard API
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:
This board and ESP32S3 processor was selected for its excellent specifications and crisp display. Aside of gaining experience with the 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. 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!
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...
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!
Please follow the installation instructions for the ESP32S3 T-display
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:
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
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
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
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!
- 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
Please follow the installation instructions for the ESP8266 processor
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:
- 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ºC
See the following page for more information about this product: Sonoff Basic R2 - WiFi Switch - ESP8266/ESP8285
The 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
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.
- 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 EEPROM
Virtual 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 CE
Features
- 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
- 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
The Internet is crowded with instructions on how to flash your code to a Sonoff device. Search now. One of the most detailed instructions you can find is on Random Nerd Tutorials. Study their tutorial to get acquainted with the technique!
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 |
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!
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.