Need Help With Manual Timer

I can start the timer and the pool pump, but the pool pump won’t turn off after it ends. I think the end of my script is wrong.

timer:
  pool_timer:

input_number:
  timer_seconds:
    name: Seconds
    initial: 0
    max: 60
    min: 0
    step: 1
  timer_minutes:
    name: Minutes
    initial: 0
    max: 60
    min: 0
    step: 1


script:
pool_pump_timer:
  sequence:
    - alias: Pool Pump On
      service: switch.turn_on
      data:
        entity_id: switch.02_nodemcu_3  
    - alias: Timer Start
      service: timer.start
      data_template:
        entity_id: timer.pool_timer
        duration: '00:{{ states.input_number.timer_minutes.state | int }}:{{ states.input_number.timer_seconds.state | int }}'      
    - alias: Pool Time Duration Minutes
      delay: input_number.timer_minutes
    - alias: Pool Time Duration Seconds
      delay: input_number.timer_seconds
    - alias: Pool Pump Off     
      service: switch.turn_off
      data:
        entity_id: switch.02_nodemcu_3   

automations:
- alias: 'Timer done'
  trigger:
    - platform: event
      event_type: timer.finished
      event_data: 
        entity_id: timer.pool_timer
  action:
    - service: notify.notify
      data:
        title: "Timer DONE"
        message: "THE TIME IS DONE!"

I’m not sure why your script uses a combination of delays and a timer when it can all be done with just the timer.


script:
  pool_pump_timer:
    sequence:
      - service: timer.start
        data_template:
          entity_id: timer.pool_timer
          duration: "{{'00:{:02d}:{:02d}'.format(states('input_number.timer_minutes')|int, states('input_number.timer_seconds')|int )}}"

automations:
- alias: 'pool timer started'
  trigger:
  - platform: event
    event_type: timer.started
    event_data:
      entity_id: timer.pool_timer
  action:
    - service: switch.turn_on
      entity_id: switch.02_nodemcu_3

- alias: 'pool timer finished'
  trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.pool_timer
  action:
    - service: switch.turn_off
      entity_id: switch.02_nodemcu_3
    - service: notify.notify
      data:
        title: "Timer DONE"
        message: "THE TIME IS DONE!"

Wow didnt think of it that way. Tha ks!!

worked great

Glad to hear you like it.

You may wish to consider marking the post as ‘solution’ so others can find it more easily.

You may have noticed I changed the template for duration. It ensures minutes and seconds are zero-padded so 2 minutes and 5 seconds is rendered like this 00:02:05 as opposed to this 00:2:5.

The duration option also accepts a value in seconds. So an alternative would be to convert the input_number’s minutes and seconds into total seconds.

If you wanted to get fancy, you could create automations to monitor the input_numbers for changes. If the timer is running and you change the value of minutes or seconds, it would stop the timer and restart it using the new value. Be forewarned this takes at least three more automations to achieve and may not be worth the effort if you don’t plan to adjust the timer’s duration while it’s running.

Great!! Thanks… how do i make it a solution?

Go to my post above, containing the example I supplied, and click the ‘Solution’ icon visible in the lower left. Example:

Screenshot%20from%202019-06-15%2016-07-50

Only the author (you) of a thread has the ability to mark a post in the thread as the ‘solution’. Once you do that, a link will automatically appear beneath your first thread post (that leads directly to the post containing the solution).