I’ve created an “instantaneous” measure of COP for my air/water heatpump.
COP is a ratio of how much heat energy is being produced for a unit of electrical energy. Electrical energy is usually fairly easily metered, but the heat energy is not as easy. Some heatpumps report various values which can be manipulated to give something approaching heat energy.
If you know the flow rate of the water on the heat transfer side, and can measure the supply and return temperatures then you can calculate the heat being emitted into the building. If you also know the electrical power being used to do that you can calculate the COP.
My calculation uses the flow rate, supply temperature and return temperature from my heatpump interface along with an instantaneous measurement of power from a clamp meter on the mains supply to the heatpump.
It obviously has some caveats attached, in that the measurements aren’t precisely aligned in time so there will be a variation in the accuracy of the measurement depending on how rapidly any one of the measurements is changing. This could probably be cleaned up with some filtering in additional Helpers.
I implemented this calculation it as a template sensor with the following template code. There are comments embedded as explanations:
{# If a system reports its temperatures in °F, this will correct the dT to Kelvin, otherwise it assumes the dT will come out as Kelvin #}
{% set Tcorr = 1 %}
{% if state_attr('sensor.e3_vitocal_secondary_circuit_supply_temperature','unit_of_measurement') =="°F"%}
{% set Tcorr = 1.8 %}
{% endif %}
{% set flowrate = (states('sensor.e3_vitocal_volumetric_flow')|float) * 997 / 3600 %} {# volumetric flow entity is in cubic metres per hour, flowrate is in kg per second #}
{% set dT = ((states('sensor.e3_vitocal_secondary_circuit_supply_temperature')|float) - (states('sensor.e3_vitocal_return_temperature')|float))/Tcorr %} {# in Kelvin #}
{% set Qheat = 1000 * flowrate * dT * 4.186 %} {# 4.186 is specific heat capacity of water [J/g K]; factor of 1000 to convert kg/s to g/s, Qheat is in kW #}
{% set Qelec = 1000 * states('sensor.circuit_37_heat_pump_power_apparent') | float / states('sensor.circuit_37_heat_pump_power_factor') | float %} {# Apparent power is in kVA, Qelec is kW #}
{{ 100 * Qheat / Qelec }}
{# Output is percent as there is no other Unit for ratio or efficiency. 100% = 1, 350% = 3.5 #}