Possible to use the week number of the year in a rule?

Is there any way to get the week number of the year into a rule/variable somehow?

See link for information if you don't know what a week number is:
Week Numbers for 2020 (epochconverter.com)

I have a rule that reminds me that I should take out the trash bins every other week that works well, but the problem is a year like this (2020) when the year has 53 weeks (usually 52).
My garbage pick-up is every even week (week 2, 4, 6 etc.), and then the rule will be screwed up this year.

Of course there is no major issue to adjust the rule manually and in worst case it is only once per year.
However, I'm curious if it is possible to get the week number into Hubitat somehow?

There are some variable math functions, but I don't think there are any epoch conversion functions.

Could you use a local variable to count weeks, and when you get to 52, reset the week counter to whatever works for your logic? (perhaps just a skip the reminder, add one to the counter and carry on)...it would be a bit more complicated than that to catch the edge conditions (like 2020), but it seems like it might be doable.

S

1 Like

Interesting idea I use outlook now but a Hubitat notification ( I use a RGBW bulb for my reminders) would be better.

Why does one even have to consider the date at all? Using a local variable might it be possible to have an even trigger on even weeks? If so, notifications would continue until the variable overflowed.

Here's a rule that does this:

This runs once a week, and flips a Boolean variable each week. Only every other week will it send the notification. You just have to start it so it works the first time, or change the initial value of the Boolean local variable for that same reason.

1 Like

Thanks for the tips.

I have something similar today that flips a Boolean variable every other week, but the problem are years like 2020 that has 53 weeks.
When week 53 ends in 2020 (actually 3:rd of January 2021), the weeks will start with 1 again for 2021 and the Boolean will indicate the wrong week as even (and the wrong week for garbage pick-up).

I was more thinking about if you maybe could import the current week number from somewhere to a variable or similar, and then include that variable into the rule?
Or if Hubitat had dates included in the software that also include the current (and accurate) week number?

1 Like

Curious, does this mean that at the beginning of a year with 53 weeks, you experience a pickup two weeks in a row? Or you have two weeks with no pickup?

Our recycle is picked up every other week. Makes no difference if it is leap year or on what date it might fall, its simply every other week.

I will be creating a rule for this myself, thanks to your idea and bravenel's suggestion it will be easy.

Yes, that is correct.
In my case I will have 3 weeks between pickups instead of 2 weeks for these particular weeks.

1 Like

I'm guessing you live in EU. We in the US haven't embraced weeks numbers (nor metric)!

I haven't gone throught the logic but I'm assuming starting each year you are either on the even or odd weeks, hence the shift in week numbers.

Could you, on January 1st of each year force your boolean to either even or odd, whichever applies?

John

Then have a rule that runs on January 1 that sets the Boolean to the right value for a new year.

For a year with 53 weeks, two weeks after 52 would be 1, but 1 is odd. Assuming we only want even numbered weeks, then the Boolean should be set to false on Jan 1, for the rule I posted above. The rule runs the first week, flips it to true, and exits the rule. So the first notice is the second week.

January 1 will not work since that could be in week 52, 53 or 1 depending on the year.

However, January 4 might work to use as a base for week 1 according the information in this link:
ISO week date - Wikipedia

It might cause problems sometimes though if you have pickups on odd weeks if the pickup is before January 4.

There is of course possible to use a formula to calculate this, but I don't know if it is possible to use/create formulas in the RM?

If you really really want to make this work every single year without any intervention, you will most likely need to create a small app to do this, this way you will be able to use Groovy math to get where you need to be.

Using that ISO week date info, I had managed to have this work in Excel but don't have access to that file anymore (old work place). So mathematically it is possible to do with easy maths (since I managed to do it in Excel).

Bonus, you will have learned basic Groovy app development and could release it to the community for others to use

If you don't mind using webCore the value can be returned using the expression:

``````formatDateTime(inputDate,"w")
``````

where inputDate is any valid dateTime value.

1 Like

I'm not sure that this is worth all the time for the small benefit of this

However, I wouldn't mind learning Groovy though, but I would probably need the basic code of something similar if I should get started with this.

Any recommendation of an existing code that I could start with?

Do you have these events in a Google calendar? There are community app(s) that can read calendar events, and could probably trigger off one of those. They aren't exactly easy to integrate with Google (Google's fault, not the app), but once you are up and running it seems to work OK.

I have Google calendar, but I did a rule like the following.
That will probably be "good enough" for me for the moment.

1 Like

Threw together a quick virtual device driver that will give you the week of the year as an attribute:

Virtual Calender Extension Example

1 Like

Yet another US vs. ROW difference.
You have defined Sunday as day 1 of the week
In Europe Monday is Day 1. (Which I think is also true for the UK)

Actually I just accepted the groovy default, but will admit that I didn't check to see if there was a way to localize the value.

Interesting, I was always under the impression it came from the Sabbath, but it seems to be limited to us old British Colonial rebels (Canada, USA & Australia).

But -- in my experience, Sunday is the first day of the week in the Middle east too (effectively), as Thursday is the last day of the work week, and Sunday the first...

Humans. Just strange.

S.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.