Can't add energy sensor to energy dashboard

Hello,
I am trying to add a dehumidifier energy sensor (which is essentially the same way as fridge energy sensor). Both dehumidifier energy and fridge energy sensors are defined the same way – a sensor that estimated the current power → integration sensor that estimates energy. While I was able to add the fridge energy sensor in the past, Home Assistant doesn’t offer me to add the dehumidifier energy sensor to the Energy dashboard. Why? How can I adjust the sensor to be able to add it to the Energy dashboard?

Excerpt from my configuration.yaml:

"homeassistant":
  …
  "customize_glob":
    "sensor.fridge_energy":
      "last_reset": "1970-01-01T00:00:00+00:00"
      "device_class": "energy"
      "state_class": "total_increasing"
    "sensor.dehumidifier_energy":
      "last_reset": "1970-01-01T00:00:00+00:00"
      "device_class": "energy"
      "state_class": "total_increasing"
…


sensor:
  - "unit_prefix": "k"
    "name": "dehumidifier_energy"
    "source": "sensor.dehumidifier_estimated_power"
    "unique_id": "dehumidifier_energy"
    "platform": "integration"
…
  - "unit_prefix": "k"
    "name": "fridge energy"
    "source": "sensor.fridge_estimated_power"
    "unique_id": "fridge_energy"
    "platform": "integration"

Note that I’ve added the customize_glob part when resolving the inability to add the fridge sensor. I know that the “glob” is not much a glob and there would be probably an easier way, but I’ve just copied what I’ve found somewhere without much adjustments.

Can you show the settings and attributes of the power sensors?

Also for “globs that aren’t globs” you can use just “customize”.

homeassistant:
  …
  customize:
    sensor.fridge_energy:
      device_class: energy
      state_class: total_increasing
    sensor.dehumidifier_energy:
      device_class: energy
      state_class: total_increasing

You don’t need a last reset for the total_increasing state_class. See Sensor Entity | Home Assistant Developer Docs

Also you only need to quote the strings that have the wildcard “*” in them (when using customize_glob).

There are the two power sensors, both are templates that estimate the power:

"template":
…
- "sensor":
    "name": "dehumidifier_estimated_power"
    "state": "{{ 250.0 if (false if (states(\"switch.dehumidifier_switch\") == \"\
      off\") else (true if (states(\"switch.dehumidifier_switch\") == \"on\") else\
      \ (unexpected_value))) else 0.0 }}"
    "unit_of_measurement": "W"

…
- "sensor":
    "name": "fridge_estimated_power"
    "state": "{{ 75.0 if ((states(\"sensor.fridge_temperature_derivative\") | float)\
      \ < 0.0) else 0.0 }}"
    "unit_of_measurement": "W"
    "state_class": "measurement"

I see there is missing "state_class": "measurement" in the dehumidifier power sensor. However, both energy sensors have essentially the same attributes (Developer Tools » States):

state_class: total_increasing
source: sensor.fridge_estimated_power
unit_of_measurement: kWh
device_class: energy
icon: mdi:chart-histogram
friendly_name: fridge energy
last_reset: 1970-01-01T00:00:00+00:00

state_class: total_increasing
source: sensor.dehumidifier_estimated_power
unit_of_measurement: kWh
device_class: energy
icon: mdi:chart-histogram
friendly_name: dehumidifier_energy
last_reset: 1970-01-01T00:00:00+00:00

Anyway, I’ve added the "state_class": "measurement", but it has changed nothing.

I know the formula for dehumidifier is a bit obscure, came from a transpiler (sort of) PoC that also tries to fail on unexpected boolean inputs. But I don’t think it matters there. The overuse of quotes has a similar reason – the YAML library I use does this in the best settings I’ve found, finding something better wasn’t a priority.

On globs: Thank you. I just wanted to mention something like “I know this is stupid, it was just not my priority.”

On last reset: Thank you. This was copied from somewhere on this forum. I’ll look at it.

OK, I’ve found the reason:

WARNING (Recorder) [homeassistant.components.sensor.recorder] The unit of sensor.dehumidifier_energy (kWh) can not be converted to the unit of previously compiled statistics (None).

I’ve changed the entity name and id in order to get rid of this issue. Now, it can be added on the energy dashboard.