Read Sensor History to then activiate an Automation?

So… i have a hot water tank with immersion heater, and i monitor it’s temp via a probe which works great, i also have a Solar Divertor that heats the hot water when their is surplus solar energy. I have a trigger than boosts the hot water if in the morning it’s not up to temperature from the day before (if overcast etc). This all works fab, but i’m wondering how i can look back over say a week’s worth of temperature readings to ensure that at some point the hot water got above 60 degrees to ensure that if needed i can force a longer boost to help prevent legionare in the water, any ideas??? many thanks everyone.

just off the top of my head I would think create an input_boolean that gets turned on by an automation if the water temp is > 60 and then off < 60 (include hysteresis if necessary).

then use a history stats sensor that counts how many times the input_boolean was on in the last 7 days.

Fair although no need to involve an automation to set an input boolean, just use a threshold sensor. It even has a hysteresis option if you do need it. Then yea combine it with history stats to count whenever it was on in the past week.

@oxtobyd If you want a single sensor to trigger an automation from it is possible. Theoretically you could do it with a statistics sensor. Something like this:

sensor:
  - platform: statistics
    name: Max temp in past week
    state_characteristic: value_max
    entity_id: sensor.hot_water_temp
    sampling_size: 10000
    max_age:
      hours: 168

Then have an automation trigger any time states('sensor.max_temp_in_past_week') < 60.

Though I’m not really sure this sensor was designed for this type of use case. You’d have to make sure to set sampling_size to your estimate of the number of samples taken in a week. And even then I don’t know if it keeps samples over a restart of HA, probably not.

Alternatively you could definitely make sensor.max_temp_in_past_week as a SQL sensor but you’d have to be comfortable in SQL.

Or you could just use that instead.

:+1: