Timer with Willow Voice / Named / Persistent

Love it. Spouse approval is so necessary!

Feel free to post your automation in here just in case anyone is looking for exactly that.

Im sure this could be cleaned up a bit but here’s my automation. It sends a notification to my wife and i as well as plays a sound over our kitchen speakers. This is for whole minute timers which is our only use case currently. Will start/stop/pause/restart a single timer.

alias: Auto Timer
description: ""
trigger:
  - platform: conversation
    command:
      - (cancel|stop|end|pause|restart) timer
      - (start|set) (a) timer (to|for) {timer_time} minute[s]
    id: command
  - platform: homeassistant
    event: start
    id: ha_restart
  - platform: event
    event_type: timer.cancelled
    id: cancelled
  - platform: event
    event_type: timer.finished
    id: finished
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - command
        sequence:
          - variables:
              command: "{{ trigger.sentence.split(' ')[0] | lower }}"
              tenbelow:
                ten: 10
                nine: 9
                eight: 8
                seven: 7
                six: 6
                five: 5
                four: 4
                three: 3
                two: 2
                one: 1
          - choose:
              - conditions:
                  - condition: template
                    value_template: "{{ command in ('start', 'set') }}"
                sequence:
                  - if:
                      - condition: template
                        value_template: >-
                          {{ trigger.slots.timer_time | trim | lower in tenbelow
                          }}
                    then:
                      - service: timer.start
                        data:
                          duration: "{{ tenbelow[trigger.slots.timer_time] * 60 }}"
                        target:
                          entity_id: timer.timer1
                    else:
                      - service: timer.start
                        data:
                          duration: "{{ trigger.slots.timer_time | int(0) * 60 }}"
                        target:
                          entity_id: timer.timer1
                  - service: tts.speak
                    metadata: {}
                    data:
                      cache: true
                      media_player_entity_id: media_player.the_kitchen
                      message: "{{trigger.slots.timer_time}} minute timer started."
                    target:
                      entity_id: tts.piper
              - conditions:
                  - condition: template
                    value_template: "{{ command in ('cancel', 'stop', 'end', 'pause', 'restart') }}"
                sequence:
                  - variables:
                      response_command: |-
                        {%- if command in ('cancel', 'stop', 'end') -%}
                          cancel
                        {%- elif command == 'pause' -%}
                          pause
                        {%- elif command == 'restart' -%}
                          start
                        {%- endif -%}
                      response_word: |-
                        {%- if command in ('cancel', 'stop', 'end') -%}
                          cancelled
                        {%- elif command == 'pause' -%}
                          paused
                        {%- elif command == 'restart' -%}
                          restarted
                        {%- endif -%}
                    enabled: true
                  - service: timer.{{ response_command }}
                    target:
                      entity_id: timer.timer1
                  - if:
                      - condition: template
                        value_template: "{{ command == 'cancel' }}"
                    then:
                      - service: timer.stop
                        target:
                          entity_id: timer.timer1
                  - service: tts.speak
                    metadata: {}
                    data:
                      cache: true
                      media_player_entity_id: media_player.the_kitchen
                      message: >-
                        Timer {{ response_word }}.
                    target:
                      entity_id: tts.piper
      - conditions:
          - condition: trigger
            id:
              - finished
        sequence:
          - service: media_player.play_media
            target:
              entity_id: media_player.the_kitchen
            data:
              media_content_id: media-source://media_source/local/timer.mp3
              media_content_type: audio/mpeg
            metadata:
              title: timer.mp3
              thumbnail: null
              media_class: music
              children_media_class: null
              navigateIds:
                - {}
                - media_content_type: app
                  media_content_id: media-source://media_source
          - delay:
              hours: 0
              minutes: 0
              seconds: 1
              milliseconds: 0
          - service: media_player.media_pause
            metadata: {}
            data: {}
            target:
              entity_id: media_player.the_kitchen
          - service: tts.speak
            metadata: {}
            data:
              cache: false
              media_player_entity_id: media_player.the_kitchen
              message: Timer Finished.
            target:
              entity_id: tts.piper
            enabled: true
          - service: tts.speak
            metadata: {}
            data:
              cache: false
              media_player_entity_id: media_player.master_bedroom
              message: Timer Finished.
            target:
              entity_id: tts.piper
            enabled: true
          - service: notify.parents
            data:
              message: Timer Finished
              title: Timer!
      - conditions:
          - condition: trigger
            id:
              - cancelled
        sequence:
          - delay:
              hours: 0
              minutes: 0
              seconds: 1
              milliseconds: 0
          - service: tts.speak
            metadata: {}
            data:
              cache: false
              media_player_entity_id: media_player.the_kitchen
              message: Timer Cancelled.
            target:
              entity_id: tts.piper
          - service: tts.speak
            metadata: {}
            data:
              cache: false
              media_player_entity_id: media_player.master_bedroom
              message: Timer Cancelled.
            target:
              entity_id: tts.piper
          - service: notify.parents
            data:
              message: Timer Cancelled
              title: Timer!
mode: single


1 Like

Thanks. I am sure it will help some folks down the road!

You certainly have some clever stuff in there :rofl: :rofl: :rofl:

Great job!

And just like that i screwed the automation up and cant figure out what the heck is going on. I’ll need to look at this when my kids arent being terrorists.

Something in here is wrong:

duration: >-
  {{ tenbelow[(trigger.slots.timer_time | trim |  lower)] |int * 60 }}

Added a default to int and then it just outputted “5,5,5,5,5…” 60 times. Somethings going on with the dictionary lookup. Should be an integer but it seems as though its still being converted to a string.

Take the quotes off of your setting of tenbelow. it is a string right now.

Nice catch. I ended up redoing it a bit and was able to just use one variable up a few levels. I’ll update the code here in a second after i do a few more tests.

Edit: Updated!

1 Like