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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

icefest opened this issue · comments

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:

  • Model: [SH6.0RS]

  • The inverter is connected via (mark one)

    • [] LAN (internal port)
    • WiNet-S (LAN)
    • [] WiNet-S (WLAN)
  • Are you using a Modbus Proxy (mark one)

    • [] yes
    • no
    • [] I don't know what that is

Home Assistant version:

  • Version: [e.g. 2024.5.5]

modbus_sungrow.yaml:

  • Version/ time stamp : [2024-04-05] (see header of the file)
  • I ensured to use the most recent version

** Inverter Firmware Status:**

  • I made sure that the newest firmware is installed via the installers account

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.