MODBUS data from SMA Inverter

Hello.
In my case modbus platform configured for sma reading is working well… Exept for some modbus communication dopout. Tipically one, maximum two times per day I need to restart Ha because every sensor from modbus sma gone to value 0 (zero)
After HA restart, everything is ok.
This happened only with new integration. Before Core update everything was ok.

Are there any settings to put, to avoid this behaviour.?
Below mine configuration

On config.yaml

modbus:
  - name: sma
    type: tcp
    host: 192.168.1.51
    port: 502
    sensors:
    # - platform: modbus
      # registers:
      - name: SMApwrL1
        # hub: sma
        unit_of_measurement: kW
        slave: 3
        address: 30777
        count: 2
        data_type: uint
        scale: 0.001
        precision: 2
      - name: SMApwrL2
        # hub: sma
        unit_of_measurement: kW
        slave: 3
        address: 30779
        count: 2
        data_type: uint
        scale: 0.001
        precision: 2
      - name: SMApwrL3
        # hub: sma
        unit_of_measurement: kW
        slave: 3
        address: 30781
        count: 2
        data_type: uint
        scale: 0.001
        precision: 2
      - name: SMAcurL1
        # hub: sma
        unit_of_measurement: A
        slave: 3
        address: 30977
        count: 2
        data_type: uint
        scale: 0.001
        precision: 2
      - name: SMAcurL2
        # hub: sma
        unit_of_measurement: A
        slave: 3
        address: 30979
        count: 2
        data_type: uint
        scale: 0.001
        precision: 2
      - name: SMAcurL3
        # hub: sma
        unit_of_measurement: A
        slave: 3
        address: 30981
        count: 2
        data_type: uint
        scale: 0.001
        precision: 2
      - name: SMAvoltL1
        # hub: sma
        unit_of_measurement: V
        slave: 3
        address: 30783
        count: 2
        data_type: uint
        scale: 0.01
        precision: 1
      - name: SMAvoltL2
        # hub: sma
        unit_of_measurement: V
        slave: 3
        address: 30785
        count: 2
        data_type: uint
        scale: 0.01
        precision: 1
      - name: SMAvoltL3
        # hub: sma
        unit_of_measurement: V
        slave: 3
        address: 30787
        count: 2
        data_type: uint
        scale: 0.01
        precision: 1
      - name: SMAnetHZ
        # hub: sma
        unit_of_measurement: Hz
        slave: 3
        address: 30803
        count: 2
        data_type: uint
        scale: 0.01
        precision: 2
      - name: SMApwr
        # hub: sma
        unit_of_measurement: kW
        slave: 3
        address: 30775
        count: 2
        data_type: int
        scale: 0.001
        precision: 2
      - name: SMAtotal
        # hub: sma
        unit_of_measurement: kWh
        slave: 3
        address: 30529
        count: 2
        data_type: uint
        scale: 0.001
        precision: 2
      - name: SMAtoday
        # hub: sma
        unit_of_measurement: kWh
        slave: 3
        address: 30535
        count: 2
        data_type: uint
        scale: 0.001
        precision: 2
      - name: SMAdevtype
        # hub: sma
        slave: 3
        address: 30053
        count: 2
        data_type: int 
      - name: SMAgridrelay
        # hub: sma
        slave: 3
        address: 30217
        count: 2
        data_type: int
 

