Issue with energy calculation on a small device

Hi guys,

I have a small device which is doing air extraction from my basement. It’s not a connected device but it’s controlled by a Sonoff BASICZBR3 which unfortunately does not have energy measurement.

Since it has a power that is more or less stable, I create a fake sensor that returns the power for it based on the switch value from the Sonoff device. And then, and integration to get the energy in kWh.

- platform: template
  sensors:
    vmc_sous_sol_power:
      unit_of_measurement: W
      device_class: power
      value_template: >-
        {{ 28 if states('switch.vmc_sous_sol') == 'on' else 0 }}

- platform: integration
  name: VMC sous-sol kWh
  source: sensor.vmc_sous_sol_power
  unit_prefix: k
  unit_time: h
  method: left
  round: 6

I already did that for a heater that is not connected or reporting energy measurement and it has worked well for months.

Well, problem is: the energy entity does not get updated and I’m wondering if it’s not related to the integration calculation itself… the device only draws 28W, so it’s like 0.028 kWh and if the maths are done every seconds (actually I don’t know how often it is updated/calculated), then it’s 0,000007777777778 kWh that should be added every seconds, which is less than the default round value (3) in the integration sensor (I tried to put this value to 6 already, without success)

So if anyone has a clue on this… ? :slight_smile:

Powercalc integration will make your life much easier.

But back to your sensors, I don’t see why it isn’t working. You shouldn’t care about the changes per second, as the integration sensor will take care of add the new piece of power consumed every time that sensor measure something. I just would change the method from “left” to “trapezoidal” (the default).
And you don´t need the round: 6 as the sensor is measuring the kW per hour, not per second, even if it updates every second or so.

And take a look at your logs for any message related to this sensor.

1 Like

Awesome component… and it has a feature to group devices! Exactly what I was looking for.

I’ll try the trapezoidal method as well and let you know.

Thank you.