Cannot change sensor unit of measurement

Hello there

I am using an Tasmota device to read my utility meter. The device is called “gplugm”. The sensor is called “sensor.gplugm_ei”, which shows the total energy consumed this year. This is working perfectly. The value is showing up in my dashboard, but without any unit of measurement.

I need to configure the sensor as Energy sensor and set a unit of measurement “kWh” to properly use the energy dashboard.

I received this configuration script from the developer of the device

homeassistant:
 customize_glob:
 sensor.gplugm_ei:
 unit_of_measurement: "kWh"
 device_class: energy
 state_class: total_increasing

I added it to the top of my configuration.yaml but I get a bad error:

Cannot quick reload all YAML configurations because the configuration is not valid: Invalid config for 'homeassistant' at configuration.yaml, line 2: expected a dictionary for dictionary value 'customize_glob', got None Invalid config for 'homeassistant' at configuration.yaml, line 3: 'sensor.gplugm_ei' is an invalid option for 'homeassistant', check: sensor.gplugm_ei Invalid config for 'homeassistant' at configuration.yaml, line 4: 'unit_of_measurement' is an invalid option for 'homeassistant', check: unit_of_measurement Invalid config for 'homeassistant' at configuration.yaml, line 5: 'device_class' is an invalid option for 'homeassistant', check: device_class Invalid config for 'homeassistant' at configuration.yaml, line 6: 'state_class' is an invalid option for 'homeassistant', check: state_class

What am I doing wrong? Could somebody help me with an example on how to set up the sensor in Configuration.yaml?

Indentation all wrong. See here:

You must only have one homeassistant: heading in the file, so you may need to combine what you’ve been sent with what you already have.

homeassistant:

# existing config already under homeassistant: here

  customize:
    sensor.gplugm_ei:
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing

Ok, thank you! I changed it to this:

homeassistant:
 # Loads default set of integrations. Do not remove.
 default_config:
 # Load frontend themes from the themes folder
 frontend:
 themes: !include_dir_merge_named themes
 automation: !include automations.yaml
 script: !include scripts.yaml
 scene: !include scenes.yaml

  customize:
    sensor.gplugm_ei:
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing

What am I doing wrong here?

The bits you’ve included before the customize do not sit under homeassistant but are top-level keys. If you don’t already have anything under that key, just leave it. Like this:

# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
themes: !include_dir_merge_named themes
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

homeassistant:
  customize:
    sensor.gplugm_ei:
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing

Do not change the indentation level of anything already in the file. Indentation is critical in YAML.

Thank you so much!

It’s working now!