Countdown kitchen timer

Thanks for your help. For anyone else totally new like me, here is how I implemented it:

In configuration.yaml

timer:
  cooking_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

In my scripts.yaml

cooking:
  sequence:
    - service: timer.start
      data_template:
        entity_id: timer.cooking_timer
        duration: '00:{{ states.input_number.timer_minutes.state | int }}:{{ states.input_number.timer_seconds.state | int }}'

In automations.yaml

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

It looks like this in lovelace:

00

The notification is not idea as it just puts an orange marker on the notification icon in the top right, so I’ll need think of a better solution to that.

4 Likes

This meight be that your automation got a trigger, but no action and therefore throws an error.

want to get an phone call when the timer finishes? you can do that…

Whoops, I do have an action I just didn’t include it in the paste my mistake. Will edit my other post

action:
    - service: persistent_notification.create
      data:
        title: "Timer DONE"
        message: "THE TIME IS DONE!"

Hey:) does your timer sensor counts down in seconds? Would love to integrate that🤗

Hi yes it does, you can visually see it count down the seconds. The text is the size that you can see in the screenshot so it’s not massive, but I’m sure you could find some custom card to display it larger!

my solution for the timer notification is a conditional card - perhaps that is something you hadn’t in mind… if you thought about that just ignore my post=)

>           - type: conditional
>             conditions:
>               - entity: input_boolean.timer
>                 state: "on"
>             card:
>               type: "custom:button-card"
>               entity: input_number.timer
>               show_state: true
>               color_type: card
>               color_off: rgb(218, 108, 108)
>               action: more-info
>               style:
>                 - font-size: 24px
>                 - font-weight: bold
1 Like

Hey out there, im still fiddling with this timer and countdown sensor solution - till now, i integrated your solution and got a sensor running with the value of the timer. i doesn’t get values out of states.timer.timer.attributes.remaining / states.timer.timer.state and also not trough state_attr('timer.timer', 'remaining') - my solution is dirty as hell but works sometimes, i really would appreciate help, think there must be a way with templating this with input_number1 > 1 and input_number2 > 1 – but i not good enough at this. back to the following, the fiddling part cames in with the integration of hours…

my files:

input_number.yaml:

timer_minutes2:
  name: Minuten
  initial: 0
  max: 60
  min: 0
  step: 1
timer_seconds2:
  name: Sekunden
  initial: 0
  max: 60
  min: 0
  step: 1
timer_hours2:
  name: Stunden
  initial: 0
  max: 24
  min: 0
  step: 1

configuration.yaml:

timer:
  timer2:

input_boolean.yaml:

timer2:
  initial: off
  name: Timer 2

automation.yaml:

##########################
#### Timer Automation 2####
##########################
  - alias: 'Timer done 2'
    trigger:
      - platform: event
        event_type: timer.finished
        event_data:
          entity_id: timer.timer2
    action:
      - service: homeassistant.turn_off
        entity_id: input_boolean.timer2
      - service: WHATYOUNEED
        entity_id: SAME
  - id: 'Timer 2'
    alias: 'Timer 2'
    hide_entity: False
    trigger:
      platform: state
      entity_id: input_boolean.timer2
      to: 'on'
    action:
      - service: timer.start
        data_template:
          entity_id: timer.timer2
          duration: '{{ (states.input_number.timer_hours2.state | int) }}:{{ states.input_number.timer_minutes2.state | int }}:{{ states.input_number.timer_seconds2.state | int }}'



### Timer Off 2#
  - id: 'Timer Off 2'
    alias: Timer Off 2
    trigger:
      platform: state
      entity_id: input_boolean.timer2
      to: "off"
    action:
      - service: timer.cancel
        entity_id: timer.timer2

  -------> if your planing to use with alarm system
