SMA Energy Meter in Home Assistant

@PtP figured this one out. Hopefully, this gets integrated into a future release of HA…

@TD22057 created a script to read the SMA energy meter and publish it on MQTT, which should then work to ingest in HomeAssistant with MQTT

I also have one of these meters and have thought of including it in pysma (the lib behind the Hass SMA integration) and then exposing it as a sensor, but not gotten so far… I already get consumption from my SB and only need 1 phase

Simple question I hope (not sure it belongs in here though), how can I remove the decimals fro the results?

Cheers in advance.

Create template sensors that look something like this:

patio_fan_load:
      friendly_name: 'Patio Fan Load'
      value_template: '{{ (states.switch.patio_fan.attributes.load_power|float)|round(1) }}'
      unit_of_measurement: 'W'

round(*) is the value you set for the number of decimals.

Hi, I’m also having issues with the SMA sensor.

I have a SunnyBoy connected to a SunnyWebbox which allows me to view my power over a web interface. I can view the stats with a webbrowser OK.

I’ve tried adding this to the sensors part of my config:

  host: 192.168.1.202
  password: !secret sma_password
  group: user
  scan_interval: 120
  sensors:
    current_power:

However once I restart HA I get the following errors on my log file:

2019-01-16 16:44:31 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/sensor/sma.py", line 125, in async_sma
    values = await sma.read(used_sensors)
  File "/usr/local/lib/python3.6/site-packages/pysma/__init__.py", line 163, in read
    yield from self.new_session()
  File "/usr/local/lib/python3.6/site-packages/pysma/__init__.py", line 134, in new_session
    body = yield from self._fetch_json(URL_LOGIN, self._new_session_data)
  File "/usr/local/lib/python3.6/site-packages/pysma/__init__.py", line 125, in _fetch_json
    return (yield from res.json()) or {}
  File "/usr/local/lib/python3.6/site-packages/aiohttp/client_reqrep.py", line 1001, in json
    headers=self.headers)
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: text/html'

What am I doing wrong?

Possibly you have simply not copied it in here but the sensor config above does not include the platform?
I assume that this may be needed. My SunnyBoy is nicely answering with the following sensor config including platfrom:

sensor:
platform: sma
host: 192.168.2.104
password: “mysecretpassword”
scan_interval: 5
sensors:
current_consumption:
total_consumption:
current_power:
sma_daily_yield:
power_from_grid:
power_to_grid:
custom:
sma_daily_yield:
key: “6400_00262200”
unit: Wh
power_from_grid:
key: “6100_40463700”
unit: W
power_to_grid:
key: “6100_40463600”
unit: W

Hi,

i’ve a sunny boy also, and i never had error.
I didn’t have access to my config right now to show it to you, but i have made exactly what is described in the doc

something like that:

sensor:
  - platform: sma
    host: IP_ADDRESS_OF_DEVICE
    password: YOUR_SMA_PASSWORD
    sensors:
      current_consumption: [total_consumption]
      current_power:
      total_yield:

Hi JensAtGitHub,

interesting, where did-you find the other available options ?
i search something like a the total_year, total_last_year, total_day, and a total_yesterday
Actually i only use the current_power and total_yield

Hi Vincent,

I learned this somewhere here in the forum. (Can’t remember where)
Those values are partly depending on the modell type. One way to reverse engineer those sma identifiers is to log on to the web interface of the inverter and inspect the web site objects with the network-developer tools of the browser. Depending on the browser you would have different options. It is worth playing around with multiple browsers there. I found some identifies with firefox and some others with chrome depending how they are being used.

E.g. You may find them (Firefox) with developer tools enabled as follows: Highlight the value you are interested in, click right mouse and choose investigate element. If this value is using an identifier it will give you a hint in the deveolper tools window:


In this case it is the identifier for current_power 6100_40263F00.

But for my understand this does not work for each and every element since some of them are not refering to identifiers directly but trigger a script to calculate them. The method above will just give no identifier directly.

You may analyse then the different java scripts running on the actual page using the Networkanalyser tab and filter for the parameters being used in the scripts. This will give you a list of identifiers which are being used on this webpage for your specific device.


My experience is that you can use them all as custom sensor. Nevertheless none of them gives you historical data.

I am also trying currently to get historical data with a small automation since total_consumption is available. But I am new to the automation part in home assistant so I am not yet successful. There are already entries which give guidance for this. E.g:
https://community.home-assistant.io/t/how-to-calculate-daily-power-consumption-from-dsmr-sensors/37696
…but this a different topic.
If you find repective direct sma identifiers for total consumption today / yesterday this would be very interesting.I am only aware of ‘dailly_yield’ which is part of the sma component: https://www.home-assistant.io/components/sensor.sma/

1 Like

Anyone successfully integrated SunnyBoy 4000SBL in Combination with a HomeManager1.0 ?
If yes, please give my some hints, maybe relevant part from your yaml.
Many thanks

I have a Sunny Tripower 6.0, and my daily_yield is not captured. total_yield is fine.

Is there any way to capture the status at midnight from the getLogger.json file, as shown in the screenshot? I could also just log it via an automation, but would like to avoid that…
The value of the kWh at midnight for me is equal to the 017A-B2FDACB9 -> 1 -> v (=211036)

Anyone a clue on how to get this into HA?

Thanks
Cadish

I am a newbie. Trying to get SMA into my HA.
I have a Sunny Boy 2.5 1vl-40, with SMA webconnect
This is in my config:

  • platform: sma
    host: 192.168……
    password: …
    group: user
    scan_interval: 120
    sensors:
    current_consumption: [total_consumption]
    pv_power:
    total_yield:

I can see the sensors in HA
sensor.pv_power unknown unit_of_measurement: W friendly_name: pv_power

This is in the log:
Sun Feb 03 2019 13:13:57 GMT+0100 (Central European Standard Time)
Could not start session, Session ID expected [result.sid], got {‘result’: {‘sid’: None}}

Problem is I get no numbers.
Please any help?

Hi Wim.
I assume you can locallly logon to the web interface of your device with the user/pwd/ip@ combination.

I had similar problems. I could not get ‘current_power’ (unknown) but later was able to use ‘pv_power’ instead. My understanding is that not all measurements are available on all SMA devices.

I would recommend to start with only one sensor (‘current_consumption’, pv_power’, …) untl you get first readings. When changed - always precheck your configuration.yaml file until it reports no more error (e.g. on hass.io: hassio ha check). Indent’s are super critical.
Good luck it will work. Jens

Thanks for the answer.
The webinterface is working fine and I have the right ip and pwd in HA.
I will try again tomorrow, when there is sun.

Please could anyone advise on how I write the yaml for two SMA Sunny Boys? I can pick up the first one but not the second when I write the following. The script sits in a file called sensors.yaml.

  • platform: sma
    host: 192.168.1.75
    password: !secret sma1
    sensors:
    current_power:

  • platform: sma
    host: 192.168.1.76
    password: !secret sma2
    sensors:
    current_power:

Thanks for your help.

Currently two sensors with the same name and same id will give you an error about entity names - see https://github.com/home-assistant/home-assistant/issues/20375

From your config you also need to indent current_power (add 2 spaces?)

This might also mean that you have too many users logged on- typically inly 1 user and 1 installer allowed

At the moment only getValues is used by the library https://github.com/kellerza/pysma/blob/master/pysma/init.py#L243

What you dont show is the request to get this result in your screenshot
Other things that needs to be considered:

  • can you request the midnight value/ have to request at midnight? (The latter is difficult)
  • how would we know when to read getlogger/getvalues? (Probably extend the Sensor class(

Thank you,
I will try this. I Will also disconnect the youless on my smart meter.

Kellerza, thanks for your response. You are right about the extra 2 spaces. These were lost between copying the lines from my yaml file to the forum.
I see from your link that the duplication issue is being discussed. Do you know how I will know when this issue has been resolved please?