Skip to content

Conversation

@alex-peck
Copy link
Contributor

I have the next rate structures for my TOU plan hardcoded into a Home Assistant template in a pretty ugly way. I want to be able to easily know the next rate structure (and when it will happen) so I can automatically perform operations like preconditioning the AC.

This PR performs a optimized calculation to determine when the next rate structure will be. A naive approach to this probably would loop through ever hour of every day for the next year. However, since rates can only change between hours and between weekdays / weekends, this can be heavily optimized to only check ~2 days per month.

The basic concept is, looping through each month:

  • check the rest of today (or the start of a new month)
  • check the next day if we are still in the same month and same type of day (weekday / weekend)
  • find when the next weekend / weekday starts and check that day

Python is not a language I really ever use so please let me know if I am breaking some unknown Python style or best practices 😄

Also, it would be nice to return both the structure int and time in the same call, but ha-openei expects any tuples returned to have the second value be the unit of measure. Let me know if you want to adjust this!

@alex-peck alex-peck changed the title feat:add ext rate structure (and time) property feat: add next rate structure (and time) property May 10, 2025
@firstof9
Copy link
Owner

Nice work. Thanks!

@firstof9
Copy link
Owner

Are you ready for this to be merged?

@alex-peck
Copy link
Contributor Author

Are you ready for this to be merged?

Yes this should be good to go. I've been running it on my own HA instance over the last week and all looks good.

@firstof9 firstof9 merged commit db9eca9 into firstof9:main May 19, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants