Hi,
I would like to use the statistics sensor to publish the min and max values of a temperature sensor on Lovelace.
I already researched a lot but still have no idea how realize.
Are there any examples?
Hi,
I would like to use the statistics sensor to publish the min and max values of a temperature sensor on Lovelace.
Are there any examples?
Make template sensors for the min and max attributes, put the template sensor entities in a card.
Or use this custom card if you don’t mind them looking like a list:
I have now tried tow variants:
- platform: template
sensors:
outside_max:
friendly_name: "OutsideMax"
unit_of_measurement: 'degrees'
value_template: "{{ statistics('sensor.temperature_outside_temperature', 'max') }}"
and
- platform: template
statistics:
outside_max:
friendly_name: "OutsideMax"
unit_of_measurement: 'degrees'
value_template: "{{ state_attr('sensor.temperature_outside_temperature', 'max') }}"
Both are not working. Sorry, I am very new in coding.
I just tried this out myself. Here is what I did:
I have a ZWave temperature sensor in the Kitchen w. entity-id:
sensor.kitchen_sensor_6_temperature_measurement
Here is my configuration for the statistics sensor and template sensor for min/max:
sensor:
#Play around with statistics sensor using kitchen temperature
#I have history and recorder components enabled for it to use.
- platform: statistics
entity_id: sensor.kitchen_sensor_6_temperature_measurement
name: Kitchen Temp Stats
sampling_size: 144 #default=20. Kitchen sensor updates 1/10mins.
#max_age:
#precision: 2 #default=2.
- platform: template
sensors:
kitchen_temp_max:
value_template: "{{ state_attr('sensor.kitchen_temp_stats_mean', 'max_value') }}"
kitchen_temp_min:
value_template: "{{ state_attr('sensor.kitchen_temp_stats_mean', 'min_value') }}"
Note that the statistics sensor friendly name Kitchen Temp Stats
is used to create a sensor with entity_id of sensor.kitchen_temp_stats_mean
The template sensors that get created have entity-ids:
sensor.kitchen_temp_min
sensor.kitchen_temp_max
both with state being the temperature XX.x
You will see this in Developer Tools->States.
UPDATE: THIS NO LONGER WORKS AS HA HAS SINCE CHANGED THE STATISTICS SENSOR.
Perfect! It works. Thank you very much! Would be lost without your help.
Sorry I thought the example given in the documentation on how to get a sensor attribute into the teplate sensor would be enough to help you (and I was rushed for time):
value_template: "{{ state_attr('sun.sun', 'elevation') }}"
Please use the button at the bottom of @wmaker’s post to mark the topic solved (it helps others searching for the same thing).
just tried this and im getting unknown as an output from the temp min and max sensors?
As it turns out, I haven’t used those in a long time myself, so I don’t know if they still work or not
_mean
was dropped from the sensor names.
how do i work out the sampling size for 24 hours if the sensor updates 1 time per hour if no change but immediately if there is a change?
Basically you take an educated guess. 24 + however many state changes you think are likely in 24 hours plus 10% more. Then keep an eye on the max age attribute of the sensor (developer tools / states) and make sure it does not drop below 24 hours. If it does, increase the sample size.
how should i use these sensors?
i created them in sensor.yaml but i have validation error
If you are refering to my PR its not been merged into home assistant yet (or maybe never as I unfortunatelly don’t have the time). You can install the integration instead as a custom component, this is the way I’m running it on my own environment. Just download the folder daily_min_max
from this github repo of mine and place it in your custom_components
folder. After doing so you can just follow the example configuration.
ok it works, now it still gives me the same values of min and max, but 24 hours have to pass I guess.
The minimum sensor had a time that I did not enter (07:15:00), what is it for? to reset the sensor at that time? what sense would it make? if I want the minimum value it must always be the minimum of 24 hours.
thanks for your help
if you refer to this example its just the time when to be reset. It will still be reset every 24h, just not att 00:00:00.
- platform: daily_min_max
name: Pan Daily Max
type: max
entity_ids:
- sensor.pan_temperature
- platform: daily_min_max
name: Outdoor Daily Max
type: max
entity_ids:
- sensor.outdoor_temp
- sensor.indoor_temp
time: "03:30:00"
Is this still working somehow? Even without mean in name, my statistic sensor does not have max_value or min_value attributes, to template the template sensors, but only the attributes listed in the docs: Statistics - Home Assistant
Or is it not possible anymore (because of another breaking change, which I wasn’t able to find) to have one mean sensor which contains the other functions as attributes (like it seemed before above) and I have to create several with value_max and value_min?
I haven’t used the statistics sensor since I tried it a couple of years ago. I agree, looking at the documentation that HA has changed the statistics sensor and that 2 year old post is no longer valid.
Thanks. I was only wondering, why I’m not able to find the attributes. So I did it now with e.g.
- platform: statistics
name: "Thermometer Aussen Min letzte 24 Stunden"
entity_id: sensor.thermometer_aussen_actual_temperature
state_characteristic: value_min
sampling_size: 1000
max_age:
hours: 24
But what I want to have, is, when the Minimum occurred. Is there any way to get this from statistics as well?
I tried to template it on my own, with
if states('sensor.thermometer_aussen_actual_temperature')|float(default=0) <= states('sensor.thermometer_aussen_min_letzte_24_stunden')|float(default=0)
But this has the gap, that it is only working when there is always another lower min inside the 24 window, what will never work. If the min is moving outside the window, it is not working anymore.
So, how to get the timestamp of the value_min. I don’t care if it is the last (preferred) or first or any, if there are more occurrences of the same value_min in the timewindow.