fsaris / home-assistant-zonneplan-one

Unofficial Zonneplan integration for Home Assistant
https://github.com/fsaris/home-assistant-zonneplan-one
MIT License
104 stars 17 forks source link

Use live data as last values #91

Closed yurnih closed 6 months ago

yurnih commented 8 months ago

Currently, the PV entities are based on meta values. These values get updated only when getting data from the user accounts-endpoint. Since some versions it receives an update every hour. However, we are also polling live data every 5 minutes with newer "last values" but not using those. With this commit I use the latest values to update the meta data, so the entities gets updated in HA.

It works locally for me for my configuration (1 solar panel system). I do not think it will works with multiple, although I do not know how the Zonneplan gives us these data in such configurations.

fsaris commented 8 months ago

so since we are not updating the account info every hour anymore some sensor data isn't updated correctly anymore?

isn't it easier to change the origin of the sensor data instead of introducing this calculation? I'm even for updating the account data every 5 minutes again. Adding more complexity in converting the incoming data will only give trouble at a later point in time.

Guess this is for all meta fields used in https://github.com/fsaris/home-assistant-zonneplan-one/blob/main/custom_components/zonneplan_one/const.py

yurnih commented 8 months ago

The easiest way is to update the account data every 5 minutes again. Changing the const to use the last measurement from the live data is during the day okay, but it will need extra checks if the data is available (live data shows only measurements from the last 3 hours, at night and in morning the list is none). The total for the inverter is not available from the live data, this property only exists in the account info. To get an update for that property it requires some calculation when using only the live data.

I don't know if it gives issues with the zonneplan api (rate limit of 60 in headers), since if it is like app-style, requests get mainly send to the chart-endpoints as somehow mentioned in #89.

martijnrusschen commented 8 months ago

I'm seeing similar issues where the solar power data is only fetched once an hour right now.

Ascathon commented 8 months ago

I thought because of recent changes all is updated every hour, but I was wrong. Now the sun is shining I saw yield_today getting updates, but last_measured_value only once a month. So not really (just) a rate limit issue?

martijnrusschen commented 8 months ago

The requests don't seem to be consistently every hour. Based on today's data here are some data points it pulled:

I enabled the debug logging to understand if it's hitting an error or rate limit, but I can't see anything weird. Once it's making the request it comes in fine, but it's not doing it every 5 minutes anymore. @fsaris would it make sense to revert to a previous version to test if it works fine in a previous iteration?

martijnrusschen commented 8 months ago

I did a reboot at 12:08 which seems to indicate it may pull directly at a reboot. I will try to confirm that.

martijnrusschen commented 8 months ago

Another reboot done at 12:26 and it pulled new data after the reboot. Expecting the next fetch will be at 13:26 now.

fsaris commented 8 months ago

@martijnrusschen the accounts endpoint is called once each hour. So if your install starts at 1:12 the next fetch wil be 2:12 and when finished a new timer for 1hour is set.

For more info about the once per hour see #89 #83 and #49

@rdgout @developmentzonneplan is there a API endpoint we can call to get the meta data that's part of the user-accounts/me endpoint without calling the accounts/me? We are interested in the pv totals

fsaris commented 6 months ago

@yurnih can't you use yield today? That is updated more often and with more precision.

fsaris commented 6 months ago

Think this will fix the issue https://github.com/fsaris/home-assistant-zonneplan-one/commit/1d628d8d3144ef08f746c0b570b5db336156ff8d please test main version