Problem with energy sensor

Hi,

I created a sensor to measure the output of my solar system on my garage. I will include my yaml for the sensor so you can see. The good news is the sensor seems to work correctly. If I check the state for the “Garage Solar kWh” it returns the correct value. If I try to add the sensor to the energy section it is returning a rapidly increasing value that is not the same as I get when I check the sensor state. My HA is running on an RPI.

How do I get the energy section to reflect the value I get when I check the state ?

esphome:
  name: garage-solar
  platform: ESP8266
  board: d1_mini

# Enable Home Assistant API
api:
  encryption:
    key: ""

ota:
  password: ""


wifi:
  ssid: Hallsweb
  password: jhall299

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: ""
    password: ""

captive_portal:

# Enable logging
logger:

sensor:
  - platform: ct_clamp
    sensor: adc_sensor
    name: "Measured Current"
    update_interval: 5s
    id: measured_current
    filters:
      - calibrate_linear:
          # Measured value of 0 maps to 0A
          - 0 -> 0
          # Known load: 5.0A - change this!
          # Value shown in logs: 0.01229A - change this!
          - 0.008 -> 3.12
    accuracy_decimals: 2
        
  # Example source sensor
  - platform: adc
    pin: A0
    id: adc_sensor
    
  - platform: template
    id: my_power
    device_class: power
    name: Measured Power
    lambda: return id(measured_current).state * 241.0; #Power = Current * Voltage (so change 230 to whatever your mains voltage is)
    unit_of_measurement: W
    update_interval: 5s

  #Total Solar kWh
  - platform: template
    name: Total Solar Watts
    id: totalSolarWatts
    lambda: return id(my_power).state ;
    accuracy_decimals: 1
    unit_of_measurement: W
    device_class: power
    update_interval: 10s


  #Garage Solar kWh
  - platform: total_daily_energy
    name: "Garage Solar kWh"
    power_id: my_power
    filters:
      - multiply: 0.001
    unit_of_measurement: kWh
    device_class: energy
    state_class: total_increasing
    accuracy_decimals: 2

time:
  - platform: sntp
    id: my_time

Thanks in advance for any help you can provide.

Jon

Only way I see this happening is if the value is periodically reporting as 0 within HA and then updating back to it’s actual value: since it’s total_increasing, the Energy Dashboard would view the change from 0 to the actual value as usage.

Your kWh sensor isn’t doing anything except dividing W by 1000. This just gives you kW (power) — not kWh (energy). You need to integrate (sum) W to get to Wh. Setting the device class or unit isn’t enough in itself.

I missed the platform line – and TIL. I’ve personally been using the integration platform/component, not knowing that alternative existed.

Show us the raw data plots of the sensors.

No, they are integrating it using the total_daily_energy sensor. I honestly had to look that one up, as I hadn’t come across it before with ESPHome: Total Daily Energy Sensor — ESPHome

Definitely this.

Thanks for the correction. I missed the platform line. I wonder why this would be preferred over e.g. the integration platform/component.

Thank you to everyone for commenting on this. As soon as the sun gets a little higher in the sky I will try to get some data points. Is there an easy way to do this?

The problem seems to be with the “Garage Solar kWh” which is the code I included in my original post. When I add the “CS6 Solar kWh” to the energy card the numbers all match what I expected. When I add the “Garage Solar kWh” to the energy card I get a much to large number that is increasing rapidly. At the same time I can look at the state of “Garage Solar kWh” and the number in the state looks right.

Jon

Once more:

Okay, when I got back to this today I started looking at the sensor values and they still looked normal when I looked at their state. Next, I added them to the energy card and boom, everything is working as expected. Since I have no real idea how this data is stored or manipulated, I’m guessing that there might have been some corrupted data?

I’ve been running HA for a number of months and have yet to get a grasp of the “big picture”. I’m able to get most things working by reading the forums and watching YouTube but I’m still lacking a comprehensive knowledge of how this beast works. For example, in the case of this issue, I have no idea where the sensor data is stored and manipulated to create output over time. Is there a database running in there somewhere?

If anyone is aware of any documentation or video that covers how everything works together, please point me at it. It would help me to be able to troubleshoot problems.

Thanks,

Jon