Hello! I want to display 2 countdown timers on weekdays for 6:08am and 6:55am (when my kids need to leave for the bus). I’ve seen some blueprints and addons that work with a calendar, but nothing that will solve my use-case.
Something like this?
{% if now().weekday() <= 4 %}
{% if now() > today_at("06:55") %}
{{ ((today_at("06:55") + timedelta(days =1) - now())|string)[0:5] }}
{% else %}
{{ ((today_at("06:55") - now())|string)[0:5] }}
{% endif %}
{% else %}
{% endif %}
Should return as HH:MM.
This is great! Thank you! Now how would I display it? I’m hoping to get to something like this:
Where have you added the code?
I plan to add it to sensors.yaml, i’ve only tested in the template studio
Dashboard:
- type: entities
title: Countdown Timers
entities:
- entity: sensor.countdown_to_06_55_am
name: Countdown to 06:55 AM
- entity: sensor.countdown_to_06_08_am
name: Countdown to 06:08 AM
Config.yaml:
- sensor:
- name: "Countdown to 06:55 AM"
unique_id: countdown_0655
state: >
{% if now().weekday() <= 4 %}
{% if now() > today_at("06:55") %}
{{ ((today_at("06:55") + timedelta(days=1) - now()) | string)[0:5] }}
{% else %}
{{ ((today_at("06:55") - now()) | string)[0:5] }}
{% endif %}
{% else %}
Weekend
{% endif %}
icon: mdi:clock
device_class: timestamp
- name: "Countdown to 06:08 AM"
unique_id: countdown_0608
state: >
{% if now().weekday() <= 4 %}
{% if now() > today_at("06:08") %}
{{ ((today_at("06:08") + timedelta(days=1) - now()) | string)[0:5] }}
{% else %}
{{ ((today_at("06:08") - now()) | string)[0:5] }}
{% endif %}
{% else %}
Weekend
{% endif %}
icon: mdi:clock
device_class: timestamp