What is the best option for saving a rolling 24 hour temperature?

which values?

For example what the temperature was 19:30 or 19:00

it’s pointless. this graph is based on the past data from HA db. you need to extract it if you need it - this integration might help.

I don’t think that statistics integration can help you - as far as I understand, you need to have access to hourly values in the last 24 hours. The trouble with statistics is it does not expose the array of values held as an attribute.

If you want to use only standard HA integrations (no custom components), one of the options is to create an automation that is triggered by your temperature sensor’s state change and adds the value to an input_text. When adding, you need to make sure there is no more than 24 readings altogether. And you will need to provide access method to the data to output a required reading to the display.
The problem here is the limit on state’s length - 255 chars. If we presume the reading may be positive or negative and has no more that 3 significant digits in total, it’s 6 chars/reading (including a separator).
So we can safely pack 42 readings in one input_text, which means update interval cannot be 30 mins, for example, it should be higher. Or you need to use several input_texts, which is more complicated I presume.

Another option is to create 24x(number of readings per hour) input_numbers and on arrival of a new reading shift all the existing data one step down… but I don’t want to implement it, sorry :wink:

I have read other post saying that it’s hard to get values from database since you don’t have the timestamp.
You need the timestamp to get the correct value, but you only know a rough number of what timestamp you want.

Yesterday as I laid in bed I had an idea.
What if I build all the logic in PHP on a webpage and use the scraper integration to pull down the values?
I think I have a quite clear puicture of it, but my plan is to not only show the temperatures but also put a “warning” with blue LEDs if the temperature is below freezing in either now temperature or five hours ago.
I want this display on my front door to show if there is a risk of ice on the windows of my car. The reason I want a temperature of five hours ago is because the temperature can be just above freezing when I get out of bed, but there might still be ice on the windows.

Now the blue LEDs should light up when either of the two vlaues are below zero. Is there any automation template that can see if there is a certain character in a string -?
Because I think I would rather have PHP build the complete string ex: -5.5° 1.7° so that I have it all in one entity that I can easily pass to my display.

Did you look to the api ? Especially GET /api/history/period/

Another option could be to dump your temperatures to influx, and use an influx sensor like

`select min(tmp) as value from "%" where "entity_id" = ''outside'' and time > now() - 6h and time < now() - 5h`

Won’t give you the exact temperature 5 hours ago, but a close approximation.

have you searched the forum?
something like this might do…

I tried to start up the API by adding api in config but it doesn’t do anything.
Maybe I did something wrong.

I’m not too worried if it’s 5, 5.5, 6 or even 4 hours ago. It’s mainly a relative temperature that helps to know if it’s ice or not on the windows of my car and what kind of road conditions I can expect.

I will have a look at influx. Thanks for the advice!

That would probably work!
Not the way I would do it but I come from a programming background so I don’t think in yaml or entities yet.
Thank you for the find!

you’re welcome.
yaml and entities are just tools/paradigms so you should be fine with your background (same here btw)

Since you only care about the min temp within the last 5 hours why not just use similar code to what you have but reduce the sample age, then use the min_value that is produced for whatever automation / notification you want

  - platform: statistics
    entity_id: sensor.dummy
    sampling_size: 3600
    max_age:
      hours: 5

create your trigger with something like trigger.below and

value_template: "{{ state_attr('sensor.dummy', 'min_value') }}"

I don’t have a great deal of template experience so haven’t quite put that together for you…

It’s not actually the min value I’m looking for.
But sure it could work.

The problem is that it does not display in a constant way.
Let’s say the temperature array looks like this:
[-4, -4.2, -5, -5.1, -6]
This means that -6 is the temperature now.
But if I get the min value from this it will also be -6.
That makes me believe the temperature was constant during the night but in reality it has been dropping lower.

Not a big issue. Totally doable and will work fine.
I’m not sure I want the min value though.

I will play with some php tomorrow and use an API to get the temperature.
The scraper sensor worked fine when I made a small test yesterday.

I’ll report back tomorrow on how it goes.

Why do you think so? Yes, the values look like a sorted set… so no, -6 is not necessary the temperature now, it’s most likely min.

exactly, initially you wanted

and as I previously said, imho statistic sensor won’t help you.

In a similar situation I ended up copying a standard integration (trend sensor) and tweaking it so I could get a value when the change started (as I need it) and I’m still happily using this custom component.

At least in all programming languages I have ever used, the last value is always the most to the right/down.

Anyways, I started up my php page and have it adding new values to the array/json each time it’s called (I add date time as key to make it easier to debug).

Just now it looks like this:

{ "2020-04-06 13:13":"14.3~", "2020-04-06 13:43":"14.8~", "2020-04-06 16:13":"15.3~", "2020-04-06 16:43":"15.6~", "2020-04-06 17:13":"15.9~", "2020-04-06 17:43":"15.8~", "2020-04-06 18:13":"15.9~", "2020-04-06 18:43":"15.3~", "2020-04-06 19:13":"14.8~", "2020-04-06 19:43":"13.7~"}

I had a downtime that is why there is a gap.
The return value to the web scraper is (with the above in mind).
14.3~ 13.7~

~ means degrees in the Max7219 display.
It all seems to work fine as far as I can see.

you could use the custom variable components (there’s two available - I use the one by rogro82).

using rogro82’s I can create attributes that I can populate using an automation

then you can run that automation every so often (say once an hour or so) to take the temperature measurement and add it to your variable list of attributes. Basically it become a FIFO register that contains the last X readings.

if that seems like what you want I can post examples of how i use it now in a couple of places.

I got it working with the php program I made.
It works the same as you describe but on the web, then Home Assistant gets two values when it scrapes the webpage.

1 Like