Home Assistant Add-on: SMA Energy Meter emulator

I have created an add-on i would like to share:

SMA Energy Meter emulator

Supports aarch64 Architecture Supports amd64 Architecture Supports armhf Architecture Supports armv7 Architecture Supports i386 Architecture

This home assistant add-on can emulate the existence of one or more SMA Energy Meters on the local network. This makes it possible to use the data from other meter types and integrate them in your SMA inverter.

features

  • Emulate meter based on mqtt messages
  • Auto discover HomeWizard meters and emulate meters based on there measurements.

Configuration

How to use MQTT

If you have a mqtt broker configured in home assistant you do not need to configure anything. Otherwise fill in the mqtt configuration in the configuration tab.

The add-on will subscribe to the following mqtt topic: sma/emeter/<NUMERIC_METER_ID>/state. When receiving the first message the emulator wil start the emulation of the energy meter with the provided <NUMERIC_METER_ID>. The emulator wil send a udp packet every 1000ms. The content of the packet wil stay the same until it gets updated by the next mqtt message.

{
  "powerIn": 125.5, // power consumption in W
  "powerOut": 80.3, // power production in W
  "energyIn": 5000.603, // consumed energy in kWh
  "energyOut": 2000.707, // produced energy in Kwh
  "destinationAddresses": [
    "192.168.1.34" // ip-address(es) to send the packets to. This should be the ip of the inverter. If you leave this emtpy then multicast will be used. (multicast is not confirmed to work yet)
  ]
}

How to use with HomeWizard meters

Enable the HomeWizard functionality in the configuration. On startup the addon will try to find the homewizard meters on the local network. When a meter is found(it can take a few minutes) a serial number will be assigned and printed to the log output. To speed up the process for the next startup you can add the hostname in the configuration in the field “HomeWizard manual addresses”.

If your homewizard meter is not automatically detected you can manually add it by entering the ip address of the meter(s) in the field “HomeWizard manual addresses”.

If the meter is not detected by the inverter you can add the ip address of your inverter in the field “HomeWizard destination ip addresses”.

Home Assistant

example of a service call to publish the mqtt message:

service: mqtt.publish
data:
  payload_template: |-
    {
      "powerIn": {{states('sensor.power_consumed_from_grid')}},
      "powerOut": {{states('sensor.power_returned_to_grid')}},
      "energyIn": {{states('sensor.energy_grid_consumed_helper')}},
      "energyOut": {{states('sensor.energy_grid_returned_helper')}},
      "destinationAddresses": [
          "192.168.1.34"
        ]
    }
  topic: sma/emeter/1/state

Installation

  • Add the repository to the add-on repository:

Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.
https://github.com/Roeland54/SMA-Energy-Meter-emulator

  • Install the addon from the add-on store.

Thanks to

Based on code from Eml2emeter and used Volvo2Mqtt as example for the home assistant add-on specific configuration.

https://github.com/Roeland54/SMA-Energy-Meter-emulator

1 Like

Using something other than the SMA meter is well worthwhile. The SMA energy meter I had produced discrepancies of 10-20% compared to my energy provider’s metering. I replaced it with an IoTaWatt which has been within 1-2%.

Not sure why I would want to integrate it into my SMA inverter though?

3 use cases:

  • In a setup that is using a hybrid inverter with battery you need a meter at the grid connection. This just makes it possible to not buy a sma meter and just use the meter you already have. (probably because you have a meter with P1 port already)
  • if you have another non sma inverter and you want that solar generation to be visible in the sma sunny portal.
  • you can configure an sma energy meter as a load (washing machine, heat pump) in the sunny portal.
2 Likes

Ah! I see. Nice one.

Successfully added a grid meter and a meter for my old sma inverter that has no internet connection and is monitored by home assistant:


This looks interesting! I’m want to use this to emulate SMA energy meters and attach loads to it for my power things.
I have a little trouble getting it up and running though, I have published some dummy data to the MQTT topic (like shown in the initial post), but I can’t seem to get the energy meter to show up.

My setup is the following:

  • SMA Home Manager 2.0
  • Hybrid SMA Tripower

For the IP addresses, I’ve used both the IP of the inverter and the home manager, they are on different subnets though, maybe that’s the problem?

The messages are using udp on port: 9522. You should make sure udp is routed between subnets.

But if you have a home manager this may be a better solution for you: https://github.com/littleyoda/ha-sma-semp
But you possibly also will need network routing changes for this.

Update v0.1.0

Added integration with HomeWizard meters.

@Roeland54 When you want to add only a consuming meter for example an dishwasher kWh meter. Can you just leave out powerOut and EnergyOut and only publish PowerIn and energyIn?

@limwakra No they need to be there. I would just send a 0 hardcoded. I have similar, reversed situation where I have solar production I want to add and so this is the template to create the json:

