Counter For Long Running Usage Time?

I have a CO2 laser and I use an ESP32 running ESPHome to track coolant and ambient temperature, logging to HA as well as displaying on an OLED screen. The laser tubes are a consumable product and generally have a range of expected hours that they should last. What I would like to do is use HA+ESPHome to track the cumulative number of hours of laser time for 2+ years. Expanding the database to track 2+ years doesn’t seem like a viable option. The laser has an air assist pump that runs on 12V. I am going to use an ADC or digital sensor either with a current sensor, or just a voltage divider so the ESPHome can track when the air assist is on. I was thinking that maybe a counter with restore=true might be a good way to keep track of this total laser time over an extended period of time. What I can’t figure out is the best way to make it increment. Maybe an automation that fired once for every 10 seconds the sensor is high and either increments by 10. This seems like it would give me a pretty good estimation of total run time since the laser itself doesn’t track this.

I’ve looked but haven’t been able to find any examples of this. Would this be a good way to track this over a long period and does anyone have any examples?

Doesn’t the life also depend on the % power the laser is run at as well as the hours?

Either way, you could increment a global variable depending on the air pump state

  - id: laser_seconds
    type: int
    restore_value: yes # never lose your total

  - platform: gpio
    pin: 16
    name: "Air Pump"
    id: air_pump
    device_class: running
  - interval: 1s
      - if: 
            lambda: 'return id(air_pump).state;'
            - lambda: |-
                id(laser_seconds) += 1; # increment seconds every second.
  - platform: template
    name: "Laser Hours"
    unit_of_measurement: 'hrs'
    lambda: |-
      return id(laser_seconds).state / 3600;
    update_interval: 60s # 0.01 hrs = 36 seconds so no need to update faster than this

Thank you, I think this makes sense and I will give it a try today.

Yes, it does depend on the power that the laser is run at. I am mostly cutting so usually running around 100%. I’m also just looking to get a rough estimate to see if I’m getting anywhere near the estimated lifetime. This is only a hobby so it isn’t critical, mostly I’m curious.