Utility_meter based on energy Counter if switch is on

Hello Community,

i try to build an utility_meter who counts “kwh” from a Energy Counter (sensor.waermepumpe_total_kwh). But only if a Switch ist on. I have tried several Options but dont know how i can do this.

I Have a Heatpump for our home. For the Heatpump i have the Energy Counter “sensor.waermepumpe_total_kwh”. In the Summertime we use the Heatpump also for our Pool. There is a Switch “switch.hmw_io_12_sw14_dr_keller_1” who tells the Heatpump to heat the Pool. I need a Counter who counts the energy when this switch is on.

For the actual Power i have a working config:

  - platform: template
    sensors:
      poolheizung_aktuell_watt:
        friendly_name: "Poolheizung aktuell"
        unit_of_measurement: "W"
        value_template: >
          {% if is_state('switch.hmw_io_12_sw14_dr_keller_1', 'on') %}
            {{( states('sensor.waermepumpe_total_system_power') | int )}}
          {% else %}
            0.0
          {% endif %}

But i dont know how to do this with a utility_meter.

Thanks for help :slight_smile:

Thanks Tom.
I have seen that but i thinked it have the same Meter but two tariffs. But i want a etxra Meter. But it seems i can do it with this.