Live Timer Display

What is the best way to display a live countdown timer? I have set up a timer process which runs fine, but I want to display the time left until it fires.

At the moment I am able to calculate the time left using a template sensor:

      {% if is_state( ("script.media_timer_off"),"on")  %}
      {{  (  as_timestamp(now()) -  as_timestamp(states.script.media_timer_off.attributes.last_triggered) )| timestamp_custom('%H:%M:%S', false)   }} 
      / {{ states.input_select.timer_select.state }}
      {% else %}"Timer Off"
      {% endif %}

Displaying: 00:15:00 for example. The problem is that the template sensor only gets updated when I start the timer and when it fires.

Am I on the right track or is there a better way to do it?

Ben

Hmmmm try adding the following to your template sensor: scan_interval: 10
That should refresh the sensor every 10 seconds.

Thanks for the suggestion but got this error:

17-02-01 02:28:41 ERROR (MainThread) [homeassistant.bootstrap] Invalid config for [sensor.template]: [scan_interval] is an invalid option for [sensor.template]. Check: sensor.template->sensors->timer_state->scan_interval. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.template/

Solved using this pattern:

sensor:
  - platform: time_date
    display_options:
      - 'time'

binary_sensor:
 - platform: template
   sensors:
      bedroom_movement:
        friendly_name: Bedroom Movement
        value_template: '{{(as_timestamp(now()) - as_timestamp(states.binary_sensor.bedroom_motion.last_changed) < 1800)}}'
        sensor_class: motion
        entity_id: sensor.time

My bad, I got confused with command_line sensors…

Your solution was going to be my next suggestion, but I was just looking for an example around here (as I’m sure I saw one once).

Anyway, glad you got it sorted :slight_smile:

Thanks for your help!

1 Like