How to create history sensor that tracks actual kWh offset of not-smart meter using kWh meter?

Hi all,
I’ve been trying to track the actual realtime state of my Analogue Mains Grid Electricity Meter, but it is not a “Smart Meter”, it’s an old Analogue Meter with a spinning disc.
I have been looking at using an AI-on-the-edge device to directly track it, but it unfortunately is in such an awkward place that it would not be feasable to install one, otherwise I would.

However, I do have a HomeWizard HomeWizard SDM230 kWh Meter directly attached to the Analogue Meter, so that directly tracks the Analogue Meter and Mains Grid usage. I also have an active solar array (With its own HomeWizard kWh Meter), so the Analogue Meter runs backwards too when “exporting” back to the Mains Grid.

Everything works, and I track both the HomeWizard kWh Meters in HA already without issues.

I want to track the actual Analogue Meter within HA.

I believe there is an “offset”, meaning the delta between the Analogue Meters “current” kWh “reading” value, and the HomeWizard kWh “current” kWh values. I’m trying to calculate that?

I think I can achieve that, using the directly attached HomeWizard kWh Meter with the offset, but I’m not sure how exactly. The HomeWizard kWh Meter also splits into “Total Power Import” and “Total Power Export” so I believe I need to take the offset and add the Import, minus that Export.

Best calculation I can figure is:
(hw_kwh_import - hw_kwh_export) + analogue_offset_delta = value?

I think I need to create a template integration to track this first, then use the history_stats integration, but I cannot see a way to set the offset.

Or I could use the “Active Power” W measurement of the HomeWizard (Which would fluctuate between plus and minus) and subtract that from the offset?

I’ve been messing around in the template editor for an hour trying to do this, and I’m confused.

Can anyone help with some pointers?

So here is what I think I’m trying to work with.

I created a number input analogue_meter_offset and I’m using that as the delta in the calculation:

{{ (
  states('states.sensor.hwwifimeter_grid_total_power_import') | float(0) -
  states('states.sensor.hwwifimeter_grid_total_power_export') | float(0) +
  states('input_number.analogue_meter_offset') | float(0)
) }}

Result is always the delta value of 86976

So I reduced it to see what is happening:

{{ (
  states('states.sensor.hwwifimeter_grid_total_power_import') | float(0) -
  states('states.sensor.hwwifimeter_grid_total_power_export') | float(0)
) }}

But I always get 0 because I think HA cannot seem to calculate the value.

Still trying to work it out…

I think I found it:

  states('sensor.hwwifimeter_grid_total_power_import') | float(0) -
  states('sensor.hwwifimeter_grid_total_power_export') | float(0)
  ) +
  states('input_number.analogue_meter_offset') | float(0)

This allows me to calculate my Analogue Meter, as far as I can tell.

I created 3 devices using the HA helpers:

First, I created the input_number.analogue_meter_offset, using the Create Number helper:

Next I created the sensor.analogue_meter_tracker using the Template Sensor helper:

Then I created the sensor.analogue_meter_grid_calculation using the Template Sensor helper:

The template for the Grid Calculator is:

  states('sensor.hwwifimeter_grid_total_power_import') | float(0) -
  states('sensor.hwwifimeter_grid_total_power_export') | float(0)

So after that I had 3 devices.

What I did to make it as accurate as possible is:

  • Stood in front of the physical Analogue Meter
  • Noted the current reading on the Analogue Meter
  • Pulled up the calculator on my phone
  • Used the phone calculator to subtract the physical Analogue Meter Reading from “Analogue Meter Grid Calculation”
  • Input the resulting number into “Analogue Meter Offset”

I ended up with:

I think it’s working, so I’ll monitor it a few days and see how it goes… :sweat_smile:

If that works, I’ll create a long term metric using the history_stats integration.

If there’s any drift due to effeciency, in theory I can also just repeat the process and update the “Offset” sensor.