MODBUS data from SMA Inverter

It looks really good.
My own dashboard (including DSMR Slimme Meter - Home Assistant) looks like this.

I let the data collect for a few days and will provide feedback on the result in Energy Dashboard.

Thanks again for your support !
I am wondering these config we made could be consolidated in an integration

Is it possible to share your config regarding the Modbus SMA Lines and and the sensor stuff to archieve what you show in that screenshot. This looks awesome. I am very new to the modbus section and try to fetch the data from my Sunny Tripower 8.0 / Sunny Boy Storage 5.0 / Sunny Home Manager 2.0.

I would appreciate if you would share your code!

Thank you

One day full of data.
I compared the values from the energy Dahboard and Sunny Portal => All Good (but no sun today …)

modbus:
  - name: SMA
    type: tcp
    host: YOUR_INVERTER_IP_HERE
    port: 502
    sensors:
      - name: SMA_Power_AC
        state_class: measurement
        unit_of_measurement: W
        slave: 3
        address: 30775
        count: 2
        data_type: uint32
        scan_interval: 60
      - name: PV_Daily_Yield
        unit_of_measurement: kWh
        state_class: measurement
        slave: 3
        address: 30517
        scan_interval: 60
        scale: 0.001
        precision: 3
        count: 4
        data_type: int64    
      - name: PV_Total_Production
        unit_of_measurement: MWh
        state_class: measurement
        slave: 3
        address: 30513
        scan_interval: 60
        scale: 0.000001
        precision: 3
        count: 4
        data_type: int64
      - name: Grid Voltage
        unit_of_measurement: V
        slave: 3 
        address: 30783
        scan_interval: 60
        count: 2
        scale: 0.01
        precision: 2
        data_type: int32
      - name: Grid frequency
        unit_of_measurement: Hz
        slave: 3 
        address: 30803
        scan_interval: 60
        count: 2
        scale: 0.01
        precision: 2
        data_type: uint32
      - name: SMA_temp
        unit_of_measurement: °C
        slave: 3
        address: 30953
        scan_interval: 60
        count: 2
        scale: 0.1
        precision: 1
        data_type: int32
      - name: SMA_status
        slave: 3
        address: 30201
        scan_interval: 60
        count: 2
        data_type: int32
      - name: SMA_grid
        slave: 3
        address: 30217
        scan_interval: 60
        count: 2
        data_type: uint32
      - name: Insulation
        slave: 3
        address: 30225
        scan_interval: 60
        count: 2
        scale: 0.001
        unit_of_measurement: kOhms
        data_type: int32
      - name: SMA_Residual_current
        slave: 3
        address: 31247
        scan_interval: 60
        count: 2
        scale: 1
        unit_of_measurement: mA
        data_type: int32
      - name: Apparent Power
        unit_of_measurement: VA
        slave: 3
        address: 30813
        scan_interval: 60
        scale: 1
        precision: 0
        count: 2
        data_type: int32
      - name: Reactive Power
        unit_of_measurement: VAr
        slave: 3
        address: 30805
        scan_interval: 60
        scale: 1
        precision: 0
        count: 2
        data_type: int32
sensor:
  - platform: template
    sensors:
      modbus_sma_pv_power:
        friendly_name: 'Power Output'
        value_template: >-
            {% if states('sensor.sma_power_ac')|float < 0 or states('sensor.sma_power_ac')|float > 10000 %}
              0
            {% else %}
              {{ states('sensor.sma_power_ac') }}
            {% endif %}
        unit_of_measurement: "W"
        icon_template: mdi:flash-circle
      modbus_sma_pv_power_kw:
        friendly_name: 'Power Output kW'
        value_template: >-
            {% if states('sensor.sma_power_ac')|float < 0 or states('sensor.sma_power_ac')|float > 10000 %}
              0
            {% else %}
              {{ states('sensor.sma_power_ac')|float / 1000 }}
            {% endif %}
        unit_of_measurement: "kW"
        icon_template: mdi:flash-circle
      modbus_sma_pv_apparent_power:
        friendly_name: 'Apparent Power'
        value_template: >-
            {% if states('sensor.apparent_power')|float < 0 or states('sensor.apparent_power')|float > 10000 %}
              0
            {% else %}
              {{ states('sensor.apparent_power') }}
            {% endif %}
        unit_of_measurement: "VA"
        icon_template: mdi:flash-circle
      modbus_sma_pv_reactive_power:
        
        friendly_name: 'Reactive Power'
        value_template: >-
            {% if states('sensor.reactive_power')|float < 0 or states('sensor.reactive_power')|float > 10000 %}
              0
            {% else %}
              {{ states('sensor.reactive_power') }}
            {% endif %}
        unit_of_measurement: "VAr"
        icon_template: mdi:flash-circle
      modbus_sma_pv_residual:
        
        friendly_name: 'Residual Current'
        value_template: >-
            {% if states('sensor.sma_residual_current')|float < 0 or states('sensor.sma_residual_current')|float > 10000 %}
              0
            {% else %}
              {{ states('sensor.sma_residual_current') }}
            {% endif %}
        unit_of_measurement: "mA"
        icon_template: mdi:flash-circle
      modbus_sma_temperature:
        
        friendly_name: 'Inverter Temp'
        value_template: >-
            {% if states('sensor.sma_temp')|float < 0 or states('sensor.sma_temp')|float > 100 %}
              0
            {% else %}
              {{ states('sensor.sma_temp') }}
            {% endif %}
        unit_of_measurement: "°C"
      modbus_grid_frequency:
        
        friendly_name: 'Grid Frequency'
        value_template: >-
            {% if states('sensor.grid_frequency')|float < 30 or states('sensor.grid_frequency')|float > 100 %}
              Not Measured
            {% else %}
              {{ states('sensor.grid_frequency') }}
            {% endif %}
        unit_of_measurement: "Hz"
      modbus_grid_voltage:
        
        friendly_name: 'Grid Voltage'
        value_template: >-
            {% if states('sensor.grid_voltage')|float < 180 or states('sensor.grid_voltage')|float > 300 %}
              Not Measured
            {% else %}
              {{ states('sensor.grid_voltage') }}
            {% endif %}
        unit_of_measurement: "V"
      modbus_inverter_status:
        
        friendly_name: 'Inverter Status'
        value_template: >-
            {% if is_state('sensor.sma_status', '307' ) %}
              OK
            {% elif is_state('sensor.sma_status', '303' ) %}
              Off
            {% elif is_state('sensor.sma_status', '455' ) %}
              Warning
            {% elif is_state('sensor.sma_status', '35' ) %}
              Fault
            {% endif %}
      modbus_grid_contactor:
        
        friendly_name: 'Grid contactor'
        value_template: >-
            {% if is_state('sensor.sma_grid', '51' ) %}
              Closed
            {% else %}
              Open
            {% endif %}    
  - platform: integration
    source: sensor.modbus_sma_pv_power_kw
    name: Panneaux_Solaires
    unit_time: h
    round: 2
    method: left
homeassistant:
    customize: !include customize.yaml

And in the customize.yaml

sensor.Panneaux_Solaires:
  state_class: total_increasing
  device_class: energy
  unit_of_measurement: kWh
  last_reset: '2022-11-02T11:35:23.862268+00:00'

Once done in the Energy Panel configuration, you can choose the Panneaux_Solaires sensor
Settings - Dashoards - Energy

2 Likes

hello
I will have a sunny boy 6kWc + SMA energy meter in the next few days.
I’ve understood that modbus connection is better than HA sma integration for more values and value in real time. Am I right?
I’ve read the code above to establish the modbus connection from HA to your inverter, but does modbus is initially integrate into HA, and do I have to activate or manage something on SMA inverter interface to activate modbus connection?
We can switch in mp if you want, I’m French.

Hey guys,

I also had a hard time in integrating devices with MODbus Interface in homeassistant… it was not SMA but just to give you an hint:
I stopped working with the modbus integration from hassio and solved the communication in the NODE-RED App because this was more easy to find errors…:

Best greetings,
Alex

Is your configuration still working fine?
I have an issue when PV production is Zero, no zero value i recevie from modbus but 2MW value since some weeks

My first post here, but a big thank you! :grinning:. The contributions by @chris_ka and @crumpy were all that I needed to get my SMA solar panel setup in the HA energy dashboard along my other Enphase setup.

Hey there,
great thanks to all of you for all your information. Helped me a lot with my project.

Now i´m stuck on this question:
How can i read out the actual Power consumption of my house, what comes out of the grid and goes into it (aktueller Verbrauch, Netzeinspeisung und Netzbezug)? I can see, some of you have already solved this, but i don´t get data here.

My configuration: Sunny Tripower STP 9000 TL, Sunny Boy 2.0, Modbus is working fine for some registers.

