Operating hours/minutes for GPIO Output (relay / heater)

Hello,
How can I create an operating hours or operating minutes counter for a GPIO output. This should also be visible in HA.

sensor:    
  - platform: template              
    name: "Betriebsstunden Heizung 1"
    id: Betriebsstunden_Heizung_1

using something like

interval:
  - interval: 1min
    then:
      Betriebsstunden_Heizung_1 += 1

This History Stats - Home Assistant

My goal is to have these key figures available in the ESP32.

My solution now looks like this:

switch:
  - platform: gpio
    pin: 25
    id: heizstab_1
    name: 'Heizstab 1'
    restore_mode: ALWAYS_OFF 
    on_turn_on:
      while:
        condition:
          switch.is_on: heizstab_1
        then:
          - globals.set:
              id: global_Betriebsstunden_Heizung_1
              value: !lambda |-
                    return id(global_Betriebsstunden_Heizung_1) +1;
          - delay: 60s