Skip to content

About

Using an ESP8266/ESP32 to emulate a Shelly Power Meter using various energy meter data inputs

Resources

Stars

69 stars

Watchers

6 watching

Forks

Latest commit

 

History

546 Commits

Folders and files

Repository files navigation

Energy2Shelly_ESP

CI

Getting started

This is a Shelly Pro 3EM Emulator running on ESP8266 or ESP32 using various input sources for power data.
This can be used for zero feed-in with Hoymiles MS-A2, Growatt NOAH/NEXA and Marstek Venus (testers needed!).

Kudos to @sdeigms excellent work at https://github.com/sdeigm/uni-meter which made this port easily possible.
SMA Multicast code is based on https://www.mikrocontroller.net/topic/559607

Installation

Option 1: Compile yourself

Compile and flash for your microcontroller using PlatformIO

Option 2: Flash pre-compiled binary via browser

Connect your ESP to your PC using USB and follow the instructions on the webflasher

Note

If you have trouble connecting to your ESP32-S3 or C3, hold BOOT and press RESET once before starting webflasher.

Option 3: OTA update if you have previously installed Energy2Shelly

Directly download a matching OTA-binary for your ESP device from the releases page and install the over-the-air update using WifiManager on your Energy2Shelly.

Reconfiguration & Software Updates

After a successful initial setup, WiFiManager no longer runs in Access Point (AP) mode. You do not need to connect to a temporary Wi-Fi network anymore. Instead, the device is now available locally within your home network.

To re-enter WiFiManager for updates or parameter changes:

  1. Make sure your computer or smartphone is connected to the same home network as the device.
  2. Navigate to http://<your-device-ip>/update to reboot the device into configuration mode. Webpage will reload in about 20s
  3. Once the system has restarted, you can:
    • Use http://<your-device-ip>/update to perform an OTA software update. After OTA update, webpage will reload in about 20s
    • Use the interface to adjust parameters and reconfigure your settings.

💡 Tip: If the page does not appear or shows an error after the reboot, refresh/reload your browser to force a clean reconnect.

Option 4: Factory reset, if everything went wrong

Press 5 times reset button of the device within 60s. This will erase all configs and reboots in a fresh setup

Configuration

1. Power device and wait for a hotspot named "Energy2Shelly"

2. Connect to that hotspot

3. Enter wifi data using the captive portal or by opening http://192.168.4.1/

4. Check if your device is visible in the WLAN. http://IP-address

5. go to configuration page and enter the detailed configuration.

 The device will ask for user and password. Default: empty. In configuration you can set a password. User name is not used; let it empty.

