Recurring Task Notification with datetime calculations (HVAC Filter Replacement Reminder)

In my automation for some reason it’s give me an error:

alias: "Notify: HVAC Filter"
description: ""
trigger:
  - platform: state
    entity_id: sensor.hvac_filter_days_left
    to: "0"
    id: Days Left HVAC
condition: []
action:
  - service: notify.mobile_app_sm_s918u
    data:
      message: Time to Replace an HVAC Filter
  - service: input_boolean.turn_off
    target:
      entity_id: input_boolean.hvac_filter_clean
    data: {}
mode: single
    - name: HVAC Filter Days Left
      unique_id: 1ef0d629-911a-4a18-96a1-f0503e77b119
      #friendly_name: 'HVAC Filter Days Left'
      state: >
        {% set hvac_filter_change_date = strptime(states('input_datetime.hvac_filter_date_last_changed'), '%Y-%m-%d %H:%M:%S') + timedelta(days=states('input_number.hvac_filter_days_until_old') | int) %}
        {{ (as_timestamp(hvac_filter_change_date) / 86400 - as_timestamp(now()) / 86400) | int  }}
      icon: mdi:clock-end
      unit_of_measurement: 'Days'

does this setup still work? I seem to be getting errors when setting up the sensors.

Still working for me. But I set this up a long time ago now and haven’t had a reason to redo it.

What errors are you getting?

NVM, I see what I’d did wrong. Didn’t add the helpers…

2024-07-02 22:39:00.130 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: ‘None’ has no attribute ‘attributes’ when rendering ‘{{ (( as_timestamp(now()) - (states.input_datetime.upstairs_kitchen_water_filter_date_last_changed.attributes.timestamp)) | int /60/1440) | round(0) }}’


  - platform: template
    sensors:
      upstairs_kitchen_water_filter_change_date:
        friendly_name: 'Upstairs Kitchen Water Filter Change Date'
        value_template: "{{ strptime(states('input_datetime.upstairs_kitchen_water_filter_date_last_changed'), '%Y-%m-%d %H:%M:%S') + timedelta(days=states('input_number.upstairs_kitchen_water_filter_days_until_old') | int) }}"
        icon_template: mdi:calendar-refresh-outline
      upstairs_kitchen_water_filter_days_left:
        friendly_name: 'Upstairs Kitchen Water Filter Days Left'
        value_template: >
          {% set upstairs_kitchen_water_filter_change_date = strptime(states('input_datetime.upstairs_kitchen_water_filter_date_last_changed'), '%Y-%m-%d %H:%M:%S') + timedelta(days=states('input_number.upstairs_kitchen_nater_filter_days_until_old') | int) %}
          {{ (as_timestamp(upstairs_kitchen_water_filter_change_date) / 86400 - as_timestamp(now()) / 86400) | int  }}
        icon_template: mdi:clock-end
        unit_of_measurement: 'Days'
      upstairs_kitchen_water_filter_age:
        friendly_name: 'Upstairs Kitchen Water Filter Age'
        value_template: "{{ (( as_timestamp(now()) - (states.input_datetime.upstairs_kitchen_water_filter_date_last_changed.attributes.timestamp)) | int /60/1440) | round(0) }}"
        icon_template: mdi:clock-start
        unit_of_measurement: 'Days'

I did a batch replace of HVAC to upstairs_kitchen_water

Fixed via changing helper entity to Date + Time
I am still getting some errors.

2024-07-03 09:43:54.243 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('ValueError: Template error: strptime got invalid input '2024-07-02' when rendering template '{{ strptime(states('input_datetime.upstairs_kitchen_water_filter_date_last_changed'), '%Y-%m-%d %H:%M:%S') + timedelta(days=states('input_number.upstairs_kitchen_water_filter_days_until_old') | int) }}' but no default was specified') while processing template 'Template<template=({{ strptime(states('input_datetime.upstairs_kitchen_water_filter_date_last_changed'), '%Y-%m-%d %H:%M:%S') + timedelta(days=states('input_number.upstairs_kitchen_water_filter_days_until_old') | int) }}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.upstairs_kitchen_water_filter_change_date'
2024-07-03 09:43:54.244 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template<template=({% set upstairs_kitchen_water_filter_change_date = strptime(states('input_datetime.upstairs_kitchen_water_filter_date_last_changed'), '%Y-%m-%d %H:%M:%S') + timedelta(days=states('input_number.upstairs_kitchen_water_filter_days_until_old') | int) %} {{ (as_timestamp(upstairs_kitchen_water_filter_change_date) / 86400 - as_timestamp(now()) / 86400) | int  }}) renders=2>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2100, in strptime
    return datetime.strptime(string, fmt)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/_strptime.py", line 554, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/_strptime.py", line 333, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data '2024-07-02' does not match format '%Y-%m-%d %H:%M:%S'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 603, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2616, in _render_with_context
    return template.render(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.12/site-packages/jinja2/sandbox.py", line 394, in call
    return __context.call(__obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2103, in strptime
    raise_no_default("strptime", string)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1853, in raise_no_default
    raise ValueError(
ValueError: Template error: strptime got invalid input '2024-07-02' when rendering template '{% set upstairs_kitchen_water_filter_change_date = strptime(states('input_datetime.upstairs_kitchen_water_filter_date_last_changed'), '%Y-%m-%d %H:%M:%S') + timedelta(days=states('input_number.upstairs_kitchen_water_filter_days_until_old') | int) %} {{ (as_timestamp(upstairs_kitchen_water_filter_change_date) / 86400 - as_timestamp(now()) / 86400) | int  }}' but no default was specified
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 715, in async_render_to_info
    render_info._result = self.async_render(  # noqa: SLF001
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 605, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: strptime got invalid input '2024-07-02' when rendering template '{% set upstairs_kitchen_water_filter_change_date = strptime(states('input_datetime.upstairs_kitchen_water_filter_date_last_changed'), '%Y-%m-%d %H:%M:%S') + timedelta(days=states('input_number.upstairs_kitchen_water_filter_days_until_old') | int) %} {{ (as_timestamp(upstairs_kitchen_water_filter_change_date) / 86400 - as_timestamp(now()) / 86400) | int  }}' but no default was specified
2024-07-03 09:43:54.246 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('ValueError: Template error: strptime got invalid input '2024-07-02' when rendering template '{% set upstairs_kitchen_water_filter_change_date = strptime(states('input_datetime.upstairs_kitchen_water_filter_date_last_changed'), '%Y-%m-%d %H:%M:%S') + timedelta(days=states('input_number.upstairs_kitchen_water_filter_days_until_old') | int) %} {{ (as_timestamp(upstairs_kitchen_water_filter_change_date) / 86400 - as_timestamp(now()) / 86400) | int  }}' but no default was specified') while processing template 'Template<template=({% set upstairs_kitchen_water_filter_change_date = strptime(states('input_datetime.upstairs_kitchen_water_filter_date_last_changed'), '%Y-%m-%d %H:%M:%S') + timedelta(days=states('input_number.upstairs_kitchen_water_filter_days_until_old') | int) %} {{ (as_timestamp(upstairs_kitchen_water_filter_change_date) / 86400 - as_timestamp(now()) / 86400) | int  }}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.upstairs_kitchen_water_filter_days_left'

You’re at least sharing the error, but you also need to share the latest template.