Creating a Smart Sleep Timer Slider for TV

Hey everyone, I’m trying to create a smart sleep timer for my TV using a slider in Lovelace. I have a script that works to turn off the TV after a delay, but I want to make it more user-friendly and improve the Wife Approval Factor (WAF). Here’s what I’ve done so far:

  1. Script Setup: I created a script called bedroom_tv_sleep_timer that takes a minutes input and turns off the TV after the specified time. The script uses a template to handle the delay and execution. It looks like this:

yaml
bedroom_tv_sleep_timer:
alias: Bedroom TV Sleep Timer
fields:
minutes:
name: Minutes
description: “The amount of time to wait before turning off the TV”
selector:
number:
min: 0
max: 60
step: 1
unit_of_measurement: minutes
mode: slider

If called again while still running, start over.

mode: restart
sequence:
- delay: “{{ minutes }}”
- service: media_player.turn_off
target:
entity_id: media_player.bedroom_android

  1. Lovelace Slider Integration: I want to use the Slider Entity Row to make the interface more interactive. I need to create a template entity to control the slider and pass the selected time to the script. However, I’m not sure how to structure the template correctly.

  2. Dynamic Updates: After setting the timer, I’d like the slider to reflect how much time is left. I found a community post that discusses dynamically updating timers, but I’m struggling to adapt it to my setup.

Questions:

  • How do I create the template entity for the slider? What should the template look like?
  • How can I pass the slider’s value to the script dynamically?
  • Is there a way to update the slider in real-time as the timer counts down?

I’d really appreciate any guidance or examples you can share. I’m excited to make this work and would love to hear how others have tackled similar projects!