The following options are available:

  • MQTT

    • Server IP, port, username, password and topic

    • Power values on the MQTT topic are expected in JSON format. The are multiple fields to define available values using a JSON Path-style syntax. You can also select between monophase and triphase power data.

      example (monophase profile):

      • Total power JSON path -> ENERGY.Power for {"ENERGY":{"Power":9.99}}
      • Phase 1 power JSON path -> "no definition"
      • Phase 2 power JSON path -> "no definition"
      • Phase 3 power JSON path -> "no definition"
      • Energy from grid JSON path -> ENERGY.Consumption for {"ENERGY":{"Consumption":77}}
      • Energy to grid JSON path -> ENERGY.Production for {"ENERGY":{"Production":33}}
        -> Energy2Shelly_ESP responds to
        {"ENERGY":{"Power": 9.99,"Consumption":77,"Production":33}}

      example (triphase profile):

      • Total power JSON path -> ENERGY.Power for {"ENERGY":{"Power":7.3}}
      • Phase 1 power JSON path -> ENERGY.Pow1 for {"ENERGY":{"Pow1":98}}
      • Phase 2 power JSON path -> ENERGY.Pow2 for {"ENERGY":{"Pow2":196}}
      • Phase 3 power JSON path -> ENERGY.Pow3 for {"ENERGY":{"Pow3":294}}
      • Energy from grid JSON path -> ENERGY.Consumption for {"ENERGY":{"Consumption":98}}
      • Energy to grid JSON path -> ENERGY.Production for {"ENERGY":{"Production":131}}
        -> Energy2Shelly_ESP responds to
        {"ENERGY":{"Power":7.3,"Pow1":98,"Pow2":196,"Pow3":294,"Consumption":98,"Production":131}}
  • SMA

    • SMA Energy Meter or Home Manager UDP multicast data
    • if you have multiple SMA energy meters you can optionally provide the serial number of the source you want to use in the configuration options
  • SHRDZM

    • SHRDZM smart meter interface (common in Austria) with UDP unicast data
    • please enable UDP broadcasts to the IP of the ESP and port 9522 within SHRDZM
  • HTTP

    • a generic HTTP input
    • enter a query URL in the second parameter field which delivers JSON data and define at least the JSON Path for total power.
    • for full details on JSONPath configuration, check the section on MQTT above.
  • SUNSPEC

    • generic SUNSPEC register data polling via Modbus TCP
    • you can setup host ip of Modbus device (e.g. Kostal Smart energy meter)
    • Modbus TCP port (usually 502)
    • Modbus Device ID of the unit ID (71 for KSEM)
  • TIBBERPULSE

    • Parses SML data from your Tibber Pulse IR locally using the sml_parser ESP library. This is a great option if you want to use Tibber Pulse data for zero feed-in with Hoymiles MS-A2, Growatt NOAH/NEXA, TSUN DCU2000lite or Marstek Venus inverters/batteries.
    • Follow these instructions to access your Tibber Pulse/Bridge data locally.
    • Provide the IP address / hostname and port of the WebSocket API, the node id of your Pulse IR in the Bridge configuration, plus username and password of your Tibber Bridge, in the configuration options so Energy2Shelly_ESP can connect and receive power data.
    • The parser automatically extracts total power, phase power and energy from/to the grid from the WebSocket API data stream and makes it available for the Shelly Pro 3EM Emulator.
    • The following power meters are confirmed to work:
      • EMH EHZB
      • eBZ DD3
      • Iskra MT631
      • EMH EHZ
      • EasyMeter ESY11
    • Most power meters with SML output should work out of the box. If you encounter an error, please open an issue with your meter's model and a sample data log.
  • SMLSERIAL

    • Reads SML data directly from an IR reading head (e.g. Hichi IR TTL, bitShake SmartMeterReader-UART) wired to a UART pin of the ESP, no WiFi bridge needed.
    • Wiring: reading head VCC -> 3V3, GND -> GND, reading head TX -> configured RX GPIO of the ESP. The TX line of the ESP is not used.
    • Configuration: RX GPIO (default 20 on ESP32-C3, 16 on ESP32, 18 on ESP32-S3, 13/D7 on ESP8266), Baud rate (usually 9600) and Invert RX signal (usually false).
    • GPIO20 on the ESP32-C3 is only free on boards with native USB and no USB-UART chip (e.g. ESP32-C3 SuperMini). On boards like the ESP32-C3-DevKitM-1 GPIO20 is driven by the USB-UART chip, use another pin such as 4 or 10 there. Flash and USB pins are rejected.
    • Energy counters are only published if the meter sends them. Telegrams without a power value publish 0 W and are reported in the console (enter the meter PIN / enable extended data).
    • Same OBIS values as TIBBERPULSE: 1.8.0, 2.8.0, 16.7.0 and, if available, 36.7.0/56.7.0/76.7.0 for the phases. Many meters only send the current power after the PIN has been entered at the meter.
    • The console shows a hex dump of the first received bytes and statistics every 30s, which helps to find wrong baud rate or invert settings.
    • On ESP32 a hardware UART (Serial1) is used, on ESP8266 SoftwareSerial. A reboot is required after changing the settings.

Here are some sample generic HTTP query paths for common devices:

The Shelly ID defaults to the ESP's MAC address, you may change this if you want to substitute an existing uni-meter configuration without reconnecting the battery to a new shelly device.

Power offset option:

  • This option allows a positive or negative value to be added to the emulated Shelly's output data

How the phase_number option can be used:

  • If you have a monophase setup, set phase_number to 1. This asigns all power and energy data to phase 1.
  • If you have a triphase setup, set phase_number to 3. This distributes power and energy data across all three phases.

Note

This option controls how energy2shelly firmware outputs energy data, it does not change the input data. So if you have a triphase setup but want to assign all data to phase 1, set phase_number to 1. The TRIPAHSE option in JSONPATH settings only controls how the firmware reads the input data, not how it outputs this data.

don't forget to save the new settings. Some of the settings come into effect immediately, some of them need a reboot.

6. reboot / power on/off the device or press the reset button

7. Check the current power data at http://IP-address

8. Check debug output at http://IP-address/console

  • you can enable/disable autoscroll, save text data and clear console

9. Or monitor the power consumption over time at http://IP-address/plot

Currently supported microcontrollers

  • ESP32-C3
  • ESP32-S3 (>=4MByte Flash)
  • ESP32-S3-N8 (>=8MByte Flash)
  • ESP32
  • ESP8266

You found a bug

First, sorry. This software is not perfect.

  1. Open an issue
  • With helpful title - use descriptive keywords in the title and body so others can find your bug (avoiding duplicates).
  • Which branch, what microcontroller, what setup
  • Steps to reproduce the problem, with actual vs. expected results
  • If you find a bug in our code, post the files and the lines.
  1. Open a PR 😻
  • Explain in detail your changes
  • Ask for a review

some screenshots from project

wifi

Settings

settings settings

main

status

console

Note

Images may vary depending on the version. We always try to be up to date.

About

Using an ESP8266/ESP32 to emulate a Shelly Power Meter using various energy meter data inputs

Resources

Stars

69 stars

Watchers

6 watching

Forks

Releases

Packages

Contributors

Languages