Weird long term statistics behaviour - some entities work some don't

In my setup I have a template convert the temperature statistics of my TRVs into a sensor entity. In total there are seven such sensors, all using the same yaml with only the uuid, name and source changed. Three of them have long term statistics, four of them not.

This confuses me.

Here is the yaml of a working sensor:

- sensor:
    # Küche Temperatur
    - name: "Temperatur Küche"
      unique_id: a5e6c639-64c9-4c75-af06-08288c89a85f
      state_class: measurement
      state: "{{ state_attr('climate.heizung_kuche','current_temperature') }}"
      device_class: temperature

Here is the yaml of a broken one:

- sensor:
    # Bad Temperatur
    - name: "Temperatur Bad"
      unique_id: 747e4b31-d5e4-470d-9131-63315834b888
      state_class: measurement
      state: "{{ state_attr('climate.heizung_bad','current_temperature') }}"
      device_class: temperature

Does anyone have an idea what could cause this?

Add a correct unit_of_measurement (see the device class docs) then restart. You may have to go to Developer Tools → Statistics and fix any issues for the sensors by clicking the Fix Issue buttons, if present.