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.