Energy Consumption Problem

Hey There

I’d Like to track my energy Consumption of a device… i only gut the Ampere Value of the device… But i know i just can calculate 230v*0.073A=~17W.

My Configuraton

template:
  - sensor:
      - name: "KNX Verbrauch Total"
        unique_id: knx_energy
        state: "{{ states('sensor.knx_stromverbrauch')|float|round(4) * 230 / 1000 }}"
        availability: "{{ states('sensor.knx_stromverbrauch')|is_number }}" 
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total

then i created a helper

and added it to the dashboard
image|387x282

but i go the value of unknown
image|690x240

what am i doing wrong?

Hi :wave:!

This is not energy but power.
Not state_calss total but measurement
Has a unit of kW instead of kWh (but you may skip the division and just use W for better readability).

Also it’s entiry_id seems to be sensor.knx_verbrauch_total but you configured your Riemann helper to use sensor.knx_kwh.
(The helper calculates it to “energy” and “total_increasing” and “kWh”/“Wh”).

1 Like

Hey thanks!

I Chnaged the Yaml Config (below), and created a new Riemann helper. But the Riemann helper ist not available in the energy dashboard

      - name: "KNX Verbrauch Total"
        unique_id: knx_energy
        state: "{{ states('sensor.knx_stromverbrauch')|float|round(4) * 230  }}"
        availability: "{{ states('sensor.knx_stromverbrauch')|is_number }}" 
        unit_of_measurement: "W"
        device_class: power
        state_class: measurement

What i don’t understood is, whe ist there no knx_energy available and the source is named knx_verbrauch_total. (knx_energy is not available in the helper configuration).

Any Idieas?

knx_energy is the unique_id of this entity. This is never used in any user-visible configuration. Only the entity_id is used. And this is, if it was not changed meanwhile, sensor.knx_verbrauch_total. You can see this in Dev-tools → States.

1 Like

Okay thanks for the explenation!

in the states, the measurment values are okay, but the Riemann Entites is “unkown” and uses the soruce_entity: knx_verbrauch_total.

Why is this unkown, any ideas how i an fix this… or am i to impatient, and have just to wait 2h to collect the values?

Exactly this, or sensor.knx_verbrauch_total?
Maybe have a look in the logs if there is some kind of message.

1 Like

I Found following error

The unit of sensor.knx_verbrauch_total (W) can not be converted to the unit of previously compiled statistics (kWh). Generation of long term statistics will be suppressed unless the unit changes back to kWh or a compatible unit. Go to Link to Developer Tools: Statistics – My Home Assistant to fix this

So i have changed the unique id and created a new Riemann integration. I Hope i got some values there after 1-2h

image

Still not working like expected.

The Riemann helper still (after 3h) has Unkown value. The source value is always ~17W

Should i Choose Left or Right Riemann Integration?

I have just tested this with a random power sensor. I only set a source entity and left everything at default → Trapezoidal rule.
A value was shown immediately.

I did a second test with a different sensor that rarely changes value → state of the helper was “unknown”. So I guess a change of value is required to start calculation 🤷
Looking at your graph above it looks like your sensor doesn’t change value much. If that is true, maybe try to add always_callback: true to the knx sensor and force_update (I think its called so) at the template sensor.

Hey thanks… i tried this, but force_update is not available for templates sensors. I did some google searches and found a workaround for this.

I had to add an attribute (that changes every second (maybe minute will also work?)).

so in conclustion, when a sensor state does not change often. Wee need to user force_update or as a workaround we need to add a changing attribute for the sensor.

I also changed the KNX sensor… but i think in my case this has no effect. (Depens on the KNX Component)

I ended up with this:

      - name: "KNX W Spannungsversorgung"
        unique_id: knx_power_measurement
        state: "{{ (states('sensor.knx_stromverbrauch')|float * 230)|round(4) }}" 
        availability: "{{ states('sensor.knx_stromverbrauch')|is_number }}" 
        unit_of_measurement: "W"
        device_class: power
        state_class: measurement
        attributes:
           last_sample: "{{ now() }}"

Ah ok I was just going to suggest using a lambda

I had to to this once in esphome, so I wasn’t sure it would even work in HA

  - platform: adc
    pin: 35
    attenuation: 11db
    name: "Voltage Battery"
    filters:
    - lambda: return x * 2 *3.3 *1.1 / 4095 * 1000;
    unit_of_measurement: "Voltage"
    update_interval: 300s