Hi,
Background: I have an ultrasonic sensor coded with ESPHome and it provides a regular stream of distances which I convert to litres in our home’s water tanks. The sensor ‘sensor.use_today’ subtracts the current tank value from yesterday’s value (which is set as an input_number value at midnight). I have a statistics sensor that compares the last 7 input_number values and averages them - named sensor.seven_days_water_use.
Anyway, that is all working fine and as you can see from the history here. It’s not perfect due to the variation in values from the sensor but it’s close enough for my needs.
The problem with all this is my automation. We have just entered summer and we likely won’t get much rain so we need to be careful with our water usage in the next few months. I made an automation to notify me when our use_today is greater than our average seven_days_water_use. The template editor suggests that this template works, yet it’s triggering all the time. It usually triggers within a couple of minutes of midnight. When I made it and didn’t have it trigger once per day (by disabling the automation until midnight) it triggered every few minutes even though it was well under the average.
Automation:
id: '1670374497438'
alias: Water Use Warning
description: >-
If you've used more than the 7 day average and the date is less than 15th
April 2023 notify about water use. You'll need to update the epoch date for
2024 - 1713108690, 2025 - 1744644690, 2026 - 1776180690
trigger:
- platform: template
value_template: |
{{ states('sensor.use_today') > states('sensor.seven_days_water_use') }}
condition:
- condition: template
value_template: '{{((as_timestamp(states.sensor.date_empty.state)))|int < 1681485613}}'
- condition: template
value_template: ' {{ states.sensor.use_today.state > states.sensor.seven_days_water_use.state }}'
action:
- service: notify.notify
continue_on_error: true
data:
title: Water Alert
message: >-
Be careful with water use. {{ states('sensor.use_today') }} litres used
today. At this rate, we will run out of water by {{
states('sensor.date_empty') }}. It probably won't rain properly until
mid-April.
- service: automation.turn_off
data: {}
target:
entity_id: automation.water_use_warning
mode: single
Can anyone help?