Energy: Not showing the expected entities for consumption

For me this works:

homeassistant:
  customize_glob:
    sensor.myomnik_energy_total:
      unit_of_measurement: "kWh"     
      device_class: energy
      state_class: measurement
      last_reset: "1970-01-01T00:00:00+00:00"
1 Like

Same here, I can’t use my custom REST smart-meter sensor with the new Energy dashboards.

1 Like

Same issue :frowning: Can I covert it to a different template sensor?

Same here,

I have configured 5 sensors to manage my hoime consumption - production but I can not select in the combobox.

Anyone has achieved it?

it would help if you show your sensors.

For instance,

This is my sensor for “current solar energy producing”

- platform: rest
    resource: http://kostal.lan/measurements.xml
    name: "Solar Generando"
    device_class: energy
    value_template: '{% for x in value_json["root"]["Device"]["Measurements"]["Measurement"] -%}{% if x["@Type"] == "AC_Power" %}{% if x["@Value"] is defined %} {{x["@Value"] | round(0,"floor")}} {% else %} 0 {% endif %}{% endif %}{%- endfor %}'
    unit_of_measurement: kWh
    scan_interval: 5
1 Like

I don’t think you can. As a work around, create a template sensor from your rest sensor.

template:
  - sensor:
      - name: "Solar Generado energy"
        unit_of_measurement: 'kWh'
        state: >
          {{ (states("sensor.solar_generado") | float | round(2) }}       
        device_class: energy
        state_class: measurement      
        attributes:         
          last_reset: '1970-01-01T00:00:00+00:00'
1 Like

Hi Francisp,

Thank you for the message, I tried to configure as you metionend but I receive:

Invalid config for [template]: invalid template (TemplateSyntaxError: unexpected ‘}’, expected ‘)’) for dictionary value @ data[‘sensor’][0][‘state’]. Got ‘{{ (states(“sensor.solar_generando”) | float | round(2) }} \n’. (See /config/configuration.yaml, line 86).

My error, I forgot a )

template:
  - sensor:
      - name: "Solar Generado energy"
        unit_of_measurement: 'kWh'
        state: >
          {{ (states("sensor.solar_generado") | float) | round(2) }}       
        device_class: energy
        state_class: measurement      
        attributes:         
          last_reset: '1970-01-01T00:00:00+00:00'

1 Like

Solved!!!

You are gorgeous!

I am able to choose the sensors now. Regarding this, I wonder if I am using the right way to import the xml data using rest, maybe there is another method cleaner?

I have some Tuya devices that measure power (in W); and I am trying to represent that in kWh using the integration (Reiman sum integral). Set as follows:

- platform: integration
  source: sensor.tuya_tv_current_consumption
  name: tuya_tv_energy
  unit_prefix: k
  round: 2

The energy now shows in kWh as follows:

but when trying to select it from the energy dropdown, it is not showing. Am I missing something?

1 Like

Looks like you need to add the device_class Energy Management in Home Assistant - #119 by dgaust

Work like charm…thanks

This solved my problem as well. Thank you

A thread dedicated for the specific issue with REST sensors can be found here: State_class: “measurement” for platform: rest - #3 by jonasgustavsson

1 Like

I’m unable to add the Slimmelezer gas measurements in the Energy tab. Do any of you struggle with this too? I get this:

Unexpected unit of measurement

The following entities do not have the expected units of measurement ‘kWh’, ‘m³’ or ‘ft³’:

I have already taken care of the reset time. Any advice is greatly appreciated.

  customize_glob:
    sensor.*consumed*:
      last_reset: '1970-01-01T00:00:00+00:00'
      device_class: energy
      state_class: measurement

* sensor.gas_consumed (m3)

be sure to have the unit set to m³ and not m3.

you should no set the last_reset any longer as this is taken car of by the correct state_class

lastly, thought not a deal breaker, try to set all attributes directly on the sensor config, and not via customize, if at all possible. Not sure if the sensors you use are from the integration Slimme Lezer, or template sensors. If the latter, set the attributes in the template. If the former, doesnt that integration set the state_class?

Hi @Mariusthvdb,

I have tried quite a few times.

The last_reset was necessary for the Energy tab to accept the Slimmelezer as a source for energy consumption. Many people in this topic have done the same. I’m puzzled by why it wouldn’t work before.

Regarding the gas: I’ve tried with the m3 in the customize_glob. That has not solved the problem. Also I wouldn’t have the slightest idea where or how to edit the state class for Slimmelezer. Do you know?

Also I think template sensors aren’t allowed in the energy tab.

Yes they are. This is my energy consumption in energy tab :

    - name: "House electricity energy"
      unique_id: '0a7476cc-d6c1-40ba-8ae1-606518c3497f'
      unit_of_measurement: 'kWh'
      state: >
        {{ ((states("sensor.mains_consumed_energy") | float(0)) + (states("sensor.upstairs_consumed_energy") | float(0)) + (states("sensor.extra_consumed_energy") | float(0)) )| round(2) }}       
      availability: >
        {{ not 'unavailable' in 
        [ states('sensor.mains_consumed_energy'), 
          states('sensor.upstairs_consumed_energy'),
          states('sensor.extra_consumed_energy') ] }}        
      device_class: energy
      state_class: total_increasing  

this seems a very clear message. the unit is incorrect. it really should be and if the entity doesn’t have that, you should either be able to set it in the customize, or preferably, check in the core repo on the integration and file an issue there.
did you check here https://www.zuidwijk.com/initial-setup-slimmelezer/ ?

sure template sensors are allowed, as long as they fit the bill. that is, are of the correct state_class and have the correct unit

      - unique_id: lights_total_device_energy
        name: Lights total device energy
        state: >
          {{states('sensor.lights_inside_total_device_energy')|float(0) +
            states('sensor.lights_outside_total_device_energy')|float(0)}}
        unit_of_measurement: kWh
        icon: mdi:lightbulb-group-outline
        device_class: energy
        state_class: total_increasing

working just fine in the panel

the state_classes have been fixed in core HA to set the last_reset, so you shouldn’t need to set that manually.

btw, if yours in a total sensor, the state_class should be total_increasing.

what does your sensor look like in dev tools states?