Gas consumption in energy panel not working

Hi all !

I had successfully plugged a zigbee button to my gas counter following this guide :

So i have a input_number increasing each 10L and a sensor that divide this value by 1000 to convert in m³ for the volume.

Here is my configuration :

  • The input_number :
gas_counter:
  min: 0
  max: 100000000000
  name: gas_counter
  icon: "mdi:gas-station"
  mode: box

For information only, the input_number is updated with nod red to avoir false counter when HA restart :


.
.

  • The sensor :
- platform: template
  sensors:
    gas_volume:
      friendly_name: "Gaz Volume"
      unit_of_measurement: 'm³'
      value_template: "{{ states('input_number.gas_counter') | int / 1000 | round(3) }}"
      device_class: gas
      # state_class: total

→ sensor is working BUT the state class is not ( HA refuse to restart, unsupported state )
.
.
.

  • Finally the utility meter :
# gazpar
utility_meter:
  daily_gas_volume:
    source: sensor.gas_volume
    cycle: daily
  weekly_gas_volume:
    source: sensor.gas_volume
    cycle: weekly
  monthly_gas_volume:
    source: sensor.gas_volume
    cycle: monthly
  yearly_gas_volume:
    source: sensor.gas_volume
    cycle: yearly

.
.

The result :


.
.

In energy tab :

Don’t know WHERE and WHAT is sensor.gas_consumption_index_kwh cause i can’t found it anywhere in all my config file ( HA created this one automatically ? no existing in dev tools too btw )

→ Problem none of my sensor is accepted in energy panel. And why the state classe is unsupported ?
Any help would be gratefully appreciated ! Thk !

no one :frowning: ?

Shouldn’t your state class be ‘total_increasing’?

Sadly, i can’t :

The system cannot restart because the configuration is not valid: Invalid config for [sensor.template]: [state_class] is an invalid option for [sensor.template]. Check: sensor.template->sensors->gas_volume->state_class. (See ?, line ?).

- platform: template
  sensors:
    gas_volume:
      friendly_name: "Gaz Volume"
      unit_of_measurement: 'm³'
      value_template: "{{ states('input_number.gas_counter') | int / 1000 | round(3) }}"
      device_class: gas
      state_class: total_increasing

I think it’s because you’re using the legacy template sensor format (pretty sure it can’t handle state class). Try the current one:

Thanks for your support but…

EDIT : sorry, still legacy format…

Did it !

This is the correct syntax :

- platform: template
  sensors:
    gas_volume:
      friendly_name: "Gaz Volume"
      unit_of_measurement: "m³"
      device_class: "gas"
      attribute_templates:
        state_class: total_increasing
      value_template: "{{ states('input_number.gas_counter') | int / 1000 | round(3) }}"

Thanks !