Try to understand Power Sensor Component with ESPHome

I bought some Gosund SP1 plugs and quite happy with how simple they are to get running with ESPHome. I followed Calibrating an ESPHome flashed power plug » Frenck.dev to get them calibrated. Also figured out that with the new Engergy Dashboard an additional energy entry is needed for the sensor.

But what I am really struggling is the power sensor. Frenck does calibrate them in addition to the current and voltage, but I do not understand why. The power is a simple calculation of current multiplied with the voltage. Now I have calibrated my current and voltage and the outcome is a power which is way off.

Why is this, does the sensor itself calculate the values and not ESPHome using the calibration I did?
If this is the case, I want to get rid of the power from the sensor and get the power calculated from current and voltage. Those are easy to calibrate and the rest is just math.

Can someone help me what in understanding this ?
First I want to understand what is calculating the values, the sensor itself or esphome, if the sensor delivers the values I would understand why they are off and need calibration :slight_smile:
Can I create my own power by the calibrate current and voltage valures in esphome?
And how is the energy sensor being generated? Is this just the Watts per time? Because then it would be once again way off and I would like to let it calculate using the calibrated current and voltage.

This is my yaml

sensor:
  # Power sensor
  - platform: hlw8012
    sel_pin:
      number: GPIO12
      inverted: true
    cf_pin: GPIO04
    cf1_pin: GPIO05
    change_mode_every: 3
    update_interval: 3s
    # Current sensor
    current:
      name: "${upper_devicename} Current"
      unit_of_measurement: A
      accuracy_decimals: 2
      filters:
      # Map from sensor -> measured value
        - calibrate_linear:
            - 0.0 -> 0.0
         # Heizkörper
            - 0.21 -> 0.13
            - 5.21 -> 4.10
            - 10.05 -> 7.92
          # Glühbirne 60W
            - 0.33 -> 0.24
            
    # Voltage sensor
    voltage:
      name: "${upper_devicename} Voltage"
      unit_of_measurement: V
      accuracy_decimals: 0
      filters:
      # Map from sensor -> measured value
        - calibrate_linear:
          - 0.0 -> 0.0
        # Heikörper Vollast
          - 586 -> 227
        # Glühbirne 60W
          - 597 -> 230
        # Leerlauf
          - 596 -> 231
    # Power sensor
    power:
      id: power
      name: "${upper_devicename} Power"
      unit_of_measurement: W
      accuracy_decimals: 0
    
    energy:
      id: energy
      name: "${upper_devicename} Energy"
      unit_of_measurement: Wh
      accuracy_decimals: 0

Thanks for your help :slight_smile: also if this was already asked and answered - I search but could not find what I was looking for.

Yes in terms of basic principle power = VA but that ignores power factor. PF varies depending on type of load.

That is true, there are loads like inductive load, idle power, apparent power etc. but without really knowing the details of the chip (yet) as a customer I mainly care about the active / effective power. Which is also what most devices actually count, and as far as I know even energy supply companies did this until they started with smart meters (which sometimes also only care about the effectiv power in terms of customer).

Anyhow, if the power measurement on the plug needs to be calibrated, because it counts all the different power types, I would also need to use a motor, a fluorescent tube etc to calibrate. Which I would understand.
If this is the case, I would like to overwrite the power measurment by the simple VA calculation. Is this possible and if, how ?

On the other hand, I assume that those cheap devices just internally do VA and push it as power, or esphome is doing this. Both of this I do not know, and perhaps there is someone who can bring some light into the internals of the chip, or the esphome power calculation code.

But for now, is there a way for me to “overwrite” the power and therefor the energy to use the simple principle of Ohm’s law and does a VA calculation.

THANKS

Yes fair points. I don’t know how the chip works, but esphome is open source so you could try to understand the c++.

Ok, thanks, but I am still hoping that someone could help me, because I am not good in reading code at all :wink: especially not C++ :smiley:

But is there a solution to send the VA calculation as power or energy, instead of the data sent by the device itself ?