########################################################################
########################################################################
######################### Counter for Timer 2 ###########################
########################################################################
########################################################################
  - id: 'Counter 21'
    alias: counter 21
    trigger:
      platform: time_pattern
      seconds: '/1'
    condition:
      condition: state
      entity_id: 'input_boolean.timer2'
      state: 'on'
    action:
      - service: input_number.decrement
        data:
          entity_id: input_number.timer_seconds2

  - id: 'Counter 22'
    alias: Counter 22
    trigger:
      platform: state
      entity_id: input_number.timer_seconds2
      to: "0.0"
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: 'input_boolean.timer2'
          state: 'on'
        - condition: or
          conditions:
            - condition: numeric_state
              entity_id: input_number.timer_minutes2
              above: "0.0"
            - condition: numeric_state
              entity_id: input_number.timer_hours2
              above: "0.0"
    action:
      - service: input_number.decrement
        data:
          entity_id: input_number.timer_minutes2
      - service: input_number.set_value
        data:
          entity_id: input_number.timer_seconds2
          value: 59.0

  - id: 'Counter 23'
    alias: Counter 23
    trigger:
      platform: state
      entity_id: input_number.timer_minutes2
      to: "0.0"
    condition:
      - condition: state
        entity_id: 'input_boolean.timer2'
        state: 'on'
      - condition: numeric_state
        entity_id: 'input_number.timer_hours2'
        above: '0.0'
    action:
      - service: input_number.decrement
        data:
          entity_id: input_number.timer_hours2
      - service: input_number.set_value
        data:
          entity_id: input_number.timer_minutes2
          value: 59.0
  - id: 'Counter 23'
    alias: Counter 23
    trigger:
      platform: state
      entity_id: input_number.timer_hours2
      to: "0.0"
    condition:
      - condition: state
        entity_id: 'input_boolean.timer2'
        state: 'on'
    action:
      - service: input_number.set_value
        data:
          entity_id: input_number.timer_minutes2
          value: 59.0
  - id: 'Counter 24'
    alias: Counter 24
    trigger:
      platform: state
      entity_id: input_boolean.timer2
      to: "on"
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: 'input_number.timer_seconds2'
          state: '0.0'
        - condition: numeric_state
          entity_id: input_number.timer_minutes2
          above: "0.0"
    action:
      - service: input_number.decrement
        data:
          entity_id: input_number.timer_minutes2
      - service: input_number.set_value
        data:
          entity_id: input_number.timer_seconds2
          value: 59.0
  - id: 'Counter 25'
    alias: Counter 25
    trigger:
      platform: state
      entity_id: input_boolean.timer2
      to: "on"
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: 'input_number.timer_minutes2'
          state: '0.0'
        - condition: numeric_state
          entity_id: input_number.timer_hours2
          above: "0.0"
    action:
      - service: input_number.decrement
        data:
          entity_id: input_number.timer_hours2
      - service: input_number.set_value
        data:
          entity_id: input_number.timer_minutes2
          value: 59.0
      - service: input_number.set_value
        data:
          entity_id: input_number.timer_seconds2
          value: 59.0

ui-lovelace.yaml:

  - type: vertical-stack
    cards:
      - type: markdown
        content: >
          ## Timer 2
      - type: entities
        entities:
          - input_boolean.timer2
          - input_number.timer_hours2
          - input_number.timer_minutes2
          - input_number.timer_seconds2
          - timer.timer2
          - sensor.timer2

sensor.yaml:

  - platform: template
    sensors:
      timer2:
        value_template: "{{ states.input_number.timer_hours2.state | round}}:{{ states.input_number.timer_minutes2.state | round}}:{{ states.input_number.timer_seconds2.state | round}}"
        friendly_name: 'Timer 2'

as mentioned its not really finished but the work in progress with the call for help =)=)

@lukenn, any way you can post the lovelace config for your timer? Thanks!

  # Kitchen timer
  - type: entities
    title: Timer
    show_header_toggle: false
    entities:
      - entity: input_number.timer_minutes
      - entity: input_number.timer_seconds
      - type: "custom:button-entity-row"
        buttons:
          - entity: script.timer_start
            icon: mdi:timer
            name: Start
          - entity: script.timer_cancel
            icon: mdi:timer-off
            name: Stop
      - entity: timer.cooking_timer
        name: Timer
        icon: none

In script.yaml:

##########################
#    COOKING TIMER
##########################

timer_start:
  sequence:
    - service: timer.start
      data_template:
        entity_id: timer.cooking_timer
        duration: '00:{{ states.input_number.timer_minutes.state | int }}:{{ states.input_number.timer_seconds.state | int }}'