{
  "powerIn": 0,
  "powerOut": {{states('sensor.solar_power_pv_1')}},
  "energyIn": 0,
  "energyOut": {{states('sensor.solar_energy_pv_1')}},
  "destinationAddresses": [
  "192.168.5.37"
    ]
}
1 Like

Thanks @Roeland54 for the quick response. What is the trigger interval for this? I got it now on 1 sec. But don’t see the emeter show up anywhere. I guess I should see it in the graph in the inverter? Is there somewhere I can look to see if it is correctly working.
Data is feed in screenshot of MQTT explorer:

If you enable debug logging in the configuration of the add-on you should see log outputs similar to this every second:

2024-08-21 20:19:30,446 - DEBUG - Updated packet for serial number 1
2024-08-21 20:19:31,070 - DEBUG - Sent packet to 192.168.5.37 for serial number 1
2024-08-21 20:19:31,438 - DEBUG - Received message on topic sma/emeter/1/state
2024-08-21 20:19:31,439 - DEBUG - Message data: {'powerIn': 341.617, 'powerOut': 0, 'energyIn': 2929694.5, 'energyOut': 550505.55, 'destinationAddresses': ['192.168.5.37']}

If that works you should be able to add a “sma speedwire device” in your inverter or home manager configuration. On my ennexOs inverter this is located at: Configuration > device administration > add device > SMA speedwire devices then it searches for messages on the network and you should be able to add it.

Hi @Roeland54

I just tried to use your add on and i almost got it to work. My HA is now sending UDP packages to my sunny tripower SE 10.0 inverters. Unfortunately the inverters refuse to accept any data. Am I doing something wrong or did the spec for the UDP payload change over the last 3 years?

Here are the different debug logs:
Energy Meter Addon:

Binary data received from a UDP Server plugged into the 2nd ethernet port of the inverter: “83 77 65 0 0 4 2 160 0 0 0 1 0 76 0 16 96 105 1 14 239 40 176 129 61 87 228 12 0 1 4 0 0 0 0 0 0 2 4 0 0 1 168 195 0 3 4 0 0 0 0 0 0 4 4 0 0 0 0 0 0 1 8 0 0 0 0 6 245 188 84 32 0 2 8 0 0 0 0 23 31 140 29 32 144 0 0 0 1 2 4 82 0 0 0 0”

The inverter himself does not auto discover the meter emulator nor will it be accept when added via device parameters directly:

  • The Status of the manually added device is “unavailable”
  • there is no list of found devices available
  • Under spotvalues: the speedwire meter notes “faulty communication”.

Do you have any idea what could be missing?

The UDP package logic used is from the sml2emeter project. I guess I got lucky that it works on my sunny boy smart energy 5.0

Last week there was someone with a tripower that had similar issues like you have. So my best guess is that there is something wrong with the udp packet. But without a real sma energy meter to compare the messages i don’t think there is much I can do.

GitHub - RalfOGit/sma-emeter-simulator: An SMA(TM) emeter simulator written in C++ generates speedwire packets that are accepted by an SMA tripower inverter. I managed to create an esp/tasmota meter emulation that works.

Tanks for the info. I already checked the simulator and created a pull request for the emulator. @Roeland54 quickly build a test version (tanks again for the promt response :slight_smile: ) and I managed to verify it on my local installation just this morning. For everyone who cant wait for the release version, here is the link to the test version branch: GitHub - Roeland54/SMA-Energy-Meter-emulator: Emulate the existence of one or more SMA Energy Meters on the local network. This makes it possible to use the data from other meter types and integrate them in your SMA inverter..

v0.1.3 is released with the fix of @cyrill.wyss should work for tripower inverters now.

my PV system
SMA Tripower SE inverter
BYD Battery
2x Hoymiles inverters (balcony power plant)
1x SHM (SMA Home Manager)
1x SMA Energy Meter 2.0 (Hoymiles inverters are counted here)
so far it is not possible to get the SMA Energy Meter 2.0 into Sunny Portal as a generation meter. actually, that’s exactly why I bought the SMA Energy Meter 2.0. Unfortunately, SMA does not allow this!
Now the question.
Can I use your SMA Energy Meter emulator to get the two balcony power plants (Hoymiles inverters) into Sunny Portal?
I only have to bring the values of the SMA Entergy Meter 2.0 into the portal
What exactly do I have to do?
I have Home Assitant running

thank you for support
Timo

As far as I know, emeter is only meant to broadcast on your LAN the power consumed from or supplied to the utility for use by the inverter. What you would need is to simulate an SMA inverter. I don’t know of any SMA inverter emulation that is able to read your Hoymiles inverters and send that information to the Sunny portal. Actually, I don’t know of any SMA inverter emulation.

This addon is only emulating a real SMA Energy Meter 2.0. So it will not be possible to do more with it than with a real SMA Energy Meter 2.0 which you have.

I can only speak for my setup with a SBSE 5.0 where I successfully added the SMA Energy Meter 2.0 to show PV values of an other inverter in the ennexos sunny portal (which is probably different from your portal as you have a SHM).