hultenvp / solis-sensor

HomeAssistant integration for the SolisCloud PV Monitoring portal via SolisCloud API
Apache License 2.0
207 stars 42 forks source link

sensor.solis_battery_power is always negative #249

Closed barthoefs closed 1 year ago

barthoefs commented 1 year ago

Battery power shows always as negative (charging and discharging). Battery current does show as positive and negative when charging and discharing (see screenshots). Battery power should follow the state of current.

Is there a way to align this? When current show charging, battery power shows charging?

I am using latest everything.

Screenshots sensor.solis_battery_power image. sensor.solis_battery_current image

barthoefs commented 1 year ago

This is my current "fix":

template:
  - sensor:
      - name: "Battery Power Corrected"
        unit_of_measurement: W
        device_class: power
        icon: mdi:battery
        state: >-
          {% if states('sensor.solis_battery_current') | float <= 0 %}
            {{ states('sensor.solis_battery_power') }}
          {% else %}
            {{ states('sensor.solis_battery_power') | float | abs }}
          {% endif %}
hultenvp commented 1 year ago

Interestingly, the code actually already has a fix for wrong bat power sign, when it was always positive. But in your case, the power seems to be always negative, instead of always positive. I will extend the fix to also check for the inverse, but maybe it's also good to submit a ticket with Solis that they finally fix their API.

            # turn batteryPower negative when discharging (fix for https://github.com/hultenvp/solis-sensor/issues/158)
            try:
                if self._data[BAT_CURRENT] < 0 and self._data[BAT_POWER] > 0:
                    self._data[BAT_POWER] = self._data[BAT_POWER] * -1
            except KeyError:
                pass
matthewbyrne commented 1 year ago

I'm still getting this... Though battery is always positive for me. This was fine until I upgraded to the latest a couple of days ago.