timer_cancel:
  sequence:
    - service: timer.cancel
      data:
        entity_id: timer.cooking_timer
2 Likes

Is it posible to make this cooking timer without the sliders?
I want it to count down from 1h, 20min?
The programe we use most on our washing machine takes 1h, 18min.
And I want the countdown time to show in Lovelace.
Counter starts when I close the door on the washing machine (got a door sensor on it).

That wouldn’t be too hard.

Create an automation with your sensor as the trigger, and the action should activate the timer_start script.

Copy the ‘timer_start’ script I posted above but in the duration you can simply set your 1hr 20mins instead of using the templates from the sliders

1 Like

Hi there, in addition I’ve made myself a countdown card based on this code.
It is conditional, so it will only show when the timer is active. Also, when you click it, the timer is cancelled. But before that, a confirmation message pops up.
It is based on the custom-button-card.

See my code attached:

type: conditional
conditions:

  • entity: timer.cooking_timer
    state: active
    card:
    type: ‘custom:button-card’
    entity: timer.cooking_timer
    show_state: true
    show_label: false
    show_icon: false
    aspect_ratio: 2/1
    name: Timer
    styles:
    card:
    • font-size: 70px
    • font-weight: bold
    • padding: 1%
    • color: grey
    • align-self: middle
      name:
    • font-size: 40px
    • color: grey
    • align-self: center
    • text-transform: capitalize
    • text-shadow: 0px 0px 0px black
      tap_action:
      action: call-service
      service: timer.cancel
      service_data:
      entity_id: timer.cooking_timer
      confirmation:
      text: ‘[[[ return Are you sure you want to cancel the timer? ]]]’

5 Likes

I try to use a condition in a script to check is the timer-countoun below than 2 minutes. I tried it with something like that:

      - condition: template
        value_template: '{{ states.timer.gardenlight.attributes.duration | int < 00:02:00 }}'

But it doesn’t work. @petro do you know a solution? Thanks a lot

Have you read the documentation? Take a look here:

There you’ll find the following:

Avoid using states.sensor.temperature.state , instead use states('sensor.temperature') . It is strongly advised to use the states() , is_state() , state_attr() and is_state_attr() as much as possible, to avoid errors and error message when the entity isn’t ready yet (e.g., during Home Assistant startup).

The next point would be “Time”, there you’ll find, what you’re looking for. :slight_smile:
You need to find out, what type duration is. Normally you would want to typecast this value to an integer or int. Than add 120 seconds.

{{ (states_attr("timer.gardenlight", "duration") | int) < 120 }} 

Not tested! :slight_smile:

Thanks fir the hint @paddy0174 :+1:
The main problem are still there. I don’t know the type of the duration attribute. In the devlopment-tool shows the state as 00:05:00. (static, even if the timer is running)

Meaning, the code I posted, doesn’t work? :slight_smile: Or do you just want an explanation? :slight_smile:
In the snippet I posted, the duration will be type casted to INT or Integer or at least should get type casted… :smiley: :smiley: :smiley:

sorry, my answer was a little short. Yes, I took over your code. The template logic is now correct. Unfortunately, the condition still does not change after 2 minutes. I think it’s because of the ‘120’. But I have no idea how to solve this (I’m not a programmer and not familiar with int.). :see_no_evil:
If you have the solution as code, that would be perfect.:clap:

I found the problem. The countdown is not an attribute. Just the start (and remaining) time. But both are not change, if you start the countdown. So isn’t possible to make a condition: https://github.com/home-assistant/core/issues/30062

This is what I made for my Xiaomi Smart fan 1C. Thanks for the inspiration :slight_smile:

Would you please let me know what am I doing wrong on this automation? The problem is on the trigger/condition. Thanks in advance.

- id: 'Start Cooking Timer When Temp Reached'
  alias: 'Start Cooking Timer When Temp Reached'
  trigger:
    platform: numeric_state
    entity_id: sensor.temperature
   condition:
    condition: template
    value_template: "{{ (states('sensor.temperature') | int) >= (states('input_number.cooking_temperature') | int) }}" 

  action: 
    - service: timer.start
      data_template:
        entity_id: timer.cooking_timer
        duration: "00:{{ states('input_number.cooking_time') | int }}:00"