SMA Energy Meter in Home Assistant

Hi there,

is there a way to get the sma energy meter running?

thanks
Steve

1 Like

That link mentions a ’ local WebUI '.

So yes, you should be able to use the scrape sensor to get your info. I’d also be surprised if there wasn’t an API which returns JSON that would then let you use the Rest sensor.

On further reading, the meter also supports modbus, so you should be able to use the modbus sensors to extract your data.

  • I have zero experience with modbus.

hello,

thanks i never heard modbus before. i check that out.
if anyone has experience please let me know.

thanks

Hi @steveknoefler,

I’m also researching ways to get sensor info and/or control SMA devices via Modbus on Home Assistant. I’ve got a PV system with Sunny Boy 5.0, Sunny Island 8.0 and Home Manager 2.0 hopefully coming online soon and would like to get some guidance on this too.

So far, it seems like there are 2 ways to connect to SMA Energy Meters:

  1. Solar SMA WebConnect integration
  2. Modbus protocol documentation on SMA website
    The limited numbers of sensors exposed by the pysma library would hint at looking at Modbus instead. SMA has posted some documentation about which devices can expose which sensors and their associated register numbers. This can be found by looking at the second link above. It could be easy to integrate in practice, but on first look without the ability to test this platform, the Modbus protocol seems pretty tricky to use…

Has anyone gone that route already? Care to share your findings?

Anyone making some progress on this? I’m getting nowhere… Cannot access Modbus and cannot add custom sensor keys in the SMA component. Both Webconnect and Modbus (TCP) are activated!

I just started looking into this. I have not actually looked into modbus integration through Home Assistant but I was able to read out my inverter (SB2500TLST-21) throught the modbus using this repo: https://github.com/jghaanstra/PyModMon (i forked it and fixed a compatibility issue with pymodbus first).

I had to manually enable modbus communication through Sunny Explorer but after doing that this at least allowed me to prove that it’s possible to read out the inverter over modbus.

Quick update: I’m using WebConnect and it’s working fine. Takes some hunting down for the individual sensors. This can be done via Chrome’s Inspect element feature on the WebConnect interface.
Recommendation is to set the scan interval as the SMA’s don’t seem comfortable with frequent requests. Kind of shocking for expensive machines, but here you go!
One advantage with this method is that it only exposes the sensors and no inverter settings can be tempered with by a malicious intruder.

Am happy to share my code, if wanted, but it seems that different sensor keys exist on different models…

Here is the code for Sunny Island:

- platform: sma
  host: xxx.xxx.x.xxx
  group: user
  password: xxxxx
  scan_interval: 120
  sensors:
    sma_si_battery_voltage:
    sma_si_battery_charge:
    sma_si_battery_activity:
    sma_si_battery_cycles:
    sma_si_total_yield:
    sma_si_grid_frequency:
    sma_si_grid_voltage:
    sma_si_current_consumption:
    sma_si_current_grid_consumption:
    sma_si_current_pv_output:
    sma_si_total_pv_energy:
    sma_si_daily_pv_energy:
    sma_si_daily_total_energy:
  custom:
    sma_si_battery_voltage:
      key: "6100_00495C00"
      unit: V
      factor: 100
    sma_si_battery_charge:
      key: "6100_00295A00"
      unit: "%"
      factor: 1
    sma_si_battery_activity:
      key: "6180_08495E00"
      unit: ""
    sma_si_battery_cycles:
      key: "6402_00497900"
      unit: "#"
      factor: 1
    sma_si_total_yield:
      key: "6400_00462400"
      unit: Wh
      factor: 1
    sma_si_grid_frequency:
      key: "6100_00465700"
      unit: Hz
      factor: 100
    sma_si_grid_voltage:
      key: "6100_00464800"
      unit: V
      factor: 100
    sma_si_current_consumption:
      key: "6100_40463900"
      unit: W
      factor: 1
    sma_si_current_grid_consumption:
      key: "6100_40463700"
      unit: W
      factor: 1
    sma_si_current_pv_output:
      key: "6100_00452200"
      unit: W
      factor: 1
    sma_si_total_pv_energy:
      key: "6400_00454B00"
      unit: Wh
      factor: 1
    sma_si_daily_pv_energy:
      key: "6400_00454C00"
      unit: Wh
      factor: 1  
    sma_si_daily_total_energy:
      key: "6400_00461F00"
      unit: kWh
      factor: 1000

