Energy Dashboard - Sensor not showing up

Hello everyone,

hope someone can give me a hint.

I do have a smart meter where I get the values via esphome via the following configuration for my esphome - it was a project I just used from GitHub because it works for my smart meter:

  - platform: template
    id: meter01_reactive_energy_plus
    name: meter01_reactive_energy_plus
    unit_of_measurement: Wh
    accuracy_decimals: 0
    device_class: "energy"
    state_class: "total_increasing"
  - platform: template
    id: meter01_reactive_energy_minus
    name: meter01_reactive_energy_minus
    unit_of_measurement: Wh
    accuracy_decimals: 0
    device_class: "energy"
    state_class: "total_increasing"

I get the values in Home assistant which works great.

Now I just would like to convert from Wh to kWh that I can add it to the energy dashboard:

in my configuration.yaml I added the following:

sensor:
  - platform: template
    sensors:
      smartmeter_energy_plus_kwh:
        friendly_name: 'Netzbezug in kWh'
        unit_of_measurement: 'kWh'
        device_class: energy
        value_template: "{{ states('sensor.meter01_active_energy_plus') | float / 1000 }}"
        icon_template: mdi:transmission-tower-export
  - platform: template
    sensors:
      smartmeter_energy_minus_kwh:
        friendly_name: 'Netzeinspeisung in kWh'
        unit_of_measurement: 'kWh'
        device_class: energy
        value_template: "{{ states('sensor.meter01_active_energy_minus') | float / 1000 }}"
        icon_template: mdi:TransmissionTowerImport

I see it now in the developer tools as the following:

which shows the correct values and I think also the properties are good??

When I now want to add it to the energy dashboard I see just the sensor from the ESP which is in Wh and I have no chance to add the sensor from the template.

Any hints what else to try? thanks a lot in advance

Your template sensors have no state_class.

A state_class of total or total_increasing is required for the sensors to be available in the energy dashboard.

The legacy template sensor platform does not support state_class as an option. You will have to use customize to add it to the sensors.

Or start using the new template integration which does support state_class.

You should also be supplying defaults for your float filters and be using an availability template to protect your energy dashboard from junk data.

Thanks @tom_l for your answer!

I now changed to the new template integration, as I was not using templates at all until now:

template:
  - sensor:
      - name: "Netzbezug in kWh"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total_increasing
        state: "{{ states('sensor.meter01_active_energy_plus')|float / 1000 }}"
        icon: mdi:transmission-tower-export

      - name: "Netzeinspeisung in kWh"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total_increasing
        state: "{{ states('sensor.meter01_active_energy_minus')|float / 1000 }}"
        icon: mdi:transmission-tower-export

The values seem to be valid what I get, just have now the following issue, after adding it to the energy dashboard I got the message “statistics_not_defined” - unfortunately I didn’t do a screenshot and don’t get this message now anymore. Do I have to care about it? I will just observe If I see any issues the next couple of days when values are available…

I have read a bit about but I am not an experienced user with yaml configuration - not sure if I can handle it, will try to adapt the examples provided - I am not sure if I need it, I get the values from my smart meter and they are increasing on the smart meter itself - it could happen, that the connection is broken for whatever reason, but after connection is up again their might be some bigger increase, not more…

I will check the next couple of days how the values are in the energy dashboard are evolving compared to reading it directly from the smart meter… and if there is maybe an issue with the message “statistics_not_defined”.

thanks for your help, really appreciate it

Go to Developer Tools → Statistics and see if there are any FIX ISSUE buttons listed. Press them if there are.

It’s pretty simple, you just need to add a template that makes sure the sensors you are feeding the template are valid. You should also define default values for your float filters. Like this:

template:
  - sensor:
      - name: "Netzbezug in kWh"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total_increasing
        state: "{{ states('sensor.meter01_active_energy_plus')|float(0) / 1000 }}"
        availability: "{{ states('sensor.meter01_active_energy_plus')|is_number }}"
        icon: mdi:transmission-tower-export

      - name: "Netzeinspeisung in kWh"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total_increasing
        state: "{{ states('sensor.meter01_active_energy_minus')|float(0) / 1000 }}"
        availability: "{{ states('sensor.meter01_active_energy_minus')|is_number }}"
        icon: mdi:transmission-tower-export

This way if either of the source sensors are not numbers (e.g. none, unavailable or unknown) the template sensor state will become “unknown”. This will prevent big spikes in your energy dashboard when the source sensor comes back.

5 Likes

Hi! Forgive me if this is not the place to post, but I’m experiencing a similar issue when trying to add a custom template sensor to my energy dashboard. It works fine in the template editor, but can’t see to source it when trying to add devices.

 - platform: template
   sensors:
      all_other_office_kitchen:
        friendly_name: Other Office & Kitchen
        unit_of_measurement: 'KWh'
        device_class: energy
        state_class: total_increasing
        value_template: '{{ (states("sensor.plugs_office_kitchen_2_1d") | float | round(2) - states("sensor.main_desk_today_s_consumption") | float | round(2)) | round(2) }}'       
        icon_template: mdi:lightning-bolt-outline

There are probably errors in your log about this you having this in your sensor config.

Hi,

having the same Problem. Sensor will not show up in energy Dashboard.

Sensor delivers value in Wh and I want to use it in energy Dashboard.

