Run automation every two days

You need to use the condition: key with shorthand notation of template conditions within the action block. It looks like I left it out in my original response… I have fixed it there as well.

.....
    default:
      - condition: "{{ (now() - as_datetime(0)).days % 3 == 0 }}"
      - service: switch.turn_on
        target:
          entity_id: switch.maquina_espresso
mode: parallel

Thank you!

Hmm… No one realized a problem when months have 31 days?

“Every two days” or “every 48 hours” isn’t the same thing as “every DATE evenly divisible by 2”

The template works off days between two dates. Number of days in the month don’t impact it.

1 Like

Ok, I missed that it was subtracting the epoch, but the limitation that it only triggers on specific dates is still there.

Because it relies on a specific date (the epoch) to produce an offset, it can’t trigger on arbitrary dates, for instance 48 hours after initially being set up if it had been set up on an odd offset such as today (July 5 2023). It’ll trigger tomorrow and then 48 hours after that.

That’s an important limitation to be aware of, IMO.

… you can use any date as the start date. It doesn’t have to be epic, there are a few examples of this above.

Unix Epoch: 1970-01-01

Another way to express the same thing (where 0 represents the timestamp of the Unix Epoch):

as_datetime(0)

You can supply as_datetime() with a datetime string or timestamp value of your choice. Therefore, like petro explained, you can choose the starting date in order to adjust the offset.