History_Stats assistance requested - state is a float value, not a text state

Attempting to use the History_Stats sensor to derive daily rainfall measurements. Currently, the rain guage just keeps incrementing any time rainfall occurs. As the measurement is in mm, it is a floating point value with one decimal place. My current sensor definition always returns “Unknown value” and I suspect it has to do with the state: definition. I verified this definition returns that float value, using Developer Tools / Template. I’ve also tried both type:time and type:count but neither succeeds.

I would appreciate any suggestions from you great and infinitely more experienced HA wizards. Thank you! :slight_smile:

sensor:
  - platform:  history_stats
    name:      'rain_mm_today'
    entity_id: 'sensor.cotech_367959_121_rain_mm_today'
    state:     '{{ states("sensor.Cotech-367959-121-rain_mm") | float(1) }}'
    type:      time
    start:     "{{ now().replace(hour=0, minute=0, second=0) }}"
    end:       "{{ now() }}"

The History Stats state option does not support templates.

Screenshot 2022-03-21 at 13-30-23 History Stats

The utility meter integration with a daily cycle would be a better fit for this application. Just feed it your always increasing rainfall sensor and it will keep track of daily rainfall.

Thank you, @tom_l!! :smiley:

I’ve updated configuration.yaml and restarted Home Assistant. Just have to wait until tomorrow to confirm the solution works as expected, then I’ll mark this ‘resolved’.