On sma.yaml into packages

  - platform: template
    sensors:
      sma_power_l1:
        value_template: "{% if states('sensor.smapwrl1')|float > 10000 %}0{% else %}{{ states('sensor.smapwrl1') | float | round(2)}}{% endif %}"
        friendly_name: "sma power L1"
        unit_of_measurement: 'kW'
        icon_template: mdi:solar-power
      sma_power_l2:
        value_template: "{% if states('sensor.smapwrl2')|float > 10000 %}0{% else %}{{ states('sensor.smapwrl2') | float | round(2)}}{% endif %}"
        friendly_name: "sma power L2"
        unit_of_measurement: 'kW'
        icon_template: mdi:solar-power
      sma_power_l3:
        value_template: "{% if states('sensor.smapwrl3')|float > 10000 %}0{% else %}{{ states('sensor.smapwrl3') | float | round(2)}}{% endif %}"
        friendly_name: "sma power L3"
        unit_of_measurement: 'kW'
        icon_template: mdi:solar-power
      sma_corrente_l1:
        value_template: "{% if states('sensor.smacurl1')|float > 100 %}0{% else %}{{ states('sensor.smacurl1') | float | round(2)}}{% endif %}"
        friendly_name: "sma ampere L1"
        unit_of_measurement: 'A'
        icon_template: mdi:solar-power
      sma_corrente_l2:
        value_template: "{% if states('sensor.smacurl2')|float > 100 %}0{% else %}{{ states('sensor.smacurl2') | float | round(2)}}{% endif %}"
        friendly_name: "sma ampere L2"
        unit_of_measurement: 'A'
        icon_template: mdi:solar-power
      sma_corrente_l3:
        value_template: "{% if states('sensor.smacurl3')|float > 100 %}0{% else %}{{ states('sensor.smacurl3') | float | round(2)}}{% endif %}"
        friendly_name: "sma ampere L3"
        unit_of_measurement: 'A'
        icon_template: mdi:solar-power
      sma_tensione_l1:
        value_template: "{% if states('sensor.smavoltl1')|float > 1000 %}230{% else %}{{ states('sensor.smavoltl1') | float | round(2)}}{% endif %}"
        friendly_name: "sma volt L1"
        unit_of_measurement: 'V'
        icon_template: mdi:solar-power
      sma_tensione_l2:
        value_template: "{% if states('sensor.smavoltl2')|float > 1000 %}230{% else %}{{ states('sensor.smavoltl2') | float | round(2)}}{% endif %}"
        friendly_name: "sma volt L2"
        unit_of_measurement: 'V'
        icon_template: mdi:solar-power
      sma_tensione_l3:
        value_template: "{% if states('sensor.smavoltl3')|float > 1000 %}230{% else %}{{ states('sensor.smavoltl3') | float | round(2)}}{% endif %}"
        friendly_name: "sma volt L3"
        unit_of_measurement: 'V'
        icon_template: mdi:solar-power
      sma_frequenza_di_rete:
        value_template: "{% if states('sensor.smanethz')|float > 1000 %}50{% else %}{{ states('sensor.smanethz') | float | round(2)}}{% endif %}"
        friendly_name: "sma frequenza di rete"
        unit_of_measurement: 'Hz'
        icon_template: mdi:solar-power
      sma_power:
        value_template: "{% if states('sensor.smapwr')|float < 0 %}0{% else %}{{ states('sensor.smapwr') | float | round(2)}}{% endif %}"
        friendly_name: "sma Power"
        unit_of_measurement: 'kW'
        icon_template: mdi:solar-power
      sma_total:
        value_template: "{% if states('sensor.smatotal')|float < 0 %}0{% else %}{{ states('sensor.smatotal') | float | round(3)}}{% endif %}"
        friendly_name: "sma Total"
        unit_of_measurement: 'kWh'
        icon_template: mdi:solar-power
      sma_today:
        value_template: "{% if states('sensor.smatoday')|float > 1000 %}0{% else %}{{ states('sensor.smatoday') | float | round(2)}}{% endif %}"
        friendly_name: "sma Today"
        unit_of_measurement: 'kWh'
        icon_template: mdi:solar-power
      sma_device_type:
        value_template: "{% if states('sensor.smadevtype')|float == 9165 %}SunnyBoy3.6{% else %}?{% endif %}"
        friendly_name: "sma device type"
        icon_template: mdi:solar-power
      sma_grid_relay:
        value_template: "{% if states('sensor.smagridrelay')|float == 51 %}Chiuso{% elif states('sensor.smagridrelay')|float == 311 %}Aperto{% elif states('sensor.smagridrelay')|float == 16777213 %}Spento{% else %}?{% endif %}"
        friendly_name: "sma grid relay"
        icon_template: mdi:solar-power

Thank you very much

Daniele

1 Like

I’m seeing this same issue on my SMA Tripower 8.0. The inverter reboots once in a while during nighttime. Afterwards the modbus intergration doesn’t start anymore unless I restart my HA instance.

I think this will be fixed in 2021.7.4.
See here: Allow pymodbus to reconnect in running system (not startup) by janiversen · Pull Request #53020 · home-assistant/core · GitHub

Hi Daniele,
Ciao.

