Help with device/state class?

Hi, unfortunately I can’t find good documentation on how I can provide my CO2, humidity and TVOC sensors with the correct measurement, so to speak. So that in HA I not only see the numbers but also what kind of number it is.

Can someone please help me with this?

I’ve already done some testing with device class and state class, but I can’t get it done yet. Which in any case doesn’t work:

  - sensor:
    - name: "humidity"
      state: '{{ states.sensor.air_sensors.attributes["humidity"] }}'
      device_class: humidity
      state_class: measurement
    - name: "TVOC"
      state: '{{ states.sensor.air_sensors.attributes["tvoc"] }}'
      device_class: volatile_organic_compounds
      state_class: measurement
    - name: "CO2"
      state: '{{ states.sensor.air_sensors.attributes["eco2"] }}'
      device_class: carbon_dioxide
      state_class: measurement

image

Template Sensor docs

o I thought HA already knew/filled this in when your device class was used. e.g. device_class: humidity you would think that HA would automatically apply %.
but apparently I have to configure it myself.

You happen to be using device classes that only have one unit supported, but a lot of them have multiple units so it wouldn’t have a way of deciding for you:

that makes sense. thanks