What am I missing here. Expect it’s something very obvious – any help would be gratefully received.
I appreciate I am recording the last 24 hours in the above code, ideally it would reset at midnight - but that might be a phase II project
You need to specify a sample_size. The default sample_size is twenty. Once twenty samples are recorded it starts to reuse the sample storage places so even if you specify 24 hours as max_age that sample was likely overwritten. So if a sample is taken every 15 minutes then for 24 hours you need 24*4=96 sample slots.
As you can see this can get kind of wasteful of memory especially if you only want to save the maximum value. A better solution would be to write a little automation that checks the max (input_number) versus the current temp and keeps the higher value on every temperature change plus just keeps the current value as maximum at midnight.
Hi and thanks for your reply, I have added the sample size but it still doesnt really work.
Using the below code including the sample size it isn’t pulling the highest value over the 24h period, which is closer to 15c opposed to the 8.45c reported. I suppose this might be because the sensor is providing a lot of readings and in this instant the last 96 may only go back a hour or so?
I understand your idea on the automation but not sure where to start, is there any reading you can recommend?
That’s, again because of your sample size.
The temperature seems to report much more often than every 15 minutes just by looking at the graph.
Calculate the sample size you need based on how often it reports.
I was just giving you an example. My weather station provides an update every 15 seconds. If the temperature changed every update then I would need at least 24604=5760 spaces for a 24 hour period.
I am having the same issue and want to try the automation route. I am still a little new to Home Assistant Can you provide some guidance on how to go about this?
Here is a triggered sensor that will keep the max value and reset at midnight. When first started the sensor will report ‘unknown’ until sensor.outside_temp changes for the first time.
template:
- trigger:
- platform: time_pattern
hours: 0
minutes: 0
id: 'midnight'
- platform: state
entity_id: sensor.outside_temp
id: 'change'
sensor:
- name: Max Temp
state: >
{% set outt = states('sensor.outside_temp')|float(None) %}
{% set maxt = states('sensor.max_temp')|float(None) %}
{% if outt != None and (trigger.id == 'midnight' or maxt == None
or outt > maxt) %} {{ outt }}
{% else %} {{ maxt }} {% endif %}
unit_of_measurement: F