Automation - reset timer when valve status changed

Hi, trying to reset the timer countdown when valve status changed to off but it’s not working.

timer:
  vtime2:
    duration: "00:00:00"
  
  
automation test:
  - alias: Turn off the timer
    trigger:
      - platform: state
        entity_id: switch.valve_2
        to: 'off'
    action:
      - service: timer.cancel
        data:
          entity_id: timer.vtime2

Any help would be appreciated!

What does “reset the countdown” mean here? Like you want it to go back to it’s initial duration and start counting again? You want it to return to it’s initial duration and stay there?

Also what starts this timer? It obviously doesn’t have a duration of 00:00:00 when it’s actually running so something must be starting it with a duration. Are you hoping the timer will return to 00:00:00 or to the duration you started it with?

Hi, “reset the countdown” mean to initial duration and stop the counting.

“initial duration” here meaning 00:00:00? I think perhaps this is the confusion then, from doc on timer.start:

If a new duration is provided, this will be the new default for the timer until Home Assistant is restarted (which loads your default values).

I assume you provided a duration when you called timer.start since a 00:00:00 timer isn’t useful. So when you do timer.cancel it will return to that duration you specified, not to 00:00:00. It remembers the last provided duration until the next restart. Or until timer.reload is called which reloads and resets all timers.