Automation for checking if run x days prior

I am trying to setup an automation that will send me a notification to take a reading of my energy meter with the following conditions:

  1. If it’s the first of the month and it hasn’t been done, send a notification reminder
  2. If I have done it within the last 3 days prior to first of the month, send a notification advising I’ve already done it.

I have setup a toggle helper for if the read has been done or not, as well as an input date helper (date only) to keep track of when the read was last done.
I’ve done a bit of searching but haven’t been able to get the check done around if it’s been done within the last 3 days.

This is the code I have so far:

alias: Energy Read Check
description: ""
trigger:
  - platform: time
    at: "10:10:00"
condition:
  - condition: template
    value_template: "{{ now().day == 1 }}"
    enabled: true
action:
  - if:
      - condition: state
        entity_id: input_boolean.energy_read
        state: "on"
      - condition: and
        conditions:
          - condition: template
            value_template: >-
              "{{ now() - input_datetime.energy_read_date <= timedelta(days=3) }}"
    then:
      - service: notify.all_mobile_devices
        metadata: {}
        data:
          message: Meter has been read for the month already.
          title: Meter already read.
          data:
            ttl: 0
            priority: high
    else:
      - service: input_boolean.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: input_boolean.energy_read
        enabled: true
      - repeat:
          count: 2
          sequence:
            - if:
                - condition: state
                  entity_id: input_boolean.energy_read
                  state: "off"
              then:
                - service: notify.all_mobile_devices
                  metadata: {}
                  data:
                    message: Need to send energy meter reading
                    title: Send meter read
                    data:
                      ttl: 0
                      priority: high
                - delay:
                    hours: 1
                    minutes: 0
                    seconds: 0
                    milliseconds: 0
        enabled: true
mode: single

In checking if the read has been done within the last 3 days of 1st of the month, I’ve tried the following with none working:
{{ now() - input_datetime.energy_read_date <= timedelta(days=3) }}
{{ now() - states(‘input_datetime.energy_read_date’) | as_datetime <= timedelta(days=3) }}
{{ now() - input_datetime.energy_read_date <= timedelta(days=3) }}

Hoping someone can assist with how to do this check.

Cheers.

Your datetime needs to be offset-aware:

{{ now() - states('input_datetime.energy_read_date') | as_datetime | as_local <= timedelta(days=3) }}

Thank you.
I also found I was probably making things complicated for myself and could also just use the last updated information for the input boolean instead.

Be aware, that last_updated and last_changed do not survive restart of HA or reload of the entity’s integration, so they may not be completely reliable for this use.

Ah okay, thanks for the heads up. Sounds as though my original plan is the way to go then.