But it is not available here.

 # Meross Switch Heizlüfter liefert Wh und die können wir im Energy Dashboard nicht brauchen,
 # daher rechnen wir aus Volt und Ampere Werten die Watt aus.
   - sensor:
     - name: "Heizlüfter Energieverbrauch (kWh)"
       unique_id: heizluefter_energie_kwh
       unit_of_measurement: kWh
       device_class: energy
       state_class: total_increasing
       state: "{{ states('sensor.smart_plug_2211015479756951080148e1e9ada23a_energy')|float(default=0) / 1000 }}"
       availability: "{{ states('sensor.smart_plug_2211015479756951080148e1e9ada23a_energy')|is_number }}"

Please help, home assistant is powerful, but using and configuring is like 300 years ago…

Greetings
Christian

1 Like

Hello,

my problem is:
I want to take a kwh Sensor into two different virutal sensors. depend on a boolean sensor.

my template.yaml:


     - name: "Strom vom Netz"
       unique_id: strom_vom_netz
       icon: mdi:pulse  
       unit_of_measurement: 'kWh'
       device_class: energy
       state_class: total_increasing
       state: >
         {% if is_state('switch.stromzkeller_laufrichtung2', 'off') %}    
         {{ states('sen![Screenshot (45)|442x343](upload://nfia56Xn00HXq6J3T0mxOyslWDs.png)
![Screenshot (46)|435x330](upload://hKQAIeDSxFTUSGKcLhQ6U773eQF.png)
![Screenshot (47)|438x361](upload://vBN8eCp4AQTqCmMknkWvdWMf8ej.png)
sor.stromzkeller_zv_stromzahler_gesamt') | float }}
         {% else %}
         0
         {% endif %}

     - name: "Strom ins Netz"
       unique_id: strom_ins_netz
       icon: mdi:pulse  
       unit_of_measurement: 'kWh'
       device_class: energy
       state_class: total_increasing
       state: >
         {% if is_state('switch.stromzkeller_laufrichtung2', 'on') %}    
         {{ states('sensor.stromzkeller_zv_stromzahler_gesamt') | float }}
         {% else %}
         0
         {% endif %}

these virtual sensors go to energy dashboard. But the sensors do not work correct with the home assistant energy module
in energy Dashboard the values are wrong. can you help me ?

.Screenshot (45)Screenshot (46)
Screenshot (47)

I have a similar problem and I think it might have to do with state_class? total or total_increasing feels wrong, but wherever I look for it in home assistant threads, that’s the recommendation

Values shown in energy board are ridiculously high (even if it was the sum of everything since i set it up yesterday)
grafik
This should show the current energy production, right?

Sensor values seem to be right:
grafik

solar Sensor configuration is simple:

 - name: solar
        device_class: energy
        state_class: total
        unit_of_measurement: "Wh"
        value_template: "{{ value_json.production.solar }}"

Update: so it’s probably because i get watts (W) but HA Energy Dashboard wants Wh. Not sure how to solve that but that’s a new approach to google with. I must say it’s way more complicated than I expected. I put in several hours yesterday to reach this point.

thanks I did not know about the statistics “fix issue”, I had a bunch of things to fix and it cleared up my issues.

Good morning!

I got installed my solar panels and want to integrate them into HA. I pass values (from_grid, to_grid, consumption) via MQTT to HA. In a first try I’ve been successful using any parameters from my solar panels. To clean up my energy-dashboard I used the hint I found somewhere in their internet and deleted ./homeassistant/.storage/energy
When I became more familiar with what is required by the dashboard I tried to provide accurate values and failed, as the provided parameters/values are not shown in the drop-down list of the energy-dashboard.
My current definitions in ./homeassistant/mqtt/sensor.yaml are

    - name: active_power
      unique_id: fusion_solar_0001
      state_topic: "fhem/PV_Lohr/active_power"
      availability_topic: "fhem/connection/status"
      payload_available: "connected"
      payload_not_available: "disconnected"
      icon: "mdi:solar-power-variant-outline"
      unit_of_measurement: "kWh"
      device_class: "energy"
      state_class: "total_increasing"
    - name: from_grid_power
      unique_id: fusion_solar_0002
      state_topic: "fhem/PV_Lohr/from_grid_power"
      availability_topic: "fhem/connection/status"
      payload_available: "connected"
      payload_not_available: "disconnected"
      icon: "mdi:transmission-tower-export"
      unit_of_measurement: "kWh"
      device_class: "energy"
      state_class: "total_increasing"
    - name: to_grid_power
      unique_id: fusion_solar_0003
      state_topic: "fhem/PV_Lohr/to_grid_power"
      availability_topic: "fhem/connection/status"
      payload_available: "connected"
      payload_not_available: "disconnected"
      icon: "mdi:transmission-tower-import"
      unit_of_measurement: "kWh"
      device_class: "energy"
      state_class: "total_increasing"

These values are accurately shown as entities


but not in the drop-down of the energy-dashboard:
Bildschirmfoto 2023-08-31 um 08.55.50
Opposite to my expectations sensor.daily_enery, which I defined (and finally deleted) earlier is still shown in the drop-down, although ist doesn’t exist any longer in my yamls.

Any help and hints are appreciated!

Thank you very much - Rallye

Holy cow. The fix issues button just saved me after fiddling around for an hour. For how much these problems affect certain integrations, they should be easier to find … Thanks!