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:
- If it’s the first of the month and it hasn’t been done, send a notification reminder
- 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.