Create an MQTT Sensor for Energy Dashboard

Hi everybody,
I am kind of stuck on the final way to build some sensors for my energy dashboard. I get some Mqtt values and setting them in the config.yaml under the tab “Mqtt”. So, they show up in HA and I can select them in the energy dashboard, but something is missing in my yaml because the dashboard tells me that “the entity is not defined” Can somebody hint me to my logical mistake?

mqtt:
  sensor:
    - name: "WR PV Leistung"
      state_topic: "modbus/0/holdingRegisters/35301 PV Total Power"
      unit_of_measurement: "W"
      device_class: energy
      state_class: total
    - name: "WR Netzeinspeisung"
      state_topic: "modbus/0/holdingRegisters/36104 ActiveEtotalSell Total"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      
    - name: "WR Netzbezug"
      state_topic: "modbus/0/holdingRegisters/36120 ActiveEtotalBuy Total"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      
    - name: "WR ActivePower"
      state_topic: "modbus/0/holdingRegisters/36008 MeterTotalActivepower"
      unit_of_measurement: "W"
      device_class: energy
      state_class: total
      
    - name: "WR PV Produktion Gesamt"
      state_topic: "modbus/0/holdingRegisters/35191 PV E-Total"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      
    - name: "WR Batterie Ladung Gesamt"
      state_topic: "modbus/0/holdingRegisters/35206 E-BatteryCharge"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      
    - name: "WR Batterie Entladung Gesamt"
      state_topic: "modbus/0/holdingRegisters/35209 E-BatteryDischarge"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      
    - name: "WR Batterie Ladestand"
      state_topic: "modbus/0/holdingRegisters/37007 BAT1 SOC"
      unit_of_measurement: "%"
      device_class: energy
      state_class: total
      
    - name: "WR Batterie Power"
      state_topic: "modbus/0/holdingRegisters/35183 BAT1 Power"
      unit_of_measurement: "W"
      device_class: energy
      state_class: total

Well for a start this is a power sensor, not an energy sensor:

The device class should be power and the state class should be measurement.

Likewise for your other power sensors measured in W.

The battery SOC configuration is incorrect too. Device class should be battery, state class measurement.

You need to perform a configuration check and restart home assistant after fixing the config.

Hei Tom,
thanks a lot for the class issue hint regarding the battery and power (the last one isn’t going in the energy dashboard for obvious reasons).

But I think I have found my main problem:
Home assistant docs says for sensors in the energy dashboard:
“* The entity must be a sensor. If you are trying to add something from another domain (for example an input_number), then you must first create a template sensor from it.”

Can this be my main problem? I don’t get the knowledge to create a “template” sensor first or to incorporate this in my “Mqtt” section. So, I think, I have to create template sensors for the energy dashboard first but how do I have to layout the “template” yaml section for sensors which are using MQTT values?

No that is not your problem. You are already creating sensors with the mqtt integration.

Are you sure you are selecting the correct sensors in the energy dashboard?

The sensors in your screenshot do not match the names in the mqtt config you provided.

Also do your mqtt sensors get valid values (check developer tools → states)?