Adjustable countdown timer to switch off any entity for dashboard

Adjustable countdown timer with a dashboard card that will switch off an entity at a selected amount of time and show a by the minute count down of time left .
**You can also tell google assistant or alexa to turn on office timer for your Last preset time set.
by saying " ok google turn on office timer"
officetimer card

Step 1:
Create a INPUT NUMBER input_number.office and a TOGGLE input_boolean.office_timer
for timer with HELPERS or with yaml.
this will be the timer and switch to activate timer.
in the settings for input number you can set your MIN or Max time to what you want.

Step 2:
Countdown timer template in your template.yaml file
or in configuration.yaml under your template: lines in the proper yaml format and spacing.

change the names of your input number and in the two spots for your input boolean below…

- sensors:
       office_time_remaining:
        friendly_name: 'office Time Remaining'
        unit_of_measurement: "min"
        value_template: >
          {% if is_state('input_boolean.office_timer', 'on') %}
            {{ [ (states('input_number.office')|int - (as_timestamp(now()) - as_timestamp(states.input_boolean.office_timer.last_changed))/60)|round(0) ,0 ] | max }}
          {% else %}
            0
          {% endif %} 

Dont forget to reload Templates entities in the YAML configuration reloading in the YAML section of Developer tools after any changes to your template.

Step 3:

Automate using automation UI or with Yaml

alias: office timer
description: adjust office light lime
trigger:
  - platform: state
    entity_id:
      - sensor.office_time_remaining
    to: "0"
condition: []
action:
  - service: light.turn_off
    data: {}
    target:
      entity_id: light.office_light
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.office_timer
mode: restart

Step 4:
Create a Entities card with Dashboard UI or Yaml.
entities card

type: entities
entities:
  - entity: light.office_light
  - entity: input_number.office
  - entity: sensor.office_time_remaining
  - entity: input_boolean.office_timer

With this card you can Select the top Office light timer toggle to turn on/off the light and timer together.

Toggle Just the light on with the Office light Toggle

Or just use the Office timer start toggle to start/stop timer or stop timer if light is already on.

6 Likes

Can you pleas help me?
what am i doing wrong?

what is the issue?
could be your formatting

don’t know if you found the answer, but you are missing a closing } on your very last line

2 Likes

I created an account just to say thanks. This worked for me and with some playing around got it to work in my automated motion sensor lights where I can adjust from the UI now the length of time for the lights to remain on for

2 Likes

This is exactly what I have been looking for. Thanks for this!

Something I noticed is, if I switch off the toggle, it will trigger the automation and switch off the device.

To workaround this, this is what I modified in the Automation

  1. Additional trigger - When the toggle entity from ‘On’ to ‘Off’
  2. Add trigger IDs to both triggers
  3. Under Actions, have separate actions for the different triggers
alias: Switch off Aircon
description: Adjustable Countdown timer for Aircon
trigger:
  - platform: state
    entity_id:
      - sensor.ac_countdown
    to: "0"
    id: countdown
  - platform: state # catch manual toggle action
    entity_id:
      - input_boolean.aircon_timer_toggle_studyrm
    from: "on"
    to: "off"
    id: toggle
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - countdown
        sequence:
          - service: script.aircon_off
            data: {}
          - service: input_boolean.turn_off  # to reset toggle after countdown
            data: {}
            target:
              entity_id: input_boolean.aircon_timer_toggle
      - conditions: # do nothing when toggle is flipped manually
          - condition: trigger
            id:
              - toggle
        sequence:
          - stop: Aircon countdown timer cancelled.
mode: single

Not too sure if this is the best way but it works for me.

1 Like

I had previously tried to implement this using separate hour and minute sliders as the ‘TIME’ input without success. I have it working as you wrote it - not triggering anything but as a visible countdown timer.

Would you know how to enter separate hours and minutes to create the initial time to countdown?

Would an input_time entry work as opposed to an input_number?

This is nice. If only someone could make it a blueprint or something simpler