I want to know the max value of a sensor over the last 5 minutes.
and in my case the value can only be 0 or 1.
the statistics sensor is kind of usesless here because if
7 minutes ago the sensor changed to 1
and 2 minutes ago it changed to 0 it still says 0 because it only uses the changes not the starting value.
if there are no changes the sensor is unavailable.
Your history_stats config is just counting the number of times you have the number 1.
Your template is doing oddness.
If you want a sensor that has the max value at all times even when it’s not changing in your 5 minute window, then add a template sensor on top of it that checks if your stats sensor has a value, and if it doesn’t just output the statistic sensors source sensor.
{{ states('sensor.gas_was_consumed_statistics') if 'gas_was_consumed_statistics' | has_value else states('sensor.thermostat_opentherm_slave_fl') }}
the value was 1 at the beginning (5 minutes ago)
then it changes to 0
stats gives 0
my current value gives 0
so the result is 0
and I need it to be 1.
that’s why I tried using history_stats,
if stats =0, check what the value was exactly 5 minutes ago.
the goal here is to get a notification when the gas usage increases but nothing has used gas.
my gas meters updates every 5 minutes, therefor the delay.
and sensor.thermostat_opentherm_slave_fl updates every 10 seconds and indicates if my boiler/water heater is active.