Trigger automation every 36 hours

Hey Folks. I’m trying to automate my hydroponic pump to run every X hours. I was previously using date/time helpers to do it every day at such and such time, but that was overwatering things so I need to increase the interval past 24 hours.

The target right now is to turn the pump on every 36 hours but it’d be great it the interval was just considered a variable for some number of hours. My YAML with the date/time helper is below.

alias: Hydro pump on
description: >-

trigger:
  - platform: time
    at: input_datetime.pump_time_1
    alias: Time equal to Pump Time 1
    enabled: true
condition: []
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.hydro_pump
  - service: timer.start
    data: {}
    target:
      entity_id: timer.pump_timer
mode: single

Time pattern can’t do every 36 hours correct? I’m familiar with using that to run other automations. Thanks for the help.

You basically just need to take your existing automation and add a service call to set the next ‘on’ time.

alias: Hydro pump on
description: ""
trigger:
  - platform: time
    at: input_datetime.pump_time_1
    alias: Time equal to Pump Time 1
    enabled: true
condition: []
action:
  - service: input_datetime.set_datetime
    data:
      datetime: "{{ now() + timedelta(hours=36) }}"
    target:
      entity_id: input_datetime.pump_time_1
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.hydro_pump
  - service: timer.start
    data: {}
    target:
      entity_id: timer.pump_timer
mode: single

You can use an automation variable or an input number helper to define the interval.

  - variables:
      interval: 36
  - service: input_datetime.set_datetime
    data:
      datetime: "{{ now() + timedelta(hours= interval ) }}"
    target:
      entity_id: input_datetime.pump_time_1
  - service: input_datetime.set_datetime
    data:
      datetime: >
        {% set interval = states('input_number.pump_interval') | float(0) %}
        {{ now() + timedelta(hours= interval) }}
    target:
      entity_id: input_datetime.pump_time_1

@Didgeridrew This worked perfectly, thank you! Templates are a little intimidating for me still. Used the input number helper option so I can adjust the interval on the fly easier.

Hopefully, as the new Local Calendar integration has its feature built out, it will make it easier to do this kind automation without the need for templates.