Manual timer in frontend

Hey,

I would like to add a timer to my frontend, but it should be startable via an input boolean. So, when I switch the input boolean to active, the timer starts and I see the remaining time. When I turn it off, it will stop.
I will also send a notification to my phone when the timer ends (I already implemented notifications, should be no problem).

My wife would like to have some timers, for example to see when the washing machine is done. Therefore, I am going to define multiple timers (for all important programs of the machine).

I already found this solution: An example of a countdown timer, and some related questions But is there an easier way?

1 Like

You could get a little bit fancy and really impress the Mrs with dedicated washing machine sensor.

I did similar but used ESPeasy instead of the code provided.

That would be really nice but I think thats a project for the future with some time.

For now, a manual timer would be nice.

Sleep timer for my TV, i just wrote. Just started using Home Assistant. Any tips or improvement are welcome!

input_number:
  sleep:
    name: sleep
    initial: 45
    min: 15
    max: 120
    step: 15
    mode: slider

input_boolean:
  sleep:
    name: sleep
    initial: off

timer:
  sleep:
    name: sleep

automation:
  - alias: Timer start
    trigger:
      platform: state
      entity_id: input_boolean.sleep
      to: 'on'
    action:
      service: timer.start
      entity_id: timer.sleep
      data_template:
        duration: "{{ states('input_number.sleep') | int * 60 }}"

  - alias: Timer cancel
    trigger:
      platform: state
      entity_id: input_boolean.sleep
      to: 'off'
    action:
      service: timer.cancel
      entity_id: timer.sleep

  - alias: Timer stop
    trigger:
      platform: event
      event_type: timer.finished
      event_data:
        entity_id: timer.sleep
    action:
    - service: input_boolean.turn_off
      data:
        entity_id: input_boolean.sleep
    - service: remote.turn_off
      entity_id: remote.livingroom
15 Likes

Great, thank you.

Is there a way to see the remaining time in the fronted (as sensor or something else)?

You should be able to do this using a template sensor.

Using your timer in the template.

{{states.timer.your_timer.state}}

I already tried that but with no effct.

When I add the template sensor {{states.timer.mytimer.state}} I get only “Idle”.

I found a solution, just adding the entity to my lovelace ui:

  • type: entities
    title: Washing!
    show_header_toggle: false
    entities:
    • timer.washing

timer.washing displays the remaining time. No other code needed.

1 Like

Hello
can be used with any entity?
thanks

Hello everyone,

He added a configuration to my configuration.yaml and in entities he selected this, but he won’t get the counter operated, could he help me?

image

Hello, i try the same but don’t manage to get it work.

Automatisation:
  alias: Arrosage
  trigger:
  - entity_id: input_boolean.test
    platform: state
  condition: []
  action:
  - data:
    entity_id: timer.arrosage
    service: timer.start
      data_template:
        duration: '{{states.input_number.duree_arrosage | int }}'

Can anyone please help me?

You may have solved this by now but, you need to delete - data: from the action. You could use File editor to access the automations.yaml.

I search all the week, try everithing but not this :sob:, thanks men, you rock!!
The solution:

Automatisation:
  alias: Arrosage
  trigger:
  - entity_id: input_boolean.test
    platform: state
  condition: []
  action:
  - data_template:
           duration: '{{states.input_number.duree_arrosage | int }}'
    entity_id: timer.arrosage
    service: timer.start

I talk to early, it don’t take the duration of the input number.

I think it should be '{{states.input_number.duree_arrosage.state | int }}'

note the addition of .state

Thanks a lot. It work perfectly this time

Automatisation:
  alias: Arrosage
  trigger:
  - entity_id: input_boolean.test
    platform: state
  condition: []
  action:
  - data_template:
           duration: '{{states.input_number.duree_arrosage.state | int }}'
    entity_id: timer.arrosage
    service: timer.start

I try to improve it with input_datetime, but the timer get immediatly in idle position

  - data_template:
           duration: "{{states.input_datetime.arrosage_manuel.state | int| timestamp_custom('%HH:%MM', False) }}"

:disappointed_relieved:

Here’s a topic that could resolve your problem: -

It appears you just need to use {{states.input_datetime.arrosage_manuel.state}}.

just for my OCD (and YAML’s) you should work on a 2xspace principle as well, so

 - data_template:
           duration: "{{states.input_datetime.arrosage_manuel.state}}"

should be

 - data_template:
     duration: "{{states.input_datetime.arrosage_manuel.state}}"

An alternative solution is to use an input_datetime as your trigger i.e. set the time for when your timer should end.

  trigger:
  - platform: template
    value_template: '{{ states(''sensor.time'') == (state_attr(''input_datetime.arrosage_manuel'',
      ''timestamp'') | int | timestamp_custom(''%H:%M'', False)) }}'

Your input_boolean (or the state change of the input_datetime) could just turn the automation on. You could add an action at the end to turn the automation off again, so it doesn’t trigger daily.

This has the added bonus that a restart of Home Assistant won’t affect this working. If Home Assitant is just counting down a duration and Home Assistant restarts then the duration will be forgotten.

It work.
Thanks for your time.

Thanks! This works great!