hultenvp / solis-sensor

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

solis_battery_power is always positive value #256

Closed matthewbyrne closed 1 year ago

matthewbyrne commented 1 year ago

Describe the bug Up until this week the solis_battery_power entity was negative while discharging, and positive while charging. Now it seems as though it is always positive.

Versions HA Version an deployment 2022.12.7 HACS version 1.30.1 Integration version v3.3.1

Screenshots

image
matthewbyrne commented 1 year ago

Feels like this change broke it https://github.com/hultenvp/solis-sensor/pull/250

hultenvp commented 1 year ago

Can you perhaps make a screenshot with both battery power and battery current?

matthewbyrne commented 1 year ago
image

From ~6am today was me charging the battery, and from 8am was me using the battery. As you can see, both are positive.

image
hultenvp commented 1 year ago

Thanks,

This is really not what I expected. I copy over the sign of the current and apply it to the power, because battery power is always positive for some people due to some silly bug in the Soliscloud API. You are using soliscloud, right, or are you using m.ginlong.com?

matthewbyrne commented 1 year ago

Correct. Soliscloud.

I've had to resort to @barthoefs fix from here: https://github.com/hultenvp/solis-sensor/issues/249#issuecomment-1379991258

hultenvp commented 1 year ago

Ughh, you are right, there is a mistake in the code. 🤦

            # turn batteryPower negative when discharging (fix for https://github.com/hultenvp/solis-sensor/issues/158)
            try:
                math.copysign(self._data[BAT_POWER],self._data[BAT_CURRENT])
            except KeyError:
                pass

should be:

            # turn batteryPower negative when discharging (fix for https://github.com/hultenvp/solis-sensor/issues/158)
            try:
                self._data[BAT_POWER] = math.copysign(self._data[BAT_POWER],self._data[BAT_CURRENT])
            except KeyError:
                pass