I have a bunch of scrape sensors to calculation an air pollution index from some station raw data (scaped once every 15 minutes) and a min/max sensor to pick the largest of these values, defined just beneath in config.yaml.
Whenever I restart HASS, the min-max sensor produces some junk data before it settles onto the correct value. I am guessing that it is evaluating the min/max while the sensors are scraping. This produces spikes in my history chart and makes it ugly (have a look at the screnshot: the line is the max of the five sensors below, none of which has the junky spikes)
Is there some to prevent this? Maybe forcing min/max to wait until the scrape has finished, or something haven’t thought about?
Same here, I’m facing the same annoying thing since a while but never raised the point. I have several temperature sensors and the min/max sensor starts calculating after a restart while all sensors are not all updated, which translates to spikes like yours.
I already did some researches and the simplest way I found would be to introduce an arbitrary delay parameter that the sensor would wait before calculating. Another more complex approach would be to wait for all the sensors to have a “valid” value, but how to define what is a valid value? Not unknown or not unavailable?
In any case, that would require adapting the code.
Nothing related but that could also be very interesting to define weights for each base sensor. Like in my case bedroom temp is more important than the basement one. Anyway that would be for another topic.
I can almost guarantee that the template sensors aren’t set up properly. The min max sensor ignores ‘unknown’ values, but not values that the sensors produce. The templates most likely produce 0 on startup instead of having an unknown state with the availability template. The min max does wait until it’s sensor has started, so I’d start looking at the sensor that produces the values.
Resurrecting this thread as it still seems to be happening today.
I have a min/max calculating the mean of 2 zigbee temperature sensors, and on a HA restart, the average always seems to jump up to match one of the sensors only:
It’s probably because one of the sensors becomes available with a valid value before the other. Your best bet would be to create a template sensor that averages the two sensors and has an availability template to prevent this glitch, e.g.
template:
- sensor:
- name: Average Temperature
device_class: temperature
state_class: measurement
unit_of_measurement: "°C" # or F
state: "{{ (states('sensor.temperature_one')|float + states('sensor.temperature_two')|float )/2 }}"
availability: "{{ has_value('sensor.temperature_one') and has_value('sensor.temperature_two') }}"
This sensor will only have a value if both source sensors have a valid numeric value. You will see gaps in your graph after restarts rather than spikes.