Tracking energy use

I’m using a CT clamp on the live from my electricity meter to track whole home electricity use. This goes via a D1 Mini in ESPHome. So the config file for ESPHome looks like this:

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: 10.0A - change this!
          # Value shown in logs: 0.01229A - change this!
          - 0.0225 -> 10

  # Example source sensor
  - platform: adc
    pin: A0
    id: adc_sensor
    
  - platform: total_daily_energy
    name: "Total Daily Power"
    power_id: my_power

  - platform: template
    id: my_power
    name: "Measured Power"
    lambda: return id(measured_current).state * 230.0 / 1000; #Power = Current * Voltage (so change 230 to whatever your mains voltage is)
    unit_of_measurement: 'kW'
    update_interval: 5s

time:
  - platform: sntp
    id: my_time

That seems to track fairly accurately. The daily power then resets at about midnight. It seems to vary by a minute or so.

I also use the Octopus energy API to get the half hourly unit prices so I can get an idea of cost.

What I’d like to do though is add in a variable into HA, once, for the meter reading in kWh. Then, have “something” increment the variable every time a kWh is hit with the CT clamp. The hope is that my variable in HA should be inline with the meter reading. I don’t care if it’s an actual variable, or just the reading hardcoded into a script.

My problem… I’m not sure where to start.

Can anyone assist, please?