ESPHome device not available to Energy dashboard

Hi

I’m trying to add a Shelly device to my energy dashboard. I flashed it with ESPHome and it is working great.

This is my configuration (left out the wifi part):

esphome:
  name: wasplaats
  platform: ESP8266
  board: esp01_1m

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

switch:
  - platform: gpio
    name: "wasplaats_switch"
    icon: "mdi:power-socket-eu"
    pin: GPIO15
    id: relay

sensor:
  - platform: hlw8012
    cf_pin: GPIO05
    cf1_pin: GPIO13 # not used because it is not available on the 1PM but it is needed to compile
    sel_pin: GPIO14 # not used because it is not available on the 1PM but it is needed to compile
    power:
      name: "wasplaats_power"
      unit_of_measurement: W
      device_class: "power"
      id: "wasplaats_power"
      icon: mdi:flash-circle
      accuracy_decimals: 0
      filters:
      # Map from sensor -> measured value
      - calibrate_linear:
          - 0.0 -> 1.0
          - 110.33186 -> 20.62
          - 131.01909 -> 24.32
          - 341.33920 -> 62.08
          - 5561.41553 -> 1000.0
          - 2975.51221 -> 535.7
          - 9612.66309 -> 1720.0
          - 14891.35352 -> 2679.0      
      # Make everything below 2W appear as just 0W.
      # Furthermore it corrects 1.0W for the power usage of the plug.
      - lambda: if (x < (2 + 1)) return 0; else return (x - 1);
    update_interval: 3s

binary_sensor:
  # Binary sensor for the button press
  - platform: gpio
    name: button
    pin:
      number: GPIO4
      inverted: true
    on_press:
      - switch.toggle: relay

output:
  # Relay state led
  - platform: esp8266_pwm
    id: state_led
    pin:
      number: GPIO00
      inverted: true

I also added two sensors to calculate kWh and store statistics:

 - platform: integration
    source: sensor.wasplaats_power
    name: broodbakmachine_power
    unit_prefix: k
    round: 2

  - platform: statistics
    name: broodbakmachine_kwh
    entity_id: sensor.broodbakmachine_power

From the information I gathered on this forum, I think an entity needs to be of device_class energy and the integration platform should automatically add this when its source entity is of device_class power. My entity wasplaats_power however does not have a device_class at all:

For reference, another entity from a zigbee smartplug looks like this:

It looks like ESPHome is not adding the device information that is needed further down the chain. I must be doing something wrong, but I can’t see what. I hope the experts here know what to do.

Kind regards,
Merijn

I think you need device_class: energy instead of power. I think you want meassure energy use for a day for in your energy dashboard?

My config for my electric heater:

sensor:
  - platform: total_daily_energy
    name: "${device_description} Energy"
    id: energy
    power_id: power
    device_class: energy
    state_class: total_increasing
    unit_of_measurement: kWh
    accuracy_decimals: 3
    min_save_interval: 300s
    force_update: true
    filters:
      # Multiplication factor from W to kW is 0.001.
      - multiply: 0.001
      - lambda: !lambda |-
          static auto last_state = x;
          if (x < last_state - 0.001) { // x was reset
            id(total_energy) += last_state;
          }
          last_state = x;
          return id(total_energy) + x;
      - heartbeat: 60s

Maybe you can use parts of it.

Thanks for your reply. You’re right, device_class must be ‘energy’, but integration sensor (broodbakmachine_power) should be of that type when the source entity - sensor.wasplaats_power - is of device_class ‘power’. From the docs:

The thing is, my source entity doesn’t have a device_class at all.

I do like that you’re doing the calculations in ESPHome. Might have a look at that too.

1 Like

I can confirm the same observation - esphome doesn’t add a device_class: power property .