Skip to content
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

reset_every filter does not consider start of [day|week|month] #290

Open
JvdMaat opened this issue Jun 6, 2023 · 3 comments
Open

reset_every filter does not consider start of [day|week|month] #290

JvdMaat opened this issue Jun 6, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@JvdMaat
Copy link

JvdMaat commented Jun 6, 2023

Describe the bug
When using a filter and using the reset_every setting, it resets everything based on current day

yaml

filters:
  - derivate
  - integrate:
      reset_every: 1M # 1 month (Should reset on 1st of month, but resets today instead)
@JvdMaat JvdMaat added the bug Something isn't working label Jun 6, 2023
@dbuezas
Copy link
Owner

dbuezas commented Jun 6, 2023

Uhm. This is a bit trickier that what I thought: the duration specified is internally converted to milliseconds. Later in the code, I don't really know if you wrote 1w or 7d or 168h.
This means that it is not quite clear where to reset. For example

  • every 30 days from the beginning of the year vs every 1st day of the month
  • every 7 days starting the beginning of the month vs the a Monday vs beginning of year
  • ...

I think the most intuitive behaviour is to use a specific parsing algorithm for this use case where the unit is kept, decimals are not allowed(i.e you can't do 1.5 weeks)

  • if the unit is years -> start on 1st of Jan
  • if months -> start on 1st of Jan and add calendar months
  • If weeks -> start on a Monday and add whole weeks
  • if days, hours, mins, secs, ms -> start at midnight

Do you see any corner case with this approach?

@JvdMaat
Copy link
Author

JvdMaat commented Jun 6, 2023

I would agree no decimals, if you reset every 1.5 days, what is your start day? Which days get cut in half? Too much ambiguity.

Every month resets on the 1st of each month (is that possible? I know in the yaml if you specify 1M, it really translates to 30 days, not exactly a month depending on which month we're in. If you start it on Jan 1st, it'll be off all year since Jan is 31 days. And after 12 months (365 days) you're off by 5 days.)

Every week restarts on each Monday in my world. But I know there are a lot of Sunday fanatics as well (I don't think HA has a "first day of week" setting. At least I couldn't find one just now. You may be able to pull that out of the OS? (Though not sure if that's exposed)). So the every week one could be an issue here and there depending on localization.

@dbuezas
Copy link
Owner

dbuezas commented Jun 7, 2023

HA does allow changing the first day of the week. To do it, click on your name on the left side bar. This card uses that to configure what "current_week" means :)

Resetting on the 1st is indeed possible, I'll need to "remember" the unit used and work with the actual calendar dates instead of bare milliseconds.

I think it will work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants