Template sensor measuring to low energy

Hi, I have various Plugwise circle plugs, which are read through a Plugwise Stretch 2 with the Plugwise integration. This works basically as expected. Both the actual power in watts are coming through and also the watts per hour (Wh) are created as a sensor.

For the Energy dashboard you need kWh sensors, so therefore I created a template sensor with the new type of configuration:

 sensor:
  - name: "Datacenter energy consumption"
    unit_of_measurement: "kWh"
    state_class: total_increasing
    device_class: energy
    state: >
      {% set value = states('sensor.datacenter_electricity_consumed_interval') | float %}
      {{ float(value) / 1000}}

The output of the sensor unfortunately is way less than

These are the plugwise readings per hour:
afbeelding

The readings from the interval sensor which was created by the Plugwise plugin are all lower then the measured ~85 - 88 Watts used per hour

afbeelding

If I sum those up in Excel, I get 1847,43 Watts used, but the template sensor reports only 1,15kWh. Off course this is incorrect. I think the spikes should be higher dan 80, which they aren’t.

Anyone any idea how to solve this? The current Scan interval is 60 seconds, should this be lower?
Thanks in advance!

@rutger You are using the wrong sensor, you should use the electricity_consumed sensor.

The interval sensor has the measurement unit Wh, so they are similar to the kWh sensor you want to create.

Also, when you make the update-interval smaller, then the accuracy will improve. Make it 10 or 20 seconds, if your Stretch can handle updating this often.

Hi @bouwew ,
First of all thanks for your reply. The interval version of the sensor represents the Watts used in that hour, right? I don’t get why this is lower than the actual reading. If the sensor is read every 20 seconds, then it should have caught the last reading in some of the last minutes in that hour?

Am I thinking wrong that calculating the amount of Watts with the ‘Integration’ integration is less reliable then the actual value which the plug has counted with hardware?

Ok, I see I read your first email wrong.

Let me start again. There are two ways you can create the increasing kWh-sensor you are looking for.

  1. Integrate the values of a sensor with the measurement unit = W, see this post Plugwise core and custom_component - #91 by bouwew

  2. Create a kWh sensor from the Wh sensor, as you tried to do originally, and then create yet another sensor that adds the values: add the new Wh-value to the sum of the previous Wh-values, every time a new hourly value is provided. This will give you the increasing kWh sensor that you need for HA Energy.

@rutger Did you manage to make it work?

Hi @bouwew ,

Yes, it is working. It took some time to get the readings accurate. But the adding of ‘method: left’ fixed that.
I’m very gratefull for your effort! Thanks!

This is the actual sensor:

platform: integration
source: sensor.kantoor_boven_electricity_consumed
name: Kantoor boven energy consumption
unit_prefix: k
round: 2
method: left

Great! Nice to read that you’ve got it working :slight_smile: