kellerza / pysma

Async library for SMA Solar's WebConnect interface
MIT License
59 stars 51 forks source link

total_yield returns 0 during the night #93

Closed somm15 closed 2 years ago

somm15 commented 2 years ago

Hello all,

I observed yesterday a total_yield value of zero during the night. While this is a great improvement for the other sensors, this is a problem for this one. The energy tab is now entirely incorrect because the total_yield went from 12 000 to 0 then to 12 000 kWh.

I'm not familiar enough with the library to guarantee that it is a problem or to make a PR.

Regards,

flopp999 commented 2 years ago

Hi

The value is coming from the inverter so this is nothing done by the code. One way could be to store the value and done change it if new value is lower or not collect any data if the value is 0

somm15 commented 2 years ago

Are you sure it comes from the inverter? I'm running this for more than a year and I never received a 0 value for the total_yield. It only happened with the last home assistant release. I thought it could be due to the new "if" returning 0 instead of None.

flopp999 commented 2 years ago

Ok then it must be Home Assistant that makes the error. At least I don't get that error. I do not use Home Assistant I only use this package in a Python code

somm15 commented 2 years ago

Well, I'm not sure you won't get it

# SMA will return None instead of 0 if if no power is generated
# If we have extracted a path, we know the value was previously
# present and res can be set to 0
if res is None:
res = 0

Not sure if this applies to total_yield but I think so.

rklomp commented 2 years ago

I think this could be caused by this change. In my installation total_yield will not go to unknown (and thus 0 now), but I can imagine this could cause incorrect behavior in if it does happen.

I will have a look if I can find a better solution for this.

somm15 commented 2 years ago

I can wait and check if it happens again if needed but the timing (update this week) is quite suspicious. Last week, around the exact same time, I have no value in the graph. This week, same time, zero.

By the way, it's a very useful change. I had nasty templates in Home Assistant to avoid "Unknown" during the night for Power. Thanks a lot !

(but I don't have any template for total_yield)

dennistd4 commented 2 years ago

In my installation total_yield will not go to unknown (and thus 0 now), but I can imagine this could cause incorrect behavior in if it does happen.

It does happen when you restart your Home Assistant while the inverter is at sleep (during the night).

rklomp commented 2 years ago

I think setting to 0 is only useful for the sensors with unit "W". Other sensors don't really benefit of this feature, so I proposed https://github.com/kellerza/pysma/pull/94.

Let me know what you think.

dennistd4 commented 2 years ago

I think it's a good solution. Hopefully it's implemented in Home Assistant as soon as possible, because tonight it went to 0 again...

dennistd4 commented 2 years ago

I still have this problem, even though Home Assistant is updated to 2021.12.9. Is this fix still not implemented?