Create Recurring Tasks in Home Assistant

by Danny
0 comment

READING TIME: 9 MINUTES

In this guide, I’ll show you how to create recurring tasks in Home Assistant. For example, if you are looking to keep track of things such as:

  • HVAC filter reminders
  • Salt reminders for water softener
  • Pill Reminder
  • Oil Changes
  • Yearly reminders such as cleaning the gutters, vehicle inspection/renewals
  • Dental/Doctor visit reminders

…then this is the guide for you.

And once the task is created, I’ll show you how to create sensors that displays “Days Until A Task is Due” or “Days Since a task has been completed”

For this tutorial, I am creating a 90-day water filter replacement recurring task. No additional addons or integrations are needed for this, just some good ol’ template sensors and helpers.

The exact same procedure can be used for any recurring task, just be sure to change the entity names and dates.

Let’s get started!


Similar Guides

I have a number of other really useful guides regarding tasks/chores, so I’m linking those below for you.

  • Follow my Chore Tracker in Home Assistant guide if you want to create a point-based rewards system when your child completes a chore or task.
  • Follow my “Days Until” guide if you’re interested in creating a countdown Lovelace card (for anniversaries, holidays, etc)
  • Follow my Home Assistant Birthday Reminder Card guide if you’d like to keep track of your family’s birthdays and display them on a Lovelace card.
  • Follow my Garbage Reminder card tutorial to be reminded of trash & recycling day.

How It Works

As you can see in the screenshot below, the “number of days until something is due” can be changed from Lovelace, as well as the “last replaced date”.

For example, if you change your HVAC air filter every 90 days, change the Water Filter Threshold to 90. If you take medicine once a week, set it to 7.

Once the task is complete, just click the Tap To Complete Task button to reset the date to today.


Step 1: Create 2 Helpers

The first thing we need to do is create 2 Helpers: 1 Number helper, and 1 Date and/or Time helper.

  1. The “number helper” will be used to set the number of days until something should be completed/is due.
  2. The “datetime helper’ will be used to set the last completed date.

Helpers can be founds in the Configuration > Automations & Scenes > Helpers tab. Click Add Helpers.


Helper #1: Toggle

Add Helper > Number.

  • Name: Water Filter Threshold
  • Icon: mdi:water-circle
  • Step size: 1

Then click Create.


Helper #2: Datetime helper

Add helper > Date and/or time.

  • Name: Water Filter Last Replaced
  • Choose “Date” radial

Then click Create.

After creating those two helpers, search the Helpers tab for water to find your entity ID names. If you followed my naming convention, then yours will be the exact same as mine below. If not, document yours, you’ll need to copy and paste these into the next step.

  • input_datetime.water_filter_last_replaced
  • input_number.water_filter_threshold

Add Sensors to Configuration.yaml

Next, we need to create a few template sensors by adding the below code to your configuration.yaml file.

These sensors will let you add a “Days Since Water Filter Was Replaced” or “Days Until Water Filter Needs Replacing” sensor to a Lovelace card.

File Editor > Configuration.yaml.

If you don’t have a sensors: block added to your config file yet, then paste this code:

sensor:
  - platform: template
    sensors:
      water_filter_days_remaining:
        friendly_name: 'Water Filter Days remaining'
        value_template: >
          {{  states('input_number.water_filter_threshold') | int - (now() - 
          states( 'input_datetime.water_filter_last_replaced') 
          | as_datetime | as_local ).days }} 
        icon_template: mdi:clock-end
        unit_of_measurement: 'Days'
  - platform: template
    sensors:
      water_filter_days_since_replacement:
        friendly_name: 'Water Filter Days Since Replaced'
        value_template: >
          {{ ((as_timestamp(now()) - state_attr('input_datetime.water_filter_last_replaced','timestamp')) | int / 86400)  | round(0) -1 }}
        icon_template: mdi:clock-end
        unit_of_measurement: 'Days'

