SMA Energy Meter in Home Assistant

I managed to do it by integrating the modbus image

Hi, froschie is providing a powerful collection of dockerized python Scripts. One of them will read all existing values from your sma device.

1 Like

Thanks, but I’m a little confused how to use these with HA.

Possibly this is a misunderstanding. I was assuming you intend to use the SMA integration (https://www.home-assistant.io/integrations/sma/).
Here you can add all values which your inverter provides as custom sensor. (https://www.home-assistant.io/integrations/sma/#configuration-variables)
But you wil need the SMA keys of your particular inverter which you can read out with froschie’s script.
If you use the modbus interface this may be no help.

1 Like

i was able to get the modbus running. i have real time watts from my 2 sunnyboy inverters. i was able to get Total watts which are lifetime watts. Also got the internal temps which is cool.

I am unable to get the daily yields. According to the document its 30517. as you can see mine shows -0.001

Also does anyone know how to get it to display unavailable or offline when the inverter has shut off?

during the day i get real values but at night when the inverter is off i get these goof ball numbers.

image

May I assume you have two SMA Sunny Boy 6.0 inverters? I have three of the Sunny Boy inverters (2 x SB7.7 and 1 x SB5.0) and I don’t think they supply a daily total. However it is easy to generate one by reading the totals after midnight and subtracting this from the current total.

This is what a WebConnect browser session does for its dashboard using a query that supplies a start and stop time and gets back a list of the totals on 5 minute intervals, just needs the first and last list elements to compute the daily total.

I can’t use Modbus (left disabled when my inverters were commissioned) but the WebConnect interface returns null values when it is dark, just substitute 0 for the power output and unknown for the temperature in your templates (looks like they return the minimum 32-bit signed integer to me).

I appreciate your help. Im pretty new with templates and getting yaml correct. Its a trial and error for me haha. Could you help me with the template? I appreciate it.

I’m new too and more focused on setting up my solar dashboard (while mastering Python, InfluxDB, Grafana, and HA) but something like this works in the Developer Tools templates tab:

{% if ((states('sensor.energy_net') | float) < 0) %}
0
{% else %}
{{states('sensor.energy_net')}}
{% endif %}

Just change ‘sensor.energy_net’ to the power/temperature sensor in your setup. I can’t test it but it did pass the configuration test when used in a value_template.

Im sorry do i create a new platform template sensor then put this. Or do i add this after each modbus entry?

I would create a sensor template for each modus sensor, then you can control the format and convert needed. For example, your total production results could be kWh or MWh as desired.

Here is how I do solar power to the grid (I get my data via MQTT):

- platform: mqtt
  name: "multisma2_acpower_site_mqtt"
  state_topic: "multisma2/ac_measurements/power"
  value_template: "{{ value_json.site }}"

So the above code extracts the power for my site (all 3 inverters combined) and makes it available as ‘sensor.multisma2_acpower_site_mqtt’ to consumers. I choose my names so they show up together when filling in fields (if I enter acpower I just see sensors associated with AC power) or for wildcards in recorder.yaml file. For AC power I have two templates, one for power in watts and the other for power in kilowatts, The templates is where I assign the friendly names and icons:

- platform: template
  sensors:
    multisma2_acpower_w:
      unit_of_measurement: "W"
      friendly_name: "Production"
      icon_template: "mdi:solar-power"
      value_template: "{{ '%d'|format((states('sensor.multisma2_acpower_site_mqtt') | int)) }}"

    multisma2_acpower_kw:
      unit_of_measurement: "kW"
      friendly_name: "Production"
      icon_template: "mdi:solar-power"
      value_template: "{{ '%.3f'|format((states('sensor.multisma2_acpower_site_mqtt') | float) / 1000) }}"

You are awesome!! Thank you for the help! Im guessing the daily yield is going to be trickier lol

Much better, I wish I could pull the temperature from my Sunny Boys using WebConnect but I don’t see where they read and display the inverter temperaturer.

Not sure how to approach it but you know how to read the value, you just need to subtract a reading from after midnight from the current reading. Seems like some sort of automation is in order.

i went back and looked and i dont see the temps. i swore they were in the instant values tab. the only value i could ever extract from the webconnect sma platform was the L1 voltage and L2 voltage. It was pretty useless for me.

My next task is to make a sensor that subtracts my solar wattage from my shop wattage. I have clamps on my wires feeding my shop sub panel which has the solar backfed into. so its combining the watts

I went and tried every SMA key that had a unit of ºC, ºF, or just ‘º’ and none of them returned a value. If they have a temperature value in the inverter I don’t know how to access it.

There is lots of data accessible using WebConnect, AC side power/voltage/current, DC side power/voltage/current and individual string power values. Divide the AC power by the DC power and you have the inverter efficiency. I sample the Instantaneous tab every 5 seconds and and pick the data I want out of there.

Plus you can access the daily and monthly past production, here is an InfluxDB dashboard of my system with some of the information:

Here are some views from my Home Assistant Production dashboard, all the data but none of the graphics. The status is the codes used by the inverters, for now the icons change to something intuitive.

I see the same error coming up. I have two strings (for east faced and west faced panels):

  custom:
    pv_power_a:
      key: '6380_40251E00_0'
      unit: W
      factor: 1
    pv_power_b:
      key: '6380_40251E00_1'
      unit: W
      factor: 1

This results in the following error:

Logger: pysma
Source: /usr/local/lib/python3.8/site-packages/pysma/__init__.py:177

Duplicate SMA sensor key 6380_40251E00

However, both sensors run just fine. I guess I can safely ignore this error.

Hi folks, if you are using Home Assistant OS, you could try to add the following add-on to read the SMA energy meter values & publish them through MQTT. It includes auto-discovery for the sensors.

Quickly add the repo: Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.

Enjoy!

Hello KellerZa,

i am using a Raspi Installation of Home Assistant. Is there a way to add the AddOn directly out of the Home Assistant UI?

Frank

I think that error is because those the two values (pv_power) are already setup in the library
You don’t need to customise those ones

Hi Mate
Tried to install but received this error

Failed to install add-on

The command ‘/bin/ash -o pipefail -c apk add --no-cache git’ returned a non-zero code: 1