Query timer time in automation

Hi all. I’m using a timer to turn off the TV after 1 hour has passed (only before 18:00) so that my kid is not watching TV all day… My automation already works fine…

I’m now trying to write another automation that gives a warning 1 minute before the TV is switched off but I’m struggling with the correct templating for the automation trigger condition - the code below does NOT trigger at any time (the action part works well in other automations, it’s only the correct trigger I’m after).

Does anyone have any ideas?

The timer is called timer.tvwatch

alias: Announcement TV Timer nur mehr 1 min
description: ''
  - platform: template
    value_template: "{{ states('timer.tvwatch') == '00:01:00'}}"
condition: null
  - data:
      entity_id: all
    service: sonos.snapshot
  - service: media_player.volume_set
      volume_level: 0.27
      device_id: 1d1dcad03428d796f08ded67d4f5fe47
  - service: tts.google_translate_say
      entity_id: media_player.sonos
      message: >-
        Der Fernseher war jetzt schon sehr lange eingeschaltet. In 1 Minute wird
        automatisch ausgeschaltet.
  - wait_template: ''
    timeout: '00:00:10'
    continue_on_timeout: true
  - data:
      entity_id: media_player.sonos
    service: sonos.restore
mode: single

It doesn’t trigger because a timer’s state value doesn’t contain a countdown (i.e. it doesn’t show the remaining time). It shows its status (idle, active, paused).

You will have to create a Template Trigger that uses the timer’s finshes_at attribute to determine when the timer will end. Be advised that the finshes_at attribute only exists when the timer is active.

Or, at the cost of a second timer that runs 1 min shorter, duplicate your existing first automation and change the action accordingly to give the warning.

I’m also wondering: Do you want to restrict it to 1 hour’s watching time, at a time, on a day, or overall watching time? If the former, what would prevent your kid to not simply turn it on again? If the latter, you could save on timers in all cases and use a history stats sensor and trigger on its numerical value.