Daily min max temperature with time stamp

Hi there

I am currently testing some code to get a daily min and max values from a temperature
sensor. Together with the min max values, a time stamp should be generated as well e.q. when was the min max value generated.
Did not yet find a proper solution, but I am sure, I am not the first one with such a request.
Does anybody has some advise/code which is working for this?

Thank you!

Do you need this as a sensor or just for display purposes?

Mini-graph-card provides this functionality, but only for lovelace.

Have a look

temp

type: 'custom:mini-graph-card'
entities:
  - entity: sensor.home_temperature
show:
  extrema: true
  average: true
  graph: false
hour24: true
hours_to_show: 48

10 Likes

You could have a input_number and two automations.
One that at midnight sets the input_number.max to -99 or something, and another automation that triggers when the current temperature is higher than max, then it updated the max number.
Then you would need the same setup for min except the midnight reset has to set min to 99, but it can do both min and max in the same automation.
So three automations in total.

Thank you, I know about this function, but I need the values as sensors, so not just to display.

this should help

1 Like

Thank you for the hint about the statistics integration. I am aware of it, already running. But there are two major disadvantages (for my application)

  1. no time stamp on min/max value
  2. time intervall is moving, so when I want to have 24h within a fixed time, this could not be done

Maybe there is a work around on those two concerns? Thx

Have a look at this. It satisfies your mean/max and time frame needs.
Maybe not the timestamp part.

As for the timestamp part, with a bit of effort you can probably export the values and their timestamp directly from your database, using the sql sensor.

I’m looking for the same thing and am actually surprised this is not available. I might go about this with some appdaemon code.
Basically at midnight
Max = current value
Min = current value

On updates
If current < min then min = current

And the same for max of course.

I just did the same you requested.

sensor:
  - platform: min_max
    type: min
    entity_ids:
      - sensor.temperature_1
      - sensor.temperature_2

And the same again for max.

2 Likes

The max min integration does it not provide a moving min or max based on all provided entities?
I wrote my own daily max min custom component with daily reset. It does although not keep track of timestamps. GitHub - philsson/HomeAssistantCustomComponents

1 Like

Sorry I missed the “daily” thing.
Yes you are correct, min/max integration provides a moving value but for me this is sufficient.

That sounds awesome! But I could not install it in HA. Am I missing something?

btw: I found this here:

Isn’t this more or less the same?

1 Like

How did you install it? Did you copy the daily_min_max folder to the custom_components folder?

Interesting integration you linked to. It seems to do the same as mine but with some extra features as sum, average (mean), median, standard deviation and variation. On top of that they have the reset function which I actually just added to my component today. What mine has that this one does not is the ability to set another time other than midnight.

Ah, no. I tried to install it with HACS.

To set the reset time manually is quite a nice feature. So I will compare your integration with the one of @jeroenterheerdt :wink:

1 Like

happy to accept PRs :wink:

Hi there. I tested now your integration not for a while. I really like the possibility to have several functions in one integration. I am using Min, Max und Mean. In general the integration works great!

Suggestions and Questions:

  1. What type of Mean is it using? It would be nice if it would be possible to choose between mean, average_linear and average_step like in the statistics-platform: Statistics - Home Assistant

  2. It really would be great to have the option to reset everything at a certain time, not only at midnight. So I will try the integration @philsson for that function.

  3. Is there an option to change the entities values later (e.g. the refresh-interval)? If not, a feature to change it later would be really awesome. As I am playing around I always had to delete the old ones, and create new ones, only if I want to try which refresh-interval is the best for my sensor.

Hi. What type of trigger automation should that be when the temp is higher than min. Wait for input or other type of trigger. I’m new to HA so that iscwhy I’m asking.

Hi.
I manage to get the daily min temp sensor reset daily to -99. But I do not know how to check the current temp is higher than the daily sensor. Can you give me an example

You can use a template trigger.
Something like:

{{ states('sensor.temp') | int > states('input_number.max') | int }}

Thanks. Got it to work now. Have one more struggle and that is the strftime formatting is not working.
I use the following code for the time stamp of the temperatures.


service: input_datetime.set_datetime
target:
  entity_id: input_datetime.max_tuin_temp_tijd_weekly
data:
  datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"

It gives me the correct time stamp but the formatting is ignored. For instance %m should result in a month number and not text, right? But that is not working