I have inverter with modbus, original integration and SMA Energy meter addon.
With the last update the integration and the Energy meter addon doesn’t show me the current house consumption (il consumo della casa istantaneo, che esso sia da grid o da pv o aggregato)

Do you have the sensor working? Is there a way through modbus to have that sensor?

Thank you
Grazie mille!

Hi.
Unfortunately I didn’t have that meter.
I bought a shelly PM, and power from grid a da from/to batteries is measured with this.
With modbus integration I’m able to read data from sma., with last update of core, without any interruption.

I fixed my SMA Modbus configuration and it’s working again:

# Modbus
modbus: 
  - type: tcp
    host: 192.168.2.155 # SMA TriPower
    port: 502
    name: "sma"
    close_comm_on_error: true
    delay: 5
    timeout: 5
    sensors:
      - name: PV_Gesamtertrag
        unit_of_measurement: kWh
        slave: 3
        address: 30531
        input_type: input
        count: 2
      - name: PV_Leistung
        unit_of_measurement: W
        slave: 3
        address: 30775
        input_type: input
        count: 2
      - name: PV_Tagesertrag
        unit_of_measurement: Wh
        slave: 3
        address: 30517
        count: 4
        data_type: int
      - name: Netzverbrauch
        slave: 3
        address: 30865
        unit_of_measurement: 'W'
        count: 2
        data_type: uint
1 Like

I hope someone can help me to enable a connection with my SMA Inverter Tripower 15000 and HA. I can connect with Solar Explorer and I have everything enabled. But so far I can’t make a connection with HA and SMA. What do I wrong? See screenshots of my settings.

check my post, I had the same issue, the format of the configuration changed.

1 Like

This is what I have right now, after your suggestion in your post.

Modbus

modbus:

  • type: tcp
    host: 192.168.1.22 # SMA TriPower
    port: 502
    name: “SMA”
    close_comm_on_error: true
    delay: 5
    timeout: 5
    sensors:
    • name: PV_totale_opbrengst
      unit_of_measurement: kWh
      slave: 3
      address: 30531
      input_type: input
      count: 2
    • name: PV_Vermogen
      unit_of_measurement: W
      slave: 3
      address: 30775
      input_type: input
      count: 2
    • name: PV_Dagopbrengst
      unit_of_measurement: Wh
      slave: 3
      address: 30517
      count: 4
      data_type: int
      But still the same error after reboot HA. I see the sensors under Entities, but with errors.

If I do a Portscan for IP of my Inverter, than no ports are scanned. Maybe thats the issue? Or do I need to setup a password and username in the configuration.yaml?

No, there’s no need for a username or password using Modbus. The Modbus server is running on your inverter?

Yes I have. Thats the strange thing of it. It looks that evertything is set well.
2021-08-10_08-59-37

The message: This entity (“sensor.smatoday”) does not have a unique ID, therefore its settings cannot be managed from the UI. See the documentation for more detail. Maybe the Unique ID is something for my problem?

Huge thank you Thorsten for your fixed modbus. Worked for me.
@rbusschner I have the same message but getting values.

sma1sma3

Nice to hear that it works for you. Can you send a sample of your config.yaml? Did you make other changes as well?
If you do a port scan for the inverter ip, is than port 502 open for that?

Found the options to change the State. It’s unavailable.
2021-08-16_13-04-48

Well it work only during daytime, at night time Im getting negative crazy high number. yaml was copy pasted from Thorsten. I am trying now chris_ka setup with node red but having trouble to figure out how to get current solar production out as he has there only total and daily yeild. I’m not coder so I have no idea what to do :slight_smile:
edit: gave up on chris_ka node red setup for now, it works for yield but have no idea how to get out current production. Went back to Thorsten setup but need to figure out what to do about the negative numbers during night.

Posting pics of my yaml.sma yaml

Have you figure this out? I have the same problem and going nuts from it. Thx

Does anyone has the problem with power value from invertor during night? I know some people had but havent seen solution to it. If you sort it out could you please share how?sma night

Hi everyone,
i had from SMA solar all the registers and codes for our inverters.

There are tons of registers that are of no usage and i need someone who can help me to fin the correct registers for all the sensors on the Sma solar inverter UI.

i will share an excel file with anyone who wish to help.

Thank you!

Hello everybody,

I have my modbus sma connection running, but how do I get it to homeassistant energy solar?

Best regards,
Stefan

If you don’t have kWh values, use: