Energy Dashboard doesn't work

Hi everyone,
I can’t get the energy dashboard working and I don’t understand why.
I started monitoring my energy consumption and production many years ago with arduinos that communicate via MQTT and that’s my result:
image

From the right to the left:

  • solar panel production
  • 1st-floor energy consumption
  • base floor energy consumption
  • entire house consumption (sum of both floors)
  • house consumption - production

Here is an example of my solar power production sensor (KWh):

- platform: mqtt
  name: 'Produzione Pannelli'
  state_topic: 'power'
  unit_of_measurement: 'KWh'
  value_template: "{{ (((states.sensor.produzione_pannelli_amp.state | float - (states.sensor.produzione_pannelli_amp.state | float * states.sensor.produzione_pannelli_amp.state | float / 1000)) * 230) | int / 1000) | round(2) }}"
  icon: mdi:flash
  device_class: energy
  state_class: measurement

by setting device_class, state_class and reset I was able to use it in the energy configuration. I set everything yesterday so it’s elapsed more than 2 hours.

That’s my current configuration:

where “Energia immessa in rete” is a calculated/template sensor (0 if the house consumption is greater than the production else production - consumption

- platform: mqtt
  name: 'Energia immessa in rete'
  state_topic: 'power'
  unit_of_measurement: 'KWh'
  value_template: >
    {% if (states.sensor.consumi_totali.state > 0) %}
        0 
    {% else %}
        {{ (-1 * states.sensor.consumi_totali.state | float) | float }}
    {% endif %}
  icon: mdi:flash
  device_class: energy
  state_class: measurement

And unfortunately, that’s my energy dashboard:

What am I doing wrong?

anybody? I’m still facing the problem :’(

I see 2 problems :

  unit_of_measurement: 'KWh'
  state_class: measurement

needs to be :

  unit_of_measurement: 'kWh'
  state_class: total_increasing

TNX
I changed the unit of measure and it started working (here are the available ones Sensor Entity | Home Assistant Developer Docs)

as far as state class is concerned, if I understood correctly, measure is when the sensor measure the current value (clamp sensor), while total_increasing is when the sensor increase always the value (energy meter).
Is it right?

Thanks again for helping me out!

state_class: measurement for power
state_class: total_increasing for energy

I have a similar problem. The setup looks correct, but the solar production on energy dashboard is always zero:

My sensor config:

platform: mqtt
  name: "Miesięczna_produkcja"
  state_topic: "pv/values"
  unit_of_measurement: kWh
  value_template: "{{ value_json.Monthly_Production }}"
  device_class: energy
  state_class: total_increasing

Please, help.

I would do but unfortunately, I’m still having problems.

It’s not possible to set state_class: total_increasing for mqtt sensor. When I check the configuration I receive value not available, that’s might be the reason why @grzesiek1651 the chart is 0. A part from that based on the link Sensor Entity | Home Assistant Developer Docs it’s not correct for my case (clamp sensor):

Similar to measurement , with the restriction that the state represents a monotonically increasing positive total

That’s what my sensor recorded yesterday:

And that’s what energy monitor recorded o_O

I really can’t understand what’s going on