On_time configured for every third day

Good afternoon,

Trying to configure a device to trigger on_time every third day. Not finding anything via Google nor searching here. This is what I have in there now:

  on_time:
      # Every third day for Garden
      - seconds: 0
        minutes: 30
        hours: 7
        days_of_week: 1-7
        then:
          - switch.toggle: GardenValve2
          - delay: 30m
          - switch.toggle: GardenValve2

Is there something I can enter into days_of_week to get every third day?

Thanks in advance for your help!

I assume this is an automation, but I cannot see the on_time trigger here Automation Trigger - Home Assistant So where is that code?

Once again I missed the ESPHome tag, sorry.

It won’t be perfect but, day of month modulo 3.
At the end of month or start of month it will be off.
Another way would be day of year modulo 3.
But this will fail at new year instead.

Number of days since the epoch will work.

1 Like

can i have the full code?

Don’t have any way of testing it currently but it seems you need to use lambdas:

And if you use the timestamp as Nick suggests then divide it with 86400 and round to 0 decimals.
That will be the number of days since 1970.
So the above calculation % 3 == 0 should return true every three days.

You can use cron syntax

30 07 */3 * *

https://crontab.guru/#30_07_*/3_*_*

Thanks Mike - I have not gradiated to Lamda’s yet and think this will be the right fit for now.

time:
  - platform: homeassistant
    id: homeassistant_time
    # ...
    on_time:
      # Every morning for 30 seconds - Chickens
      - seconds: 0
        minutes: 30
        hours: 7
        days_of_week: 1-7
        then:
          - switch.toggle: chickenValve1
          - delay: 30s
          - switch.toggle: chickenValve1
  - platform: homeassistant
    id: garden_time
    # ...
    on_time:
      # Every third day for 15 minutes - Garden
      - cron: '30 07 /3 * * *'
        then:
          - switch.toggle: chickenValve2
          - delay: 15 minutes
          - switch.toggle: chickenValve2

** Edit … cron requires (6) spaced digits, not (5) - not sure what the sixth digit is as it is not shown in the crontab.guru page. Also, the */3 needed to be /3 to make the yaml like it.

Will test and see!
Thanks to all - Greatly appreciate your input and kindness!

In case it helps someone stumbling upon this, I used the following snipped you can adapt:

time:
  - platform: homeassistant
    id: local_time
    timezone: "Europe/Vienna"
    on_time:
      - seconds: 43
        minutes: 13
        hours: 8
        then:
          if:
            condition:
              lambda: "return ((id(local_time).now().timestamp / 86400) % id(interval_days)) == 0;"
            then:
              - switch.turn_on: water_valve

This was because I wanted the interval to be changeable in a home assistant dashboard.
Maybe it’s possible to create the cron syntax string dynamically in a lambda too, I haven’t checked.

For my specific case having it in the dashboard wasn’t really worth it. The interval is rarely changed, but easy to change by accident in the dashboard.