I’ve got an issue with sensors that have no unit. Apparently, a minor change to pysma could help with this. See GitHub’s pysma page for details.

who can change the python code ?

The keys can be found by using the Inpect button on Google Chrome while browsing the WebConnect interface.
@kellerza was quite helpful with suggesting ways to change the php. I tried, but had little success… Maybe someone else is more able than me…

Repost of Sunny Boy code…

- platform: sma
  host: xxx.xxx.x.xxx
  group: user
  password: xxxxx
  scan_interval: 120
  sensors:
    current_consumption:
    sma_status:
    sma_power_a:
    sma_power_b:
    sma_voltage_a:
    sma_voltage_b:
    sma_current_a:
    sma_current_b:
    sma_grid_voltage:
    sma_pv_power:
    sma_daily_yield:
    sma_total_yield:
    sma_power_supplied:
    sma_power_absorbed:
  custom:
    sma_status: 
      key: "6180_08214800"
      unit: ""
    sma_power_a:
      key: "6380_40251E00_0"
      unit: W
    sma_power_b:
      key: "6380_40251E00_1"
      unit: W
    sma_voltage_a:
      key: "6380_40451F00_0"
      unit: V
    sma_voltage_b:
      key: "6380_40451F00_1"
      unit: V
    sma_current_a:
      key: "6380_40452100_0"
      unit: A
    sma_current_b:
      key: "6380_40452100_1"
      unit: A
    sma_grid_voltage:
      key: "6100_00464800"
      unit: V
      factor: 1
    sma_pv_power:
      key: "6100_0046C200"
      unit: W
      factor: 1
    sma_daily_yield:
      key: "6400_00262200"
      unit: Wh
      factor: 1
    sma_total_yield:
      key: "6400_00260100"
      unit: Wh
      factor: 1
    sma_power_supplied:
      key: "6100_00464800"
      unit: W
      factor: 1
    sma_power_absorbed:
      key: "6100_00464800"
      unit: W
      factor: 1

I only find 1. And it’s not working. I don’t get any value’s …

@steveknoefler @TD22057 wrote code to publish the SMA energy meter values from a UDP protocol toward MQTT see https://github.com/TD22057/T-Home.

I also have an energy meter, but I can get the most important info from my Sunnyboy 1.5, which reads it from the Energy meter.

If there is interest I can probably look at extending pysma to also read the energy meter and present those values through to HA

1 Like

@monkey-house I can incorporate your keys into the next pysma to make it a bit more accessible for everyone if you don’t mind!

1 Like

@Faecon anyone can change the Python code :wink: you can just submit a Pull Request if there is a specific feature you see will add value

it was prob a noob question :smile:

2 Likes

Hi @kellerza,

Yes, you’re welcome to incorporate the keys I use with my inverters into pysma. The models are SB5.0-1AV-40 and SI8.0H-11. Both are the latest/newest SMA models (Sunny Boy has Wifi).

Please bear in mind the keys that have 2 extra characters (e.g.: key: “6380_40452100_1”) for separate MPTT do not currently work. Same for the ones with no unit (e.g.: status).

I am happy to try to change the python code as per the instructions you gave on Github… but I currently have no access to the inverters (and my knowledge of python is close to nil).

@faecon: Don’t worry about that: we’re all new at something!
For the keys, you look at the values on the interface of your inverter. Connect directly to the inverter on your local network with the IP address and your password for a User or Installer account and look at the current values tab. Select the value that interests you, right click on it and select Inspect in Google Chrome… I’m happy to help with screen grabs when I get my inverters back online. Could be a while though!

1 Like

This is wha I’ve found:

today : *

*<span ng-if="row.calcValKey" class="ng-binding ng-scope"> 10,09 kWh </span>**

yesterday : <td translate="lYieldYesterday" class="ng-scope">Gisteren:</td>
total : <span ng-if="row.calcValKey" class="ng-binding ng-scope"> 318,2 kWh </span>

actual value : <span id="v6100_40263F00" class="ng-binding">1.371 W</span>

so It looks I got only the actual value key, not the other 3 …

Look into the “Instantaneous values” tab. You’ll find a lot more. Looks like SMA replaces keys with aliases on the main interface page…