No zero values in statistics

Hi,

I try to do get the COP per month for my heat pump. The issue is, that if the heap pump is not running the COP is “0”.
That means in the statistics, the Cop is not usable.

I found this topic https://community.home-assistant.io/t/statistics-how-to-exclude-zero-values-from-statistics/676172

Maybe you can help me out with the new template helper in the UI.

I used the code from the other post, just with my sensors:

availability: “{{ is_state(‘sensor.luxtronik2_status’,‘heating’) }}”
state: “{{ ( states(‘sensor.luxtronik_cop_2’)|float(0)|round(1) ) }}”

I get 2 errors as you see here:

Any idea how to solve it?

You can’t put the availability template in the state template box. It is a completely separate option that the UI template helper has no entry box for. You have to use YAML if you want to supply an availability template option.

Hi Tom,

thanks for your feedback.

I tried to create a template sensor but I guess I mixing something up.

At the end I would like to have sensors which I can use in statistics which show the COP for the status “heating” and the status “hot water”.
Maybe this is not possible in one template and I need more?

Would be great if you can give me another hint to solve it. :slight_smile:

Sure I can help if you copy the text you have in the image above and past it in the forum, correctly formatted using the </> button.

Thank you for your quick reply and help. I also read your post:

https://community.home-assistant.io/t/why-an-availability-template-is-important-for-energy-template-sensors/700740

But I’m not experienced enough to understand the codes.

This ist what I have in my configuration.yaml right now:

template:
 
  - sensor:
      - name: "COP Heizung"
        unique_id: 198ba133-be7c-4114-b840-8c9f847d639b
        state: "{{ ( states('sensor.luxtronik_cop') | float(0) | round(1) ) }}"
        availability: "{{ is_state('sensor.luxtronik2_status', 'heating') }}"

Assuming that is in your configuration.yaml file it is correct.

If this is the first time you have used templates you will need to restart. Otherwise a template reload will do.

The CoP value will be unavailable unless the status is heating.

You will need to add a unit_of_measurement if you want to graph it. As CoP is a unitless ratio you can use:

unit_of_measurement: " "

gerat its working.

I just added:

state_class: measurement

to get it into my statistics.

will see if this is working.