How to configure a Sensor so that is useable in in the energy Dashboard

I have similar issue. I have sonoff device that gives output as power W, i tried reimann through UI but … couldnt get it working, not shown anywhere in energy dashboard :frowning:

It’s not surprising for the sonos which exposes a power (in W) while the energy dashboard expects an energy (in Wh).

i know, this is why i tried riemann sum integral. I just dont know how to set it up, do i need to make it via configuration.yaml ?

And, im a complete noob on these things :slight_smile:

There’s no need to do anything in yaml anymore. You can do everything from the UI…

Create a new helper using the Riemann (make sure to give it a new name and select your sensor) than wait a bit and you should have the sensor available in the energy dashboard.

The new energy sensor can also be visible in the Developer tools > States… Take a screenshot from there with the attributes and share it here if you still having issues.

1 Like

Yes, thank you. I was just too hesitant, needed to wait for it to get something to show :slight_smile:

In my case with a value already in m3, so the Riemann conversion does not seem to be the solution?

Dear,
I created a Sensor (Arduino) which give a value in M3.
I need to convert to energy (Wh) by simply make a conversion (multiplication by +/- 10).
It is something similar to Riemann but no “integration” but easier a multiplication.
Is it possible to create a HELPER which do a multiplication and change the unit to Wh ?
If not, I need to do it in my Arduino and expose energy directly. But I suppose other device on the market expose volume and need to be converted to energy.
Thank a lot

You can create a simple template sensor.

Something like this:

template:
  - sensor:
    - name: Your new sensor name
      unique_id: your_new_sensor_unique_id
      unit_of_measurement: "Wh"
      device_class: energy
      state_class: measurement
      state: >-
        {% if is_number(states('sensor.your_existing_entity_id')) %}
          {{ states('sensor.your_existing_entity_id') * 10 }}
        {% else %}
          {{ states('sensor.your_existing_entity_id') }} # this will catch any 'unknown' states from the source sensor and replicate that to the new sensor
        {% endif %}
1 Like

Would the input sensor need to be in W or KW?

Hi,

I also have an issue like this. I use Tasmota and get entities for Power and “smartmeterreader_energy_total_in” and “smartmeterreader_energy_total_in_out” from my power meter in the Tasmota entities. All so fine, but I can not select the energies in the Energy Dashboard without the “trick” by creating a template sensor (see solution here: Energy consumption with Tasmota power monitoring plug).

But this does not satisfy me :wink:

I also tried to change the device_class, unit_of_measurement and state_class with the customize.yaml, which brings the needed effect of the entity to show up in the Energy Dashboard, but it doesn’t. So to vizualize it for this post here I have the following configuration:

customize.yaml:

#sensor.bitshake_smartmeterreader_energy_total_in:
#  device_class: energy
#  unit_of_measurement: 'kWh'
#  state_class: total_increasing
sensor.bitshake_smartmeterreader_energy_total_out:
  device_class: energy
  unit_of_measurement: 'kWh'
  state_class: total_increasing

And the entities look as follows (after complete restart of Home Assistant):

Although the “…_energy_total_out” has the correct attributes, it does not show up in the Energy Dashboard. I also tried it with state_class: total, but it was the same.

Can someone help here out please?

Thank you!

Ok, it even doen’t work with the solution I linked, so I have no solution yet.

Following problem with the solution which I linked. I added the following sensor templates in the configuration.yaml:

template:
  - sensor:
      - name: "Stromzaehler_Energie_Total_Bezug"
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        state: "{{ states('sensor.bitshake_smartmeterreader_energy_total_in')|float}}"
  - sensor:
      - name: "Stromzaehler_Energie_Total_Einspeisung"
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        state: "{{ states('sensor.bitshake_smartmeterreader_energy_total_out')|float}}"

And then I really can choose “Stromzaehler_Energie_Total_Bezug” and “Stromzaehler_Energie_Total_Einspeisung” in the Energy Dashboard, but get the following error:

Does anybody knows how to fix this?

Not it works, also without the template Sensor. Problem was, that I set in the customize.yaml

unit_of_measurement: 'kWh'

and it must be

unit_of_measurement: kWh

without the ticks. Furthermore I needed to remove the old statistics via Development Panel->Statistics. There it was shown that the entities have a problem, which can be fixed.

Now I have not template sensors in the configuration.yaml anymore and the following entity changes in the customize.yaml:

#Tasmota
sensor.bitshake_smartmeterreader_power_power_curr:
  device_class: power
  unit_of_measurement: W
  state_class: measurement
sensor.bitshake_smartmeterreader_energy_total_in:
  device_class: energy
  unit_of_measurement: kWh
  state_class: total
sensor.bitshake_smartmeterreader_energy_total_out:
  device_class: energy
  unit_of_measurement: kWh
  state_class: total

Now the energy entities can be selected in the energy dashboard!

1 Like

I was also having trouble with a template sensor through a riemann helper and adding the helper to the dashboard. As posted above it seems important that the template sensor has state_class: measurement.

Example:

- sensor:
    - name: "Current Power"
      unit_of_measurement: 'W'
      device_class: "power"
      state_class: measurement
      state: >
        {% if is_state('switch.some', 'on') %}
          400
        {% else %}
          0
        {% endif %}

After this I created a new Riemann integration using the Helper UI and was able to add the helper to the Energy Dashboard as an Individual device. Hope this helps.

I’m some how not able to figure out on why I can’t select this sensor in the HA dashboard:

    - name: "Growatt Solar PV Energy Today"
      state_topic: "energy/solar"
      value_template: '{{ ((value_json["PV1EnergyToday"] + value_json["PV2EnergyToday"]) | round(2)) }}'
      device_class: energy
      state_class: total_increasing
      unit_of_measurement: "kWh"

The individual ones from the strings can be selected without issues:

    - name: "Growatt Solar PV1 Energy Today"
      state_topic: "energy/solar"
      value_template: '{{ value_json["PV1EnergyToday"] }}'
      device_class: energy
      state_class: total_increasing
      unit_of_measurement: "kWh"

    - name: "Growatt Solar PV2 Energy Today"
      state_topic: "energy/solar"
      value_template: '{{ value_json["PV2EnergyToday"] }}'
      device_class: energy
      state_class: total_increasing
      unit_of_measurement: "kWh"

As far as I see there’s no difference really between them, all have the energy device_class, a correct unit and state_class

Thank you - that solved it for me. I had old statistics data in the sensor which needed to be cleaned first. After that, it showed up fine :slight_smile: