Calculation of the net energy consumtion of a heat pump

Hello,

I would like to calculate the net energy consumption of the heat pump from the power (or consumption) of my HP and the feed-in of my PV system, i.e. only the consumption that the heat pump draws from the grid. Power consumption of the HP and feed-in power of the PV system are already in HA, as well as a signal when the HP is running.
Unfortunately, the corresponding parameters are not available in the automation or helper and I am not so familiar with the programming language python.
Who has something like this already realized or an idea how to do it. Thanks a lot.

Holger

I assume the grid power is the consumption power minus the PV power?

If that is so, a simple template sensor will do it.

Hi, yes, and it has also an own entity served by the API from the inverter of the PV-plant. What is your proposal? Thanks.

That is the answer.

Do you have example? Thanks

Search here for template.

This is the code I use:


But I get an error message. What is wrong? Thanks.

Hard to tell with half the graphic cut off

sensor:
  - platform: template
    sensors:
      Sensor_WP_Energie_no_PV:
        friendly_name: "Sensor für WP Energie ohne PV"
        value_template: >-
          {% if is_state('binary_sensor.vicare_compressor_active', 'on') and states('sensor.wp_energie_netto') | float > 0 %}
            {{ states('sensor.shellypro3em_3ce90e6ece44_total_active_power') }}
          {% else %}
            0
          {% endif %}

I think

sensor:
  - platform: template
    sensors:
      Sensor_WP_Energie_no_PV:
        friendly_name: "Sensor für WP Energie ohne PV"
        value_template: >-
          {% if is_state('binary_sensor.vicare_compressor_active', 'on') and (states('sensor.wp_energie_netto') | float > 0) %}
            {{ states('sensor.shellypro3em_3ce90e6ece44_total_active_power') }}
          {% else %}
            0
          {% endif %}

Ie extra set of ( ) in the if line.

Thanks, but sorry, doesn’t work, no changes.

What does the template editor say?

Sensor None has device class ‘power’, state class ‘measurement’ unit ‘kW’ and suggested precision ‘None’ thus indicating it has a numeric value; however, it has the non-numeric value: ‘template: - sensor: - friendly_name: Sensor für WP Energie ohne PV unit_of_measurement: kW device_class: power state_class: measurement state: > 0 state: 0’ (<class ‘str’>)

I got it. The failure was I published it in the helper section instead of the entity section, now it works. Thanks.