I have a simple electrical set-up, no solar. I have 2 sensors, 1 is an integral HASS sensor (incorrect data) and the other is an esphome integration sensor. Both are doing the same job, but I had a sneaking suspicion something was wrong due to my untracked energy in the energy dashboard being a relatively large negative number.
Both sensors were freshly created, start at 0 and use the same source data. The HASS sensor reports a lifetime value of 4.175 kWh, while the esphome sensor reports the correct 2.884 kWh. That’s quite the difference!
I’m not sure what I can do besides creating left and right integral sensors to see if they show the same behaviour. I am under the impression that trapezoid was the best for highly fluctuating sensors like a power sensor, is that incorrect?
Edit: The esphome docs specify that the integration sensor uses trapezoidal rule as the default method. So something is up with how HASS is calculating.
- platform: template
name: "${friendly_name} - HASS Voltage"
id: voltage
device_class: voltage
state_class: measurement
unit_of_measurement: V
internal: True
update_interval: 5s
lambda: |-
int volts = 120;
if ( !(isnan( id(washer_plug_volts).state ) ) ) {
volts = id(washer_plug_volts).state;
} else if ( !isnan( id(ac_plug_volts).state ) ) {
volts = id(ac_plug_volts).state;
}
return float(volts);
on_value:
then:
- lambda: |-
float voltage = x;
float power_L1 = voltage * id(current1).state;
float power_L2 = voltage * id(current0).state;
id(watts0).publish_state(power_L2);
id(watts1).publish_state(power_L1);
id(total_power).publish_state(power_L1 + power_L2);
- platform: template
name: "${friendly_name} - Total Power"
id: total_power
device_class: power
state_class: measurement
unit_of_measurement: W
lambda: return 0;
update_interval: never
- platform: integration
name: "${friendly_name} - Energy"
sensor: total_power
id: total_energy
time_unit: h
restore: true
unit_of_measurement: kWh
state_class: total_increasing
device_class: energy
# if in Wh turn to kWh
filters:
- multiply: 0.001
Here is the history graph for my house total power. I get my meter reading using zigbee smart energy profile, so it’s directly from the electrical supplier meter.
Here is the energy dashboard kWh for that time period as well. It shows total house usage as 3.14 kWh, while the integral sensor for the dryer shows more than that for the 6-7 AM period.
If you go and read the paragraph on method in the integral documentation you will see that to reduce approximation errors for this sort of square waveform
That’s fair, I did read the docs and it said for sensors that fluctuate a lot, trapezoid rule should be best?
From the docs:
The left method follows the Left rule. The method underestimates the intrinsic source, but is extremely accurate at estimating rectangular functions which are very stable for long periods of time and change very rapidly (e.g. such as the power function of a resistive load can jump instantly to a given value and stay at the same value for hours). If your source keeps its state for long periods of time, this method is preferable to the trapezoidal.
From that description, it seems to say if the sensor stays at a stable state after initially spiking?
Why would the esphome trapezoid sensor have such a difference though, if they are using the same method on the same source data? I’m trying to understand the concept rather than just fix the problem.
I created new sensors in Hass and esphome with left and trapezoidal this morning to compare data.
I’m assuming the esphome sensor is closer to the correct result based on the energy dashboard consumption for 6-7am. The electric meter is reporting 3.14 kWh total for the whole house. 2.884 kWh seems reasonably close, that only leaves 256 Wh for other equipment.
The 2 CT clamps I am using need to be calibrated better as it seems there is slight over reporting of amps for the dryer. When I turn the dryer on, the whole house instant watts sensor reports a spike of between 5500-6500+ W and the 2 CT clamps report approximately the same, so I know it’s close to what the dryer is using.
Idk if the esphome sensor is accurate, I’m more wondering how 2 sensors using the same Riemann sum method and same source data have wildly different outputs. That’s what has got me confused.
The vue utility instant watts sensor is the readings from an emporia vue utility connect which uses an esp32 and a MGM zigbee chip flashed with zigbee smart energy profile. My electrical meter acts as the coordinator and provisions the emporia device which asks the meter for readings every 5 seconds. I have checked the emporia data and it matches up to what my meter and billing say. So I am fairly certain the whole house kWh and instant power sensors are correct.
I guess what has me confused is the way the docs are wording it. From my understanding, left would be used for something with an initial spike and then a constant load. The electric dryer isn’t constant, it fluctuates, so that’s where I am getting confused.
Alright, so it seems my original hypothesis of Hass having some calc/logic errors seem true for trapezoid method…
I made new left and trapezoid sensors for Hass and esphome. The esphome trapezoid, left and Hass left sensors all report the same value. The Hass trapezoid sensor is over reporting.
In most cases yes, except I have configured esphome to bulk update all power sensors. Every 5 seconds L1, L2 and total power are updated via an on_value hook.
I may be wrong, but I believe Hass and esphome integral sensors are receiving the same data at approx the same time (assuming millisecond differences). I can see the Hass sensor updating every 5 seconds using the last updated secondary info. I can also see in the Hass dashboard (and esphome debug logs) that the esphome power sensors are being updated and sending their state to Hass every 5 seconds.
Again, I may be wrong but I believe that Hass and esphome are both getting the same data at the same intervals.