Splitting energy sensor based on value

I have a heatpump which makes tapwater and is used for floorheating/cooling. I want to have separate sensors for tapwater energy consumption and floorheating/cooling(combined) energy consumption.
My physical heatpump kWh sensor is updated each 5 minutes.
I want to have a tapwater kWh sensor which is updated each hour in case the consumption that hour was larger than 1 kWh.
Else the heating/cooling kWh sensor should be updated.
So the total value of kWh sensor = tapwater + heating/cooling.
How can I create these sensors with template sensors?

You can use the tariff on utility meters. It is a list of labels that determines how to split the result. Depending on which counter you want the usage to go to you set the right tariff label. The utility meter will then make the split for you.
Note that you do not have to set a reset cycle for the utilty meter if you don’t want to reset it every x period.

Hi, thank you for your suggestion, but if I understand utility meter well, you only can make splits based on time periods. I want to make a split based on values. So if the consumption during one hour is less than 1 kWh, I consider it as heating/cooling; else tapwater.
So the utility meter won’t work.

No, that is just an example. you decide when to change the tariff. I have one splitting gas in shower, heating and other based on when the shower is running, the heating system is on or neither (which is likely tap water other than the shower). Simply use another trigger for the automation in the example in the documentation.

Hi, thank you for your suggestion, but in my situation I cannot use/don’t have other triggers than the value itself. Do you have a solution for this?

I assume you have a power sensor as well?

Based on that power sensor you can change the select entity which indicates the tariff for the utility meters. It will be more accurate that using hourly kWh values, as it could be that a short period of that hour was used for the heatpump, still keeping the hourly value below 1 kWh.

As there are many fluctuations in the power consumption, I have concluded that using the actual power is not a reliable way of measuring. So I insist in finding an answer on my question :wink:

Then you can create a trigger based template sensor which triggers every hour
Then in the action section use the recorder.get_statistics action to get the data from the past hour (or you can use an hourly utility meter sensor and use the last_period attribute)

Under that trigger (and action section) you define 2 sensors. Based on the energy usage of the last hour you add the value of the last hour to the first or to the second sensor.

I’d look into adding physical sensors that tell you what the heatpump is doing. I do this with my furnace to split out domestic hot water from zone heating, How to do it depends on your equipment.

You are correct, I have power sensors and I think I should use these. I have create below code, but it still doesn’t work correct. What am I doing wrong?

template:
  - sensor:

      # Tapwater energy: only counts when wp_power < 500 W
      - name: "tapwater_energy"
        unique_id: tapwater_energy_template
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total_increasing
        # Use 0 when condition is false so Utility Meter does not increase
        state: >
          {% if states('sensor.wp_power')|float(0) < 500 %}
            {{ states('sensor.wp_energy_delivered') }}
          {% else %}
            0
          {% endif %}

      # Verwarming energy: counts when wp_power >= 500 W
      - name: "verwarming_energy"
        unique_id: verwarming_energy_template
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total_increasing
        state: >
          {% if states('sensor.wp_power')|float(0) >= 500 %}
            {{ states('sensor.wp_energy_delivered') }}
          {% else %}
            0
          {% endif %}

utility_meter:
  tapwater_energy_daily:
    source: sensor.tapwater_energy
    cycle: daily

  tapwater_energy_monthly:
    source: sensor.tapwater_energy
    cycle: monthly

  verwarming_energy_daily:
    source: sensor.verwarming_energy
    cycle: daily

  verwarming_energy_monthly:
    source: sensor.verwarming_energy
    cycle: monthly

That’s not what I meant.
Create a utility meter with 2 tariffs (tapwater and verwarming)
The integration will then automatically create a select entity which you can use to toggle between these two “tariffs”

Use the state of the power sensor to set the select entity to the right state. The utlity meter integration will then increase the sensor based on the state of the select entity.

I’m really sorry… would you please create the Yaml code so that I understand better what I exactly need to do? In the tutorials I see I can create a Utility meter, but also need an automation, but if I understand you well you can do everything in the Utility meter. Thank you ! This will help a lot of Daikin heatpump users.

Just set it up through the UI, no yaml needed.

