Trigger automation ‘X’ days after state change

I’d like to use an automation to remind me to do things like replace the furnace filter etc.

I would use an input boolean to tell home assistant that I changed the filter. If it’s been 3 months since the last state change of the input Boolean the automation will send out an iOS notify message. I’d like it to run every day until the input Boolean toggles.

Is there a trigger platform that could do this that survives reboots?

input_number and input_datedatime both survive a restart of HA and a reboot of the device IF it was shutdown properly, i.e. with a command like sudo reboot now.

In case of a power failure or a botched restart of HA the value might not be preserved.

I have a sprinkle timer that stores the datetime when it was last run and I had it show up empty a few times :cry:

This is not the kind o stuff HA is good at/made for. I think you would be way better off doing something like this in a calendar app as a recurring event (or at least store it in e.g. a google calendar and pull it into HA.

So I’ve made a little progress on this. I can across the RestAPI documentation and there is a way to query the state of a component which will also give you it’s last state change timestamp.

$ curl -X GET -H “x-ha-access: YOUR_PASSWORD” \
-H “Content-Type: application/json” \

I was able to test this running running the curl command on a secondary RPi and see the returned JSON.

I’m thinking I could do this in a python script that runs every day and can calculate the time delta…just gotta figure all that out.

I used to store the date/time when my sprinkler system ran last in a file by using this command in a sh-file (triggered once the automation was done):

#RUN AS /bin/bash /home/homeassistant/.homeassistant/bash_files/
# In bash
# Step 1 - - Save Info from HAss
curl -k -H POST > /home/homeassistant/.homeassistant/files/sprinkler_last_runtime.json

I then retrieved it via a template sensor:

- platform: template
      friendly_name: Sprinkler Last Runtime
      value_template: '{{ states.automation.sprinkler_last_runtime.attributes["last_triggered"] }}'

Not sure if these are exactly the commands that match because I since changed it to storing the last run time in a input_datetime variable beause it started surviving restarts and reboots.