Timer with delay

I have an automation when triggered, turn on a switch and start the timer countdown. Once in a while I need to stop the automation but the “delay” keeps counting down until the time is up. How do I stop the automation with timer.cancel and cancel the “delay” part as well?

Here’s the automation:

  alias: Rodi Timer
  description: '' 
  trigger:
  - platform: state
    entity_id: switch.50207_3_socket_1
    to: 'on'
  condition:
  - condition: state
    entity_id: input_boolean.rodi_timer_enabled
    state: 'on'
  action:
  - service: timer.start
    data:
      entity_id: timer.rodi_water
      duration: "{{states('input_number.rodi_minutes')|int * 60}}"
  - delay:
      minutes: "{{ states('input_number.rodi_minutes') | int }}"
  - service: homeassistant.turn_off
    entity_id: switch.50207_3_socket_1

Unless the delay serves a different purpose than the timer, there is no reason to have both… and a timer is better. Use the completion of timer as a second trigger, then use a Choose action to specify which actions go with which trigger.

alias: Rodi Timer
description: '' 
trigger:
  - platform: state
    entity_id: switch.50207_3_socket_1
    to: 'on'
  - platform: event
    id: timer
    event_type: timer.finished
    event_data:
      entity_id: timer.rodi_water 
condition:
  - condition: state
    entity_id: input_boolean.rodi_timer_enabled
    state: 'on'
action:
  - choose:
      - conditions:
          - condition: trigger
            id: timer
        sequence:
            - service: homeassistant.turn_off
              entity_id: switch.50207_3_socket_1
    default:
      - service: timer.start
        data:
          entity_id: timer.rodi_water
          duration: "{{ states('input_number.rodi_minutes')|int(0) * 60 }}"
2 Likes

Drew, that works perfectly!! Thanks! Now trying to understand how the action works.

thanks! you helped me to understand how to use a timer with this example.