Does anyone have a register/address list for my inverter?

Can someone share some details to get these data? yaml code or noder red?

In my case this information comes from another source: I use a Homewizard energy meter attached to the P1 port of my electricity meter.

This data is not known by my Sunny Tripower and I suspect it will be the same in your situation.

Hi all, i have a problem to integrate the Power consumption of my House (30865) as well as the grid feed (30867) to have the full view in my Dashboard. In general Modbus is working, but for these two register I get always this value: 2.147.483.648. I have the inverter STP 15000TL-30 and the smart home manager 2.0. As I understood the SHM2 should send the information (via Multicast) to the Inverter. Maybe this process ist not working and the SHM2 ist not overwriting the values in the respective register of the Inverter? In the other side all relevant data are available in my Sunnyportal. I am very confused and have waste a lot of time to fix it in my own. Hopefully someone can help me. Many thanks in advance.

Hi, i have the same inverter.

Can anyone share their config?

I ve have some troubles finding the correct modbus adress numbers

There are so many examples here and as far as I know the SMA all use the same addresses. Just look further up, otherwise look for the WR type at SMA and download the document on the WR.
https://www.sma.de/service/downloads

Thanx

I use these pdfs.

I have a battery aswell and im not sure which adresses to use to see how much battery is charging or discharging

I’m sorry I don’t have a battery yet, but you’ll definitely find it here under SMA.

Any idea, why

SMA_Grid contactor works and show Open / Closed

and

SMA_Inverter_status show 307 and not OK

sensor:
  - platform: template
    sensors:
      modbus_inverter_status:
        friendly_name: 'SMA_Inverter Status'
        value_template: >-
            {% if is_state('sensor.sma_status', '307' ) %}
              OK
            {% elif is_state('sensor.sma_status', '303' ) %}
              Off
            {% elif is_state('sensor.sma_status', '455' ) %}
              Warning
            {% elif is_state('sensor.sma_status', '35' ) %}
              Fault
            {% endif %}

      modbus_grid_contactor:
        friendly_name: 'SMA_Grid contactor'
        value_template: >-
            {% if is_state('sensor.sma_grid', '51' ) %}
              Closed
            {% else %}
              Open
            {% endif %} 

Does anybody has a working config for a system with a Sunnyboy SB-xxxx TL with a modbus/tcp webconnect module (without a webserver). All the examples i found don’t work.
I am using Home Assistant 2023.1.7

the PV + modbus webconnect module are working fine, because in another tool i can get the data etc.

Sunny Boy 3600 TL-21

Config.yaml

sensor: !include sensor.yaml

modbus:
  - name: SMA
    type: tcp
    host: 192.168.xxx.xxx
    port: 502
    sensors:
      - name: SMA_Power_AC
        state_class: measurement
        unit_of_measurement: W
        slave: 3
        address: 30775
        count: 2
        data_type: uint32
        scan_interval: 10
      - name: SMA_PV_Daily_Yield
        unit_of_measurement: kWh
        state_class: measurement
        slave: 3
        address: 30517
        scan_interval: 60
        scale: 0.001
        precision: 3
        count: 4
        data_type: int64    
      - name: SMA_PV_Total_Production
        unit_of_measurement: MWh
        state_class: measurement
        slave: 3
        address: 30513
        scan_interval: 3600
        scale: 0.000001
        precision: 3
        count: 4
        data_type: int64
      - name: SMA_Grid Voltage
        unit_of_measurement: V
        slave: 3 
        address: 30783
        scan_interval: 120
        count: 2
        scale: 0.01
        precision: 2
        data_type: int32
      - name: SMA_Grid frequency
        unit_of_measurement: Hz
        slave: 3 
        address: 30803
        scan_interval: 120
        count: 2
        scale: 0.01
        precision: 2
        data_type: uint32
      - name: SMA_temp
        unit_of_measurement: °C
        slave: 3
        address: 30953
        scan_interval: 60
        count: 2
        scale: 0.1
        precision: 1
        data_type: int32
      - name: SMA_status
        slave: 3
        address: 30201
        scan_interval: 10
        count: 2
        data_type: int32
      - name: SMA_grid
        slave: 3
        address: 30217
        scan_interval: 60
        count: 2
        data_type: uint32
      - name: SMA_Insulation
        slave: 3
        address: 30225
        scan_interval: 120
        count: 2

new file in config/

