CircuitSetup / Expandable-6-Channel-ESP32-Energy-Meter

Hardware & Software documentation for the CircuitSetup Expandable 6 Channel ESP32 Energy Meter. Works with ESPHome and Home Assistant.
https://circuitsetup.us/product/expandable-6-channel-esp32-energy-meter/
MIT License
532 stars 106 forks source link

Tracking grid import and export kWh seperatly (grid tied solar) #74

Closed robwolff3 closed 2 years ago

robwolff3 commented 2 years ago

Hey CircuitSetup, love the product have been using it for many months now.

I have solar, I am using two CTs on the lines from the grid to my mains panel and two CTs on the lines from my grid tied solar to my mains panel. I am using your example ESP configuration for solar and its working great. One thing I would like to but am not familiar enough with ESP programing to figure it out is how to track import and export kWh of my grid side with separate kWh sensors. (The new Energy function of HomeAssistant doesn't tracks them separately and doesn't like it when it goes negative.) So if watts are positive tick the import kWh sensor up and if watts are negative tick the separate export kWh senor up.

Any configuration suggestions here? They would be greatly appreciated, thank you!

robwolff3 commented 2 years ago

I think I figured it out by adding these sensors:

#Total Grid Watts Import
  - platform: template
    name: Total Grid Watts Import
    id: totalGridWattsImport
    lambda: |-
      if (id(totalGridWatts).state > 0) {
        return id(totalGridWatts).state;
      } else {
        return 0;
      }
    accuracy_decimals: 1
    unit_of_measurement: W
    icon: "mdi:flash-circle"
    update_interval: ${update_time}
#Total Grid Watts Export
  - platform: template
    name: Total Grid Watts Export
    id: totalGridWattsExport
    lambda: |-
      if (id(ct1Watts).state + id(ct2Watts).state < 0) {
        return (id(ct1Watts).state * -1) + (id(ct2Watts).state * -1);
      } else {
        return 0;
      }
    accuracy_decimals: 1
    unit_of_measurement: W
    icon: "mdi:flash-circle"
    update_interval: ${update_time}

#Grid Import kWh
  - platform: total_daily_energy
    name: Grid Import kWh
    power_id: totalGridWattsImport
    filters:
      - multiply: 0.001
    unit_of_measurement: kWh
#Grid Export kWh
  - platform: total_daily_energy
    name: Grid Export kWh
    power_id: totalGridWattsExport
    filters:
      - multiply: 0.001
    unit_of_measurement: kWh

Case closed!