Utility Meter sensors not showing as available in energy dashboard

I have created a SNMP sensor to grab wattage figures from my PDU for kubernetes nodes in a cluster. This works great. I wanted to display this on the energy dashboard, so after screwing around with various ways of trying to make the sensor work, including adding a statistics sensor, I decided to use utility meter plugin, since it is supposed to show up. I have other utility meter sensors that DO show up as available in the list, but for some reason, the ones created for monitoring consumption from the PDU do not. Am i missing something here?

i have it set up as an hourly sensor, just like the ones i use for monitoring my various tariff usage sensors, so not sure whats different about this.

Not working:

Working:

When you say “wattage figures” are you talking about energy or power?

Assuming it is an energy sensor, it needs the following attributes:

The correct unit: Wh or kWh
The correct device_class: energy
The correct state_class: total or total_increasing

The SNMP integration does not support this directly so you will have to use customize to add these attributes.

hey @tom_l Thanks for the reply! So actually, I went to go grab my config for you and I think I might know the issue. Here’s the snmp sensor:

- platform: snmp
    name: "Kubernetes Node 1 kWh"
    icon: mdi:flash
    host: 192.168.1.108
    baseoid: .1.3.6.1.4.1.534.6.6.7.6.5.1.4.1.6
    accept_errors: true
    unit_of_measurement: "kWH"
    value_template: "{{((value | int) / 1000) | float | round(3)}}"

I just noticed, that the unit of measurement is “kWH”, not “kWh”. is it THAT sensitive? proceeding on, this (and others like it) grab the kWh measurement from the PDU. I then have a utility meter set up like this:


but I bet it’s because it’s not kWh… let me try changing the unit and see if it works.

Yes it is :slight_smile:

grrr. lol

One last question, while I let this start collecting fresh data. I do notice that I have another sensor that DOES show up, but it’s a template sensor that feeds the utility meter. Is having a “device_class: energy” mandatory as well? here’s the two snmp sensors + template that DO work:

  - platform: snmp
    name: "TrueNAS PSU 1 kWh"
    icon: mdi:flash
    host: 192.168.1.108
    baseoid: .1.3.6.1.4.1.534.6.6.7.6.5.1.4.0.2
    accept_errors: true
    unit_of_measurement: "kWh"
    value_template: "{{((value | int) / 1000) | float | round(3)}}"

  - platform: snmp
    name: "TrueNAS PSU 2 kWh"
    icon: mdi:flash
    host: 192.168.1.109
    baseoid: .1.3.6.1.4.1.534.6.6.7.6.5.1.4.0.2
    accept_errors: true
    unit_of_measurement: "kWh"
    value_template: "{{((value | int) / 1000) | float | round(3)}}"

  - platform: template
    sensors:
      truenas_energy_total:
        friendly_name: "Total TrueNAS kWh"
        value_template: "{{ states('sensor.truenas_psu_1_kwh') | float + states('sensor.truenas_psu_2_kwh') | float }}"
        unit_of_measurement: "kWh"
        device_class: energy

If the “device_classs: energy” is required, i can add a template sensor for the other sensors. I just did this one special as I’m grabbing the wattage figures for two power supplies.

Thanks!

Is it the SNMP sensors that work or the Utility meters they feed?

Have a look in Developer tools → States.

What attributes do the SNMP sensors have?

If they are fed to utility meters, what attributes do these sensors have have?

1 Like

the utility meters they feed works. sorry haha so here’s the “flow”:

2 SNMP sensors → Tempate sensor to merge the two PSU’s into one reading → utility meter → energy dashboard

for the non working utility meter, the flow is:

snmp sensor → utility meter

here’s what device state shows:

so it looks like it has all those values, just my fat fingering on the kWH vs kWh messed things up. I’ll report back in the morning if it works =) Thanks for your assistance!

edit: LIGHTBULB! I see. I DO need to either add device_class to the snmp sensor, or add a template sensor between it and the utility meter. I’ll try the device_class first.

1 Like

FIXED! thanks @tom_l The solution was to add the state_class and device_class to the snmp sensor, as such:

- platform: snmp
    name: "Kubernetes Node 1 kWh"
    icon: mdi:flash
    host: 192.168.1.108
    baseoid: .1.3.6.1.4.1.534.6.6.7.6.5.1.4.1.6
    accept_errors: true
    unit_of_measurement: "kWh"
    value_template: "{{((value | int) / 1000) | float | round(3)}}"
    device_class: energy
    state_class: total_increasing

they now show up as entities for the energy dashboard:
image

Thanks again!

TIL. I did not know that the SNMP platform supported those options (I should have checked the docs).

:+1:

Found it on accident from this post: SNMP Sensor - unit_of_measurement being ignored · Issue #71462 · home-assistant/core · GitHub
your doc bot sent me to the link for the snmp docs and thats where I saw it haha.

Yep if I had bothered to take even a cursory glance at the available options I would have seen it.