lovelace-plotly-graph-card icon indicating copy to clipboard operation
lovelace-plotly-graph-card copied to clipboard

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

Open JvdMaat opened this issue 1 year ago • 3 comments

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 avatar Jun 06 '23 17:06 JvdMaat

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?

dbuezas avatar Jun 06 '23 20:06 dbuezas

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.

JvdMaat avatar Jun 06 '23 21:06 JvdMaat

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

dbuezas avatar Jun 07 '23 04:06 dbuezas