How to configure a reusable card for different "days until X date"?

Hey all, new to HA. I tried looking through forums and docs first but nothing I can find specifically addresses my desired outcome. Thank you for reading!

I want to have a dashboard devoted to multiple time-based reminders of when various things around the house need to be tuned-up/replaced (ex. HVAC Filter, Water Heater Tune-up, etc). I want each card on the dashboard to be a gauge (for color-coding/visualization) counting down to a specific date (6 months from now for the HVAC Filter, 3 months from now for the nursery air filter, etc). When I click on a gauge, I want a prompt (or something) to essentially ask me whether I have just replaced the filter, and if I confirm, it runs a script or something to update the countdown with a new date 6 months in the future.

I feel like every post I find addresses one aspect of what I want to do, but I can’t figure out how to marry everything together to achieve my desired outcome. Timers and countdowns are a non-starter because they reset when HA reboots. Is there a way to run a script that calculates a date 6 months in the future like:

{{ (as_timestamp(now()) + (180 * 24 * 3600)) | timestamp_custom(ā€œ%m-%d-%Yā€, True) }}

but then automatically stores that date somewhere a countdown can count down towards?

Thank you in advance!

Create an input_datetime hepler to store the date the thing should happen. Call it ā€œfilter_change_dateā€ or something else (but you will have to change the template below).

Then create this template sensor:

configuration.yaml

template:
  - sensor:
      - name: Days to filter change
        unique_id: days_filter_change
        device_class: duration
        state_class: measurement
        unit_of_measurement: d
        state: "{{ (states('input_datetime.filter_change_date')|as_datetime|as_local - now()).days }}"

You can then use sensor.days_to_filter_change in your gauge or to trigger reminder notification automations.

That part works great now, thank you!!

Now my issue is trying to figure out why I can’t get the hold interaction on the gauge I made to run an action to set the helper’s date as a function of 180 days from now (see pic). Any thoughts?

Most core cards do not support templates. Call a script as the action and use the template to set the date in the script.

…could I bother you for a how-to on that? I’ve been trying for the last hour and I guess there must just be too many gaps in my knowledge.

I’m getting syntax errors all over whenever trying to run a script that updates the input_datetime.hvac_filter_change_date to:

{{ (as_timestamp(now()) + (180 * 24 * 3600)) | timestamp_custom(ā€˜%m-%d-%Y’, True) }}

Testing that code in the template editor successfully returns the value 01-06-2026, but I can’t figure out how to make a script actually input that into the helper. Thanks again for helping, much appreciated.

Try:

  - action: input_datetime.set_datetime
    target:
      entity_id: input_datetime.hvac_filter_change_date
    data:
      date: "{{ ( now() + timedelta(days=180) ).strftime('%Y-%m-%d') }}"

Actually try that in the card action first just to make sure. I’m almost certain the action does not support templates, but it might. If not then put it in a script.

1 Like

That worked in the script but not in the card. Thank you so much for your help!

1 Like

Thanks for confirming that the template is not supported in the card actions.