Difficulty getting a minimum value for a sensor

I am having trouble calculating the minimum value of a recurring MQTT sensor. The sensor updates every 15 seconds, if the value changes. I want to calculate the minimum over a period - right now the period is short for debugging - ultimately it will be 48 hours. It appears the statistics integration is the proper way to calculate this, but I have not been able to get this to work.

The sensor is sensor.water_heater_return_temp. Here is the entry in my sensor.yaml file:

- platform: statistics
  entity_id: sensor.water_heater_return_temp
  name: Water heater return temp stats
  state_characteristic: value_min
  sampling_size: 24
    hours: 6

After reloading YAML I still have no sensor created? I seem to be missing something. I don’t get any errors - just no result.


Have you restarted or just reloaded the YAML configuration? If you haven’t restarted, do so…

Otherwise, if no entity is being created there is something wrong with your configuration. The sensor config you have shown looks like it could be fine, depending on how the file is being merged. Which method are you using to merge this file into configuration.yaml?

IIRC, Statistics entities states stay “unavailable” until the max_age is reached. Also, be careful setting sampling size so low… for an accurate value it will need to be at least as larger as the number of values posted in the time span of max_age.

Restarting HA was the answer - thanks! fwiw, a running minimum shouldn’t require a full sample - and it apparently doesn’t - I got the entry created and updating within a few minutes of restarting. If I read it correctly, the documentation states that the default sampling_size is 20 - it seems you would need to specify anything larger than that. If it would be ignored if max_age is specified, the documentation should specify that.