Every Other Day Required Expression

I have two rules, one I'd like to run every other day, and the second to run on the days in between the first.

Currently I have a required expression of "new condition" with "Days of week" set to Monday, Wednesday, Friday, and Sunday, and the other rule having a required expression of "new condition" with "Days of week" set to Tuesday, Thursday, and Saturday. However, this causes one rule to run more than the other and also causes the same actions to run two days in a row.

Is there a way to make it the two rules actually run every other day? I was thinking maybe checking if the Julian Date modulo by two was even or odd, as that would only cause issues three times in four years (way better than once every week). I'm just not sure how to implement something like that or maybe use a better tool.

Use a Hub Variable, a Boolean. Use it for the Required Expression as true in one rule and false in the other. Each rule sets it to the opposite value when it runs. Use that instead of Days of the Week.

1 Like

Could also flip to using a schedule in the trigger depending on what the rule is actually doing.

Really? How??

Wrote this a year or so back

https://raw.githubusercontent.com/thebearmay/hubitat/main/evenDaySwitch.groovy

Among other things you can either use the attribute or have it flip a switch on even or odd days of the year and base automations based on whether the switch is on or off.

No?

That doesn't work the way you'd think it does. That does every other day starting on the first of the month. That generates the cron string 0 00 12 */2 * ? *

Interesting. I honestly used it for flowering my water bed and didn't pay that much attention. I presumed it just scheduled the next run for +48 hours.

Is the first of the month the case for any periodic schedule using n?

Periodic Schedules all generate cron strings, and cron is a peculiar thing. Check it out here:

You can exercise every element there. Generally, it starts over each minute, hour, day, month... depending on what you're using.

Thank you very much! I created my first variable (gave it an initial value of 1) and delved into that world.

The action run several times a day so I wasn't able to just have the rule set it to the new value. Instead I created a separate rule with an action that runs at midnight.

The action takes the current value and used variable math to %2, then I added 1. That gives me a resulting number of either 1 or 2 that I can check elsewhere.

If I wanted every third day instead of every second day I would just %3 to get resulting values of 1, 2, or 3. If I wanted every n day instead I would just %n to get resulting values of 1 ... n.

I wrote a tool that can help as well- you could possibly find it useful by selecting odd days or even days etc. etc.

1 Like

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