Help with template sensors in configuration.yaml for tracking gas consumption

Hi, looking for some help with the way I’ve got my configuration.yaml… I think it’s a bit messy and casuing issues.

For context, I’ve got a ‘counter’ helper in HA that updates by an increment of 1 every time it receives a pulse from my gas meter. I’ve had to customise this a bit, to change it to divide that counter by 100 to get the actual m³ used. This template sensor achieves this just fine:

sensor:
  - platform: template
    sensors:
      gas_meter_counter_m3:
        value_template: "{{ ((states.counter.gas_meter_counter.state | float) / 100) }}"
        unit_of_measurement: "m³"
        device_class: "gas"

Now my issues arise when I want to get this added into the Energy dashboard. I understand that I also need to specify state_class: total_increasing in this code.

As soon as I try changing the above code to this:

sensor:
  - platform: template
    sensors:
      gas_meter_counter_m3:
        value_template: "{{ ((states.counter.gas_meter_counter.state | float) / 100) }}"
        unit_of_measurement: "m³"
        device_class: "gas"
        state_class: "total_increasing"

This sensor completely disappears, along with some other custom sensors that I’ve got set up. I’ve tried it with or without the quatation marks but this makes no difference.

The only other thing I can think of is that further down in my configuration.yaml file, I’ve got a template sensor (coded different - can’t tell you why, this was just a copy+paste from somewhere else on this forum to add a daily charge tracker for power consumtion)

This is how said template sensor is written further down:

template:
  #Add daily charge for power consumption
  - trigger: # rate-limit the template a bit, which would otherwise re-calculate every minute
      - platform: time_pattern
        hours: "1" # calculate hourly should be fine.
    sensor:
      # Increases every day by 1W to fake a daily supply charge in energy dashboard.
      - state: >-
          {{ 0.001 * (now() - "2023-01-31" | as_datetime | as_local).days }}
        unit_of_measurement: kWh
        state_class: total_increasing
        device_class: energy
        unique_id: power_daily_charge
        name: "Daily power charge"

To recap, how do I get the state_class: total_increasing code to work with my gas template sensor, without screwing up the rest of my sensors/templates?

Any help is much appreciated! If it also is useful, I can post my entire configuration.yaml