Gas meter energy sensor

Hi all,
I created a sensor for my gas meter that shows up in the energy dashboard correctly. This is the configuration:

template:
  - sensor:
    - name: gas_meter
      state: "{{ (states ('counter.gascounter') | float * 0.01) | round(2) }}"
      unit_of_measurement: "m³" 
      device_class: gas
      state_class: total_increasing

Can I give it a display name?
Regards,
Jan

You can change the “name:” to “Gas Meter” and the entity_id will be exactly the same as it is now.

It uses the name and if it’s not in the correct format it will slugify that name and that will be the entity_id.

So “name: Gas Meter” becomes “sensor.gas_meter”

If you want something completely different you will have to modify the name field in the entity configuration pop up (easiest) or in the customize section of the configuration.yaml file.

Good idea.
Actually I had this configuration before:

sensor:
  - platform: template
    sensors:
      gas_meter:
        friendly_name: Gaszaehler
        value_template: "{{ states ('counter.gascounter') | float * 0.01 }}"
        unit_of_measurement: "m³" 
        icon_template: "mdi:fire"
        device_class: gas
        attribute_templates:
          state_class: total_increasing

This is not working anymore. I would like to keep the entity id but give it a german caption.

What do you mean?

I believe that that configuration is still valid. I still use that config right now and all of them work fine (except for the additional attribute_templates which I don’t use).

Unless it’s some other problem…

The entity is just not available in the energy dashboard anymore.

Here it says it’s legacy configuration syntax

It should still work but maybe something was changed that prevents it from showing up in the energy dashboar?

I’m not sure why yours isn’t working but I just copied your legacy template sensor config directly into mine and mine works fine.

image

I copied my old sensor as gas_meter2 but it doesn’t show up:

Any ideas how I can debug that?

Look in the homeassistant.log file in the config folder and see if there are any errors for that template sensor listed.

1 Like
2023-02-12 18:41:38.182 WARNING (SyncWorker_0) [homeassistant.util.yaml.loader] YAML file /config/configuration.yaml contains duplicate key "sensor". Check lines 11 and 72

I have two lines with sensor:
It looks like the first section is ignored then.
I’ll check that tomorrow.

The new configuration starts with template so that is not an issue.

From the error it looks like you have the “sensor:” key twice in your config somewhere.

This works now.
So I have two solutions:
-Fix my two sensor sections in configuration.
-Use the template sensor syntax and live with the fact that I can only configure the id and not the name.

Thank you very much for your help!