How can I get history from sensor templates

Hello All,

I hava four humidity sensors and want to create an additional one with the mean of all four. For this, I have created a template. I properly get the value, but cannot get the history. I have searched but cannot get a precise answer. What am I missing ?

  - platform: template
    name: "TCm Humidity"
    lambda: 'return ((id(B0H).state+id(B1H).state+id(B2H).state+id(B3H).state)/4.0);'
    update_interval: 5s
    id: BHm

All four Humidity sensors are created with the following code ( for sensor 0)

sensor:
  - platform: bme280
    i2c_id: multiplex0channel0
    address: 0x76
    humidity:
      name: "TC0 Humidity"
      accuracy_decimals: 2
      id: B0H
    update_interval: 5s

ESPHome 2023.12.5

I found the problem. The sensor needs additional information for the history to work. It not clear from the documentation.

I added

    unit_of_measurement: "%"
    device_class: "humidity"
    state_class: "measurement"

and it works. Did not try yet to see which is mandatory

where did you find that information? I don’t recall seeing it in the Docs, but it’s interesting and good to know.

I did not really see it in the doc.
It was some guess from the analysis of the output and small pieces of dissiminated information in various posts.

hhmm. Well, It’s good to know either way I suppose.