Ccu attributes to separate yaml file

Hi evereybody,

i had the following within my configuration.yaml to get attribute values of my homematic CCU.
this worked fine.

sensor:

#Aus Homematic Gas-Variable auslesen
  - platform: template
    sensors:
      gaszaehler_counter_in_m3:
        value_template: "{{ states.homematic.ccu2.attributes.Gaszaehler }}"
        unit_of_measurement: 'm³'
        device_class: 'gas'
        attribute_templates:
          state_class: 'total_increasing'
          
      gaszaehler_counter_in_kwh:
        value_template: "{{ states.homematic.ccu2.attributes.Gaszaehler_kwh }}"
        unit_of_measurement: 'kWh'
        device_class: 'energy'
        attribute_templates:
          state_class: 'total_increasing'

Now i would like to create separate yaml files for this. So i created two folder and included them in configuraiton.yaml like

homeassistant:
  allowlist_external_dirs:
    - /config/yaml_sensor
    - /config/yaml_template

sensor: !include_dir_list yaml_sensor
template: !include_dir_list yaml_template

A lot of sensors which i created within /yaml_senor are working. But not these two for CCU.
For example: This, which is within /yaml_sensor is not working

platform: homematic
gaszaehler_counter_in_kwh:
  - value_template: "{{ states.homematic.ccu2.attributes.Gaszaehler_kwh }}"
    unit_of_measurement: 'kWh'
    device_class: 'energy'
    attribute_templates:
    state_class: 'total_increasing'

Will be great if somebody can help me.
Many thanks in advance.
#ccu #homematic #yaml

If you switch to the new integration, you can enable those system-variables in the Home Assistant UI (they are sub-entities of the Hub-Device). Not sure about the state_class though. You may have to add that via customize.yaml in this case.

Hi Daniel,

thanks for your proposal. I have a physical CCU which i would like to use.

But i found the error. Did some mistakes in coding of the new two files.
one correct “external” yaml files is:

platform: template
sensors:
  gaszaehler_counter_in_kwh:
    value_template: "{{ states.homematic.ccu2.attributes.Gaszaehler_kwh }}"
    unit_of_measurement: 'kWh'
    device_class: 'energy'
    attribute_templates:
      state_class: 'total_increasing'

Solution:
a) platform has to be “template” not “homematic”
b) wrong minus before “value”
c) some typos regarding spaces.