If you do have a sensors: section, then just paste this onto a new line below the last entry.

  - platform: template
    sensors:
      water_filter_days_remaining:
        friendly_name: 'Water Filter Days remaining'
        value_template: >
          {{  states('input_number.water_filter_threshold') | int - (now() - 
          states( 'input_datetime.water_filter_last_replaced') 
          | as_datetime | as_local ).days }} 
        icon_template: mdi:clock-end
        unit_of_measurement: 'Days'
  - platform: template
    sensors:
      water_filter_days_since_replacement:
        friendly_name: 'Water Filter Days Since Replaced'
        value_template: >
          {{ ((as_timestamp(now()) - state_attr('input_datetime.water_filter_last_replaced','timestamp')) | int / 86400)  | round(0) -1 }}
        icon_template: mdi:clock-end
        unit_of_measurement: 'Days'

If you used custom entity names, make sure to swap yours in.


Reload Template Entities (or reboot HA)

Next, we need to make these template sensors active. You can either restart Home Assistant (Configuration > Settings > Check Configuration > Restart) or reload the Template Entities section (Configuration > Settings > Template Entities):


Add Entities to Entities Card

On any of your Lovelace dashboards, click Add Card. Choose Entities card.

Add all of the newly created entities (tip: just search water). There should be 4 of them.

As you can see in the screenshot below, the current date is 4/11/2022. I’ve set the “water filter last replaced” date to 4/1/2022, which was 10 days ago. The Days Since Replaced sensor accurately shows 10.

For the threshold, I set it to 10 days (reminder: water_filter_threshold is the # of days until something is due) Since it was 10 days since I last replaced it, the days remaining is now 0, which means it needs to be replaced today.


Create Script to Reset “Last Replaced” Date to Today

The next step is to create a simple script that resets the date to today. (You could of course just manually set it from the datetime helper, too).

A script is just an automation without a trigger, which makes them great for task-tracking.

I prefer to use a script for this because I have Ikea smart buttons placed near the areas HVAC unit when I replace the air filter, and another near the kitchen sink when I replace the sink filter. I can just click the button once the recurring task is complete. Or, you can call a script from an automation or by adding it to Google Assistant for voice control.

Configuration > Automations & Scenes > Scripts tab.

Click Add Script.

Click the 3 dots in the top-right corner to edit in YAML. Then paste this in.

alias: Reset Water Filter Date to Today
sequence:
  - service: input_datetime.set_datetime
    data_template:
      date: '{{ now().strftime(''%Y-%m-%d'') }}'
    target:
      entity_id: input_datetime.water_filter_last_replaced
mode: single

Before you run the script, set the date back a few days using the Datetime helper.

Then save and test the script by clicking the RUN SCRIPT button. If it works from here, the next step is to create a Lovelace button that calls this script to run.

Your new script entity is this: script.reset_water_filter_date_to_today


Create Button to Run Script

On a Lovelace dashboard, click Add Card > Button.

For the Entity, search for your script entity and leave the tap action to Toggle.

Now once your recurring task is complete, you can just tap that button!

And once you’ve done customizing, here’s what it’ll end up looking like.


Wrapping Up

Now that you’ve got everything working comes the fun part: customizing a new tasks reminder dashboard. You could also create a Google Home routine to verbally mark the task as complete (which is as simple as exposing the script entity to Google Assistant and creating a simple routine – follow the “Setup Roborock with Google Assistant” section of my guide here)

I recently moved all of my views and dashboards to Mushroom Card, so if you were looking to create a dashboard like what mine looks like, I have a Home Assistant Mushroom Card guide as well.

I’m still tweaking my new Tasks view and adding chores, so I’ll probably update some screenshots and YAML once I do.

If you followed this guide to create your own recurring chore reminder cards, I’d love to see how you laid your tasks out in Lovelace, so please share!


My Favorite Home Assistant Devices

Below are some of the Home Assistant-compatible devices I personally use in my home. I highly recommend each of them.

The full list of all Home Assistant compatible & recommended devices I use can be found on my Equipment List page.

Smart Home Product Finder

What hub do you currently use?


SmartThings

Home Assistant

Hubitat

Step 1 of 3

What product are you looking to add?


Lights

Locks

Thermostats

Cameras

Garage Door Opener

Switches

Sensors

Motion, Door & Window, Leak

Smart Plugs

Buttons

Step 2 of 3

What protocol?


Z-Wave

Zigbee

Wifi

Step 3 of 3

Retake quiz? Click here!

0 comment

You may also like

Leave a Comment