What I have done: created in Devices → Helpers a Helper “Utility meter”.
I have now 3 helpers: Name / Entity ID / Type
Heatpump / select.heatpump / Utility Meter
Heatpump Tapwater / sensor.heatpump_tapwater / Utility Meter
Heatpump Verwarming / sensor.heatpump_verwarming / Utility Meter

When I select select.heatpump, I can configure the following options:
Name (empty)
Icon
Entity ID (select.heatpump)
Add label (empty)
Utility Meter options →
— Input sensor (Warmtepomp; this is the power meter)
— Periodically resetting = on
— sensor always availalbe = on

Where to configure the split?

Unfortunately for beginners like me configuring this is less obvious than it seems to be.

You make an automation that changes the select based on whatever times/stipulations you want

Not completely sure what your options are for the select, but your automation should be something like this

triggers:
  - trigger: numeric_state
    entity_id: sensor.wp_power
    above: 500
    id: Verwarming # make sure this matches the option from the select dropdown for verwarming
  - trigger: numeric_state
    entity_id: sensor.wp_power
    below: 500
    id: Tapwater # make sure this matches the option from the select dropdown for tapwater
actions:
  - action: select.select_option
    target:
      entity_id: select.heatpump
    data:
      option: "{{ trigger.id }}"

If you want to avoid Jinja templates (the stuff with the {{ and }}) you can do this:

triggers:
  - trigger: numeric_state
    entity_id: sensor.wp_power
    above: 500
    id: Verwarming # make sure this matches the option from the select dropdown for verwarming
  - trigger: numeric_state
    entity_id: sensor.wp_power
    below: 500
    id: Tapwater # make sure this matches the option from the select dropdown for tapwater
actions:
  - if:
      - condition: trigger
        id: Verwarming # make sure this matches the option from the select dropdown for verwarming
    then:
      - action: select.select_option
        target:
          entity_id: select.heatpump
        data:
          option: Verwarming # make sure this matches the option from the select dropdown for verwarming
    else:
      - action: select.select_option
        target:
          entity_id: select.heatpump
        data:
          option: Tapwater # make sure this matches the option from the select dropdown for tapwater

Note that you won’t be able to test this automation by pressing the RUN button in the GUI, as there will be no trigger. If you want to test if it works, you can change the state of sensor.wp_power in Developer Tools > States. Also note that you have to change it so it crosses the threshold, so if it is currently below 500, you need to change it to something above 500 for the automation to trigger (or vice versa). The changed state will automatically be corrected when the sensors gets an update from the integration.

Hi, I have created the automation you suggested. I made a mistake in my request: >500W = tapwater, <500W = verwarming, so I added below automation in automations.yaml using Studio Code Server:

- id: '123452135311'
  triggers:
  - trigger: numeric_state
    entity_id: sensor.wp_power
    below: 500
    id: Verwarming # make sure this matches the option from the select dropdown for verwarming
  - trigger: numeric_state
    entity_id: sensor.wp_power
    above: 500
    id: Tapwater # make sure this matches the option from the select dropdown for tapwater
  actions:
    - if:
        - condition: trigger
          id: Verwarming # make sure this matches the option from the select dropdown for verwarming
      then:
        - action: select.select_option
          target:
            entity_id: select.heatpump
          data:
            option: Verwarming # make sure this matches the option from the select dropdown for verwarming
      else:
        - action: select.select_option
          target:
            entity_id: select.heatpump
          data:
            option: Tapwater # make sure this matches the option from the select dropdown for tapwater

After restarting HA, I see the Tapwater value is being updated, while the wp_power only is 15W. I see this after moving my cursor above sensor wp_power.
When I move my cursor above select.heatpump, the value is Tapwater, with possible options Verwarming and Tapwater.
I also see the sensor.heatpump_tapwater is being updated, and not sensor.heatpump_verwarming which I expect.
What the #### is going wrong here?

That’s because for the automation to trigger, it has to cross the threshold. So it has to go from above 500 to below 500.
As that didn’t happen yet, you need to manually change the state of the select entity (or just heat up some water so it goes above 500)

1 Like

You are correct. It is working fine now.
Thanks for the great help!

But… I also want to get of this error after startup. Do you also know a solution for this?

Which error?