mkaiser / Sungrow-SHx-Inverter-Modbus-Home-Assistant

Sungrow SH Integration for Home Assistant for SH3K6, SH4K6, SH5K-20, SH5K-V13, SH3K6-30, SH4K6-30, SH5K-30, SH3.RS, SH3.6RS, SH4.0RS, SH5.0RS, SH6.0RS, SH5.0RT, SH6.0RT, SH8.0RT, SH10RT, SH5.0RT-20, SH6.0RT-20, SH8.0RT-20, SH10RT-20, SH5.0RT-V112, SH6.0RT-V112, SH8.0RT-V112, SH10RT-V112, SH5.0RT-V122, SH6.0RT-V122, SH8.0RT-V122, SH10RT-V122, SH4.6R
375 stars 95 forks source link

16bit integer wraparound error on Single phase hybrid inverters battery current sensor #304

Closed icefest closed 1 month ago

icefest commented 5 months ago

Before you create an issue, make sure to update to the current version of modbus_sungrow.yaml

Describe the bug:

There is an issue with the battery current sensor. I think this is a signed integer, with one decimal point precision.

When the battery is discharging current is positive. When the battery is charging the current should be negative. What does happen is that the current is instead equal to battery_current - 6553.5

This only occurs on some hybrid sensors. SH6.0RS, SH10.0RS

I think this is because instead of having a signed 16 bit integer, they are using an unsigned 16 bit integer and are just using integer wraparound to transmit this information.

Given that no inverter will ever take a load of 3000 amps, I think you could correct for this without affecting other inverters with something like this. I cant work out how to apply it directly to the modbus sensor, or if it can only be done via a template. In any case, it's working for me now!

    - name: Battery Current Signed  # on SHxx.0RS inverters Sungrow uses an unsigned 16-bit integer to represent current, negative current wraps around below zero
      unit_of_measurement: "A"
      device_class: current
      unique_id: sensor.battery_current_signed
      state_class: measurement
      availability: "{{states('sensor.battery_current')|is_number }}"
      state: >-
          {% set positive = states('sensor.battery_current') | float  %}
          {% set negative = states('sensor.battery_current') | float - 6553.5 %}
          {% if positive > 3000 %}
            {{ negative }}
          {% else %}
            {{ positive }}
          {% endif %}

Your Sungrow inverter:

Home Assistant version:

modbus_sungrow.yaml:

Inverter Firmware Status:

To Reproduce Steps to reproduce the behavior: look at sensor.battery_current

Expected behavior A clear and concise description of what you expected to happen.

Screenshots SH6.0RS image SH10.0RS: image

Additional context Add any other context about the problem here.

github-actions[bot] commented 2 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 1 month ago

This issue was closed because it has been inactive for 14 days since being marked as stale.