Need help creating an automation that runs every other day

Easy way to create an automation that runs every other day (if the days of the week is used for activation then each week results two days that run consecutively)

You did not specify rule, basic rule, etc. Using Rule machine, you could just use a virtual switch. (I would say use private boolean, but a virtual switch gives you the ability to manually toggle to change the rotation)

Trigger -> Time of day (or whatever you are using for trigger)

If switch is on then
do some actions
End if
Toggle virtual switch.

3 Likes

There are several ways to do this. Here's a method in Rule Machine that uses a Private Boolean:

It relies on requiring a PB to be true for the trigger to function. The first action sets the PB to be false, and the last action sets it to be true just before the next desired execution time.

1 Like

The Date & Time Parser driver can test whether a particular day of the year is even or odd.

1 Like

It will skip or repeat every year going from Dec 31 -> Jan 1 except on leap years where the last date would be an even Julian number. (365 is odd, 1 is odd). Not sure if that is a showstopper for OP. But, thought I would point it out.

If the regular year rollover having 2 days in a row of odd numbers is an issue, here is an RM rule that uses epoch time. It will always alternate days. Also, put in your time zone offset from UMT, since epoch time is based on UMT.

Also, variables

Probably easiest in Webcore.

image

4 Likes

Thanks for all of the replies!
aaiyar: some questions (have not used the private boolean before). First, how do you add the "ONLY IF" restriction to the trigger events for the PB? Also it sounds like this needs to be done in the rule machine app rather than in room lighting where I was doing it (which is fine with me). For more detail... I'm trying to have an automation that turns on roof heat tape from 8am-8pm every other day.
Thanks!

1 Like

Still easier to me in Webcore, but do it in Rule Machine with Booleans if you actually think that is easier for some reason. Webcore is a built-in app you can install in minutes.

image

2 Likes

Back in 2021 someone asked me a similar question - my answer:

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

Solves the EOY issue by reversing its on/off logic.

4 Likes

Thanks, I’ll check it out!

You would need to use a conditional trigger in rule machine.

This doesn't work?

image

3 Likes

@user897 - what @hubitrep has posted is the simplest solution. It makes use of the Periodic Trigger in RM.

2 Likes

That would have a 4 day cycle with 2 days on then 2 days off. It changes the virtual switch every other day.
The trigger by itself would do the trick....

agreed - the action was just whatever

1 Like

So, he wants it on at 8A and then off at 8P every other day. Toggle doesn't work in that situation. But it could if you made that an "on" switch, then added a wait for 8PM and then an "off" command.

The webcore version could work if they somehow tie the off 8PM into the "on" action to make sure the "every other day" stays in sync.

@aaiyar version also works with a wait for specific time: 8PM followed by an off.

The version I posted using virtual switches works also with the same wait for specific time inserted appropriately.

Gotta luv HE.... Soooooo many ways to get things accomplished.

The one thing I was doing different with my recommendation was to use the virtual switch so you could readily see if the automation was scheduled to run today or not without opening the rule/piston/etc.

2 Likes

For sure! Choice is a good thing!

2 Likes

True of coding in general. For this issue there are better methods already posted, but I still wanted to throw in another solution I have used over the years.

image

This is can be used in much more complex situations. Say there are several outcomes that might happen in each cycle. All they need to do is multiply the test variable by -1 and not have to worry about the current state. The individual branches wouldn't have to evaluate the variable before changing it. In many languages the 1 will evaluate as true and the -1 as false making it even simpler.

if (runAction) { ... }

I'm happy the OP was able to solve their issue. I always like to see different solutions to the same problem. Sometimes they spark an "Ahah!" moment with a future problem. :slight_smile:

2 Likes

Right. I was focused on the trigger, which seemed to be the initial concern.

That's an excellent point. Also, who is Cheryl and why do they need to get up only every other day? I'm surprised nobody asked.