[SOLVED] Convert existing python script to HA component for SMA inverters

I have a SMA Sunny Boy SB2500TLST-21 inverter which I want to read out. The current SMA Webconnect component does not work with my type of inverter and the standard modbus component seems to be to limited to get the data I want into Home Assistant.

The inverter allows for a standard modbus connection and I want to retrieve the following values:

  • Current power generation (register id: 30775)
  • Voltage (register id: 30783)
  • Device temperature (register id: 30953)
  • Daily Yield (register id: 30517)
  • Total Yield (register id: 30513)

The python script in this Github repo does exactly what I want: https://github.com/jghaanstra/PyModMon

If needed, any additional data on the SMA modbus interface can be found here: http://files.sma.de/dl/2585/WEBBOX-MODBUS-TB-en-19.pdf

I’m willing to pay EUR 75,- to anyone that is capable of converting the linked Python script to a HA custom compontent.

[EDIT] After some more tinkering I might be able to use the default modbus component after all together with the template sensor. If I’m still missing something I’ll try to submit issues to extend the modus component. For now I’m pulling the bounty on this.

wouldn’t you be better filing an issue on github about what is not working with the current modbus component?

Hmmm, good point. I’ll try that first.

@phuturist Did you manage to use the ModBus component with a template sensor? If yes, do you care to share your findings?
I was using the WebConnect interface, but this keeps on turning itself off. I’m told this is because I use a Home Manager 2.0…

Yes I have. See below the configuration for configuration.yaml. Getting the right register id’s was a hassle. They seem to differ per model but there is a lot of documentation about it from SMA. And dont forget to actually enable modbus TCP on the inverter. It’s disabled by default.

modbus:
  type: tcp
  host: 192.168.0.128
  port: 502

sensor:
  - platform: modbus
    scan_interval: 10
    registers:
      - name: SMA Power AC
        unit_of_measurement: W
        slave: 3
        register: 30775
        count: 2
        data_type: uint
      - name: SMA Daily Yield
        unit_of_measurement: Wh
        slave: 3
        register: 30517
        count: 4
        data_type: int
      - name: SMA Total
        unit_of_measurement: MWh
        slave: 3
        register: 30513
        count: 4
        data_type: int
      - name: SMA Volt
        unit_of_measurement: V
        slave: 3
        register: 30783
        count: 2
        data_type: int

  - platform: template
    sensors:
      sma_power:
        value_template: "{% if states('sensor.sma_power_ac')|float < 0 or states('sensor.sma_power_ac')|float > 3000 %}0{% else %}{{ states('sensor.sma_power_ac')}}{% endif %}"
        friendly_name: 'Power'
        unit_of_measurement: 'Watt'
        icon_template: mdi:flash-circle
      sma_day_production:
        value_template: "{{ states('sensor.sma_daily_yield') }}"
        friendly_name: 'Dagopbrengst'
        unit_of_measurement: 'Wh'
        icon_template: mdi:flash-circle
      sma_total_production:
        value_template: "{{ (states('sensor.sma_total') | float / 1000) | round(2) }}"
        friendly_name: 'Totale opbrengst'
        unit_of_measurement: 'MWh'
        icon_template: mdi:flash-circle
      sma_voltage:
        value_template: "{% if states('sensor.sma_volt')|float < 0 %}0{% else %}{{ states('sensor.sma_volt') | float / 100 | round(2)}}{% endif %}"
        friendly_name: 'Voltage'
        unit_of_measurement: 'V'
        icon_template: mdi:flash-circle
1 Like

Cheers for that, that’s great!
I’ve changed the slave to 126 based on what I read somewhere. I am getting some values: all -1 or a number with 10 digits. Strange as I copied the register number straight off SMA’s crappy Excel doc.
I’ll try with slave: 3…
What does the count argument do and how do you chose which number to use? The doc is not helping me much:
count (Optional): Number of registers to read.
SMA does mention on its documents not to place more than 5 requests per poll and space each polling by at least 10 seconds.

I only can connect as user, where the modbus cannot be changed :frowning:

Get the Installer password from whoever set this up. They have to give this to you on request. No wonder you could not use WebConnect then…

haha, is that the problem ? :slight_smile:

1 Like

Yup, contact your installer and get the password!

OK, this works for me with one of the 2 inverters. Thanks @Phuturist. Now onto finding out how to integrate the second inverter…

Ok, Got the password and got it working. Can I see the yield from yesterday too ?

I’ve found out a lot of sensors output the maximum possible value when no value is published by the inverter. This occurs for example with current yield at night when the PV does not produce anything. I’ve created template sensors for such problematic values that sets the value to 0 rather than these non sensical numbers…

1 Like

That github link is broken now (May 2019), anyone have a current working link?

does anyone has a functional solution for a sma tripower + home manager 2.0 ?

Thx in advance for any help