Highest temperature of the year

Hi All,

I am having a temperature sensor in HA. It looks like in history past 10 days i only get somehow mean values for the rest of the year. The same is if export the data to csv. How to get highest temperature recorded with the day and hour it happened from long term recorded stats? Is there a way to do that with template?

Does long term stats even keep high and lows?

You could create a trigger based template sensor that fires when the state of your temperature sensor changes, but only updates its own state if the trigger value is greater than the current state of the template. You could also then just use the last_updated attribute for when that happened.

Not sure if/how you would do it from long term stats.

I use SQL integration. This is my SQL for max for the year for a sensor.

SELECT statistics.start_ts AS start_ts, statistics.max as max_value FROM statistics WHERE metadata_id = ( SELECT id FROM statistics_meta WHERE statistic_id = "sensor.cwd_apptemp" ) AND max_value IS NOT NULL AND start_ts >= strftime('%s', 'now', 'start of year') ORDER BY max_value DESC LIMIT 1

Switch all max for a `min’ for a minimum.

Then from this sensor have a template entity for the time

{{ state_attr("sensor.cwd_apptemp_max_year", "start_ts") | timestamp_utc }}

Use both with a card like multiple-entity-row so you can display both together.

          - entity: sensor.cwd_apptemp
            name: Apparent Temperature
            type: custom:multiple-entity-row
            show_state: false
            entities:
              - entity: sensor.cwd_apptemp_max_year
                name: Max
              - entity: sensor.cwd_apptemp_max_year_timestamp
                name: Date
                format: date

There’s also the recorder.get_statistics action that you can use to pull hourly data withing a time range and then use templates to organise said data. Get Recorder statistics

What temperature sensor are you using?
I use Sonoff SNZB-02D and thermocouple readings from ESP32 via ESPHome.

All of these devices long term values are their actual readings. If I look in the History, nothing is averaged. One of the ESP32 sensors is on a 3min update rate. Every reading is saved.

Data older than 3 months is curtailed to 1 reading per hour for each device.

If the csv is downloaded, you could manually select max & min using excel.

In my configuration yaml, there is the line:
RECORDER FILTER
recorder:
purge_keep_days: 96

… which probably accounts for the 3 months factor.

I have an automation that stores the max temp for the day in an MQTT sensor. Any time the temp exceeds the value stored in that sensor, it updates with the new value. The timestamp gets saved too so I know when it was recorded. I do this for a range of all time high and all time low values for temp, barometric pressure, rainfall etc.

Should this not be highest temperature of the year so far?

Thanks everyone for the help. Recorder Stats are actually pretty convinient.

They really are. I also then use Macros for anything where I need the same logic for various similar entities and it really simplifies script/automation writing.