mrvautin

Home assistant - Create date countdown template sensor

Words: 233 - (2 min read)

Home assistant - Create date countdown template sensor

Imagine you have a big event coming up, a holiday or a graduation - Quickly and easily setup a sensor to track the big day.

Jump into your configuration.yaml file in your config/ directory either via the file system or via the VSCode extension in Home assistant.

You are going to want to add a sensor for each event. Below we've setup two events - A birthday and a Marathon. You simply need to adjust the dates below to your desired date and update the name and ID for your sensor.

template:
  - sensor:
      - name: "My Birthday"
        friendly_name: "my_birthday"
        unit_of_measurement: "days"
        icon: mdi:calendar
        state: >
          {{ (strptime('02/03/2025', '%d/%m/%Y', today_at()) | as_local - today_at()).days }}
  - sensor:
      - name: "My Marathon"
        unique_id: "marathon"
        unit_of_measurement: "days"
        icon: mdi:calendar
        state: >
          {{ (strptime('04/08/2025', '%d/%m/%Y', today_at()) | as_local - today_at()).days }}

After you've updated your configuration.yaml file, save it and restart Home Assistant to see the new sensors named my_birthday and one called marathon or whatever you changed them to.

You can then head to your dashboard and add a new Entities Card. Pop the names of the entities you created above to display on your dashboard.

Related posts