Sensor.yaml

 - platform: template
   sensors:
     modbus_sma_pv_power:
       friendly_name: 'SMA_Power Output'
       value_template: >-
           {% if states('sensor.sma_power_ac')|float < 0 or states('sensor.sma_power_ac')|float > 10000 %}
             0
           {% else %}
             {{ states('sensor.sma_power_ac') }}
           {% endif %}
       unit_of_measurement: "W"
       icon_template: mdi:flash-circle
     modbus_sma_pv_power_kw:
       friendly_name: 'SMA_Power Output kW'
       value_template: >-
           {% if states('sensor.sma_power_ac')|float < 0 or states('sensor.sma_power_ac')|float > 10000 %}
             0
           {% else %}
             {{ states('sensor.sma_power_ac')|float / 1000 }}
           {% endif %}
       unit_of_measurement: "kW"
       icon_template: mdi:flash-circle
     modbus_sma_pv_apparent_power:
       friendly_name: 'SMA_Apparent Power'
       value_template: >-
           {% if states('sensor.sma_apparent_power')|float < 0 or states('sensor.sma_apparent_power')|float > 10000 %}
             0
           {% else %}
             {{ states('sensor.sma_apparent_power') }}
           {% endif %}
       unit_of_measurement: "VA"
       icon_template: mdi:flash-circle
     modbus_sma_pv_reactive_power:
        
       friendly_name: 'SMA_Reactive Power'
       value_template: >-
           {% if states('sensor.sma_reactive_power')|float < 0 or states('sensor.sma_reactive_power')|float > 10000 %}
             0
           {% else %}
             {{ states('sensor.sma_reactive_power') }}
           {% endif %}
       unit_of_measurement: "VAr"
       icon_template: mdi:flash-circle
     modbus_sma_pv_residual:
        
       friendly_name: 'SMA_Residual Current'
       value_template: >-
           {% if states('sensor.sma_residual_current')|float < 0 or states('sensor.sma_residual_current')|float > 10000 %}
             0
           {% else %}
             {{ states('sensor.sma_residual_current') }}
           {% endif %}
       unit_of_measurement: "mA"
       icon_template: mdi:flash-circle
     modbus_sma_temperature:
        
       friendly_name: 'SMA_Inverter Temp'
       value_template: >-
           {% if states('sensor.sma_temp')|float < 0 or states('sensor.sma_temp')|float > 100 %}
             0
           {% else %}
             {{ states('sensor.sma_temp') }}
           {% endif %}
       unit_of_measurement: "°C"
     modbus_grid_frequency:
        
       friendly_name: 'SMA_Grid Frequency'
       value_template: >-
           {% if states('sensor.sma_grid_frequency')|float < 30 or states('sensor.sma_grid_frequency')|float > 100 %}
             Not Measured
           {% else %}
             {{ states('sensor.sma_grid_frequency') }}
           {% endif %}
       unit_of_measurement: "Hz"
     modbus_grid_voltage:
       
       friendly_name: 'SMA_Grid Voltage'
       value_template: >-
           {% if states('sensor.sma_grid_voltage')|float < 180 or states('sensor.sma_grid_voltage')|float > 300 %}
             Not Measured
           {% else %}
             {{ states('sensor.sma_grid_voltage') }}
           {% endif %}
       unit_of_measurement: "V"
     modbus_inverter_status:
       
       friendly_name: 'SMA_Inverter Status'
       value_template: >-
           {% if is_state('sensor.sma_status', '307' ) %}
             OK
           {% elif is_state('sensor.sma_status', '303' ) %}
             Off
           {% elif is_state('sensor.sma_status', '455' ) %}
             Warning
           {% elif is_state('sensor.sma_status', '35' ) %}
             Fault
           {% endif %}
     modbus_grid_contactor:
        
       friendly_name: 'SMA_Grid contactor'
       value_template: >-
           {% if is_state('sensor.sma_grid', '51' ) %}
             Closed
           {% else %}
             Open
           {% endif %} 

This should work. I can´t test at the moment because it´s dark. :slight_smile:

thanks !

still got error in my logfile:

Logger: pymodbus.client.sync
Source: components/modbus/modbus.py:386
First occurred: 09:38:19 (50 occurrences)
Last logged: 09:41:02

  • Connection to (192.168.2.149, 502) failed: timed out
  • Connection to (192.168.2.149, 502) failed: [Errno 113] Host is unreachable

did your version is still working?

Sorry, you are right. It doesn´t work anymore. Perhaps I will find a solution.