-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V3 api, more flexible formulas, persist storage #14
base: main
Are you sure you want to change the base?
Conversation
Add support for custom formulas Make multiple sensors instead of extra state attributes. Persist rolling window of data to save API calls on restart.
Takes a start and end offset and returns total rainfall between them. - For example, start_hour = -72, end_hour = 0 will show the total rainfall in the last 72 hours. *configurable lookback days, default to 30 *better API rate limit handling with configurable settings - backfills will now happen more slowly as permitted by limits - limit tracking data is persisited * add some tests
Rebased with main repo and added a few more features: *Implement new sensor type, total_rain.
|
With the new repository I get
I guess your json structure has changed, any hints to clear the persisted data |
Dang. I’ll fix that, but I’m away from my computer right now. For now, you should be able to delete the file under .storage/openweathermaphistory.history (STORAGE_KEY in the const file) |
That helped, moving onto the next issue :) I love testing other peoples code, sure beats people finding bugs in mine.
interesting that the data returned from the API has 'rain': {'3h': 1} not 'rain': {'1h': 1}
Another question, what is the behaviour if I set up two sensors with different locations? How will the persistent storage work and API counts. |
if it helps this is the URL/location I am running for:
weatherhist.py line 68, you have both lat and lon using latitude. |
https://openweathermap.org/history tells me that 3h is the rainfall for the last 3 hrs, so we need to subtract the previous 2 hours rainfall to get this hours rainfall. Why would they do this to us?! |
- use const variables instead of literals - store data unique to a lat/lon location - handle reading data from older schema - clean up some noisy logs around storing and loading data - log path when storing and loading data
For your other comments:
The persistence will now store in a file with the location included in the name. I'm open to suggestions on how to handle multiple locations better, I only have 1 location for mine.
Maybe we should also lower the default API rate limit settings so that 2-3 locations can be supported without having to mess with including rate limits in the config? |
For the '3h' issue I would simply divide the value by 3 that should be accurate enough and given they provide 3 periods with the same data it logically makes sense. Add the forecast as a new sensor makes sense, I was not planning to use it in my factor calculation but it opens up a lot of opportunities for the future I think the first option for multiple sensors is best as it matches the way HA supports sensors.
|
I can see that there is a lot happening, the calls are made regularly but, no sensor is created in HA. Are you seeing the same at your end? |
The sensors are working on my end, could you share the config you’re using ? |
I copied your GIT repository, I can try downloading again. I'm using the docker dev container and Visual Studio Code as my environment. |
Oh I was talking about the config for your sensor so I can try to replicate on my end |
Ah, sorry, here is the yaml
|
Got it, so you’ll need to add individual sensors under the The way it works now is you have one “platform” per lat/lon location, and then each “platform” can have multiple sensors under its “resources” list. Maybe we should just add the default sensor if none are specified to shrink down the minimal config? Something like this should work to just give you the default sensor on your default location:
Here’s a full example with 2 locations and multiple sensors at each
|
The reason for splitting it this way is to allow all the sensors at the same location to share the same set of data / api calls. Though we could also just achieve that on the backend if you think its more desirable to just have one “platform” configured and specify different locations on the sensor level in the resources list. |
- up to 3 locations with default settings - A backfill up to 5 days in first few mins after startup per location -Support "3h" in rain and snow data and add test -Skip observation if unexpected dt
- Remove old version and config option, only use v3 now
Responding to a few other comments:
Makes sense to me; I've added this as well as a warning log message if we see anything else unexpected in there. Hopefully, "1h" and "3h" is all we'll see.
I've made a change to the default API rate limits that should roughly accomplish this, though without a separate service. The default lookback is still 30 days, which is the maximum amount of data that we will keep in the rolling window and persistent store, but we will only backfill the first 5 shortly after startup. The way the backfilling works now is: Every 30s SCAN_INTERVAL:
The current limits are set to allow a backfill of 5 days in the first hour after a restart. In practice, this happens in the first 6 mins of the hour at a rate of 10 hours backfilled every 30s interval, then no backfilling for the rest of the hour until our initial requests roll off. The remaining 25 days of the full lookback window will then be slowly filled in over the next couple of days as daily and hourly limits permit. The default limits allow for up to 3 locations at a time without getting into paid API requests, assuming 0 persisted data at the start and all need a full backfill. If you already have a location configured, adding more should be okay, as the existing locations will only be using 24 requests per day once the backfills are complete. Another option could be to have 2 lookback windows configured, a |
You have been busy, I like what you have done and I am learning something new from your coding, I still think in COBOL :)
That makes sense, I believe that having a default resource will make it more user friendly, less yaml = less mistakes and most users just run with default settings. we also need to consider the complexity that is needed to build into the config flow. If you are looking for an example config flow (all be it overly complex) the irrigation custom component in my repository has config flow. I also like this option, if a user requests more than 5 days your existing rules will kick in.
I would consider getting the numeric value from the key and using it as the denominator, just to future proof it.
What are your plans to use the 30 days of data?
|
I still need to clean up my config flow code some more before I publish here, but it took me a while to get going so I wanted to give an update on how I think the config flow could work. Here's a screen record demo: Screen.Recording.2023-05-06-.mov |
The config flow is looking good, couple of things to consider:
I have taken your code (mostly) and put it into my latest checked in source. I have reworked:
|
…ther coroutines that might interrupt during a backfill
-Add backfill sensor type
Thanks. I've just pushed the code with the config flow. -The same Lat Lon can only be used once across all instances of the integration. |
Hi Trevor, I just pushed out a version 2 of the component, I think it covers most of your requirements, after all I stole a whole lot of your work, thanks. If you have time let me know what you think and we can add improvements from there. Cheers |
Add support for custom formulas and multiple factors.
Make multiple sensors instead of extra state attributes.
Make sensors SensorStateClass.MEASUREMENT for graphing and statistics support.
Persist the rolling window of data to save API calls after restarts and allow for a larger lookback window.