Kubiac / homebridge-solaredge-realtime

Apache License 2.0
5 stars 3 forks source link

ScalingFactor failing if output above 3.000 Watt #5

Open ovehei opened 2 years ago

ovehei commented 2 years ago

Describe The Bug: In my system the 0.10 plugin reports 0 Watt as soon as my SolarEdge output more than 3.000 Watt. I see it relates to the scale factor SF value which becomes "0" but I guess it should become 1 (10^0)

To Reproduce: Use a SolarEdge Inverter with more than 3 kW output

Expected behavior: I modified the solaredgeInverter.ts code to convert the signed integer (i16) number as shown below, and I have verified this on my local setup, and it should work on any SolarEdge Inverter compliant with SunSpec Logging.

computeResult(factor : number, scalingFactor : number) : number | undefined {

// Converting (i16) value from inverter
if ((scalingFactor & 0x8000) > 0) {
  scalingFactor = scalingFactor - 0x10000;
}
const result = factor * 10 ** (scalingFactor);
this.platform.log.debug('Computed:', result);
return Math.max(result, 0.0001);

}

Logs: From debugging before fix: [30/03/2022, 10:22:54] [SolaredgeRealTime] Connected [30/03/2022, 10:22:54] [SolaredgeRealTime] Received Power: [ 29990 ] [30/03/2022, 10:22:54] [SolaredgeRealTime] Interpreted power value: 29990 [30/03/2022, 10:22:54] [SolaredgeRealTime] Received SF: [ 65535 ] [30/03/2022, 10:22:54] [SolaredgeRealTime] Computed: 2999 [30/03/2022, 10:22:54] [SolaredgeRealTime] Updating Ambient Light Level: 2999 [30/03/2022, 10:22:54] [SolaredgeRealTime] closed connection to xx [30/03/2022, 10:22:57] [SolaredgeRealTime] Connecting to Inverter at xx [30/03/2022, 10:22:57] [SolaredgeRealTime] Connected [30/03/2022, 10:22:57] [SolaredgeRealTime] Received Power: [ 3017 ] [30/03/2022, 10:22:57] [SolaredgeRealTime] Interpreted power value: 3017 [30/03/2022, 10:22:57] [SolaredgeRealTime] Received SF: [ 0 ] [30/03/2022, 10:22:57] [SolaredgeRealTime] Computed: 0 [30/03/2022, 10:22:57] [SolaredgeRealTime] Updating Ambient Light Level: 0.0001

Environment: SolarEdge SE5000

Kalie15 commented 2 years ago

Hi! I have implemented your changes and my problems are solved! Thank you so much!

Beside if that I had to user registers 40100 and 40101(Power Signed = TRUE) to see the DC watts, with default registers I had only seen what is exported to the grid (when nothing is exported what I use in my home).

Thanks a lot again!

Kalie15 commented 2 years ago

Oups... when I'm above some other value the same happens again...

Connecting to Wechselrichter at x [6/6/2022, 5:47:57 PM] [SolaredgeRealTime] Connected [6/6/2022, 5:47:57 PM] [SolaredgeRealTime] Received Power: [ 6683 ] [6/6/2022, 5:47:57 PM] [SolaredgeRealTime] Interpreted power value: 6683 [6/6/2022, 5:47:57 PM] [SolaredgeRealTime] Received SF: [ 0 ] [6/6/2022, 5:47:57 PM] [SolaredgeRealTime] Computed: 0 [6/6/2022, 5:47:57 PM] [SolaredgeRealTime] Updating Ambient Light Level: 0.0001 [6/6/2022, 5:47:57 PM] [SolaredgeRealTime] closed connection to x

Kubiac commented 2 years ago

This is very weird behaviour. I removed a sanity check, that I thought to be useful and hope this fixes this. But the computation is very straight forward and should not have any unexpected edge case behaviour. Try Version 0.12