Hour Meter for Motors

I have not seen or read about tracking operating hours for electric motors. I have a swamp cooler automated to run on high and low depending on humidity and temp of the house. With this Id like to see stats for how many hours the swamp cooler has run on low, high and both combined. Does anyone have thoughts how i can pull switch data and convert it to something like an hour meter that can not get reset. Im still very green on coding and node red. This is going to be used for maintenance on the swamp cooler if i can keep track of the operating hours.

Its quite primitive, but I use counters to time my wash and drying times.
When the respective appliance is running, an automation increments the counter by one every minute.

Counter values are retained across restarts

Is this motor in home assistant already?

This will work up to as long as your keep_days logger setting.

@ jivesinger
This helped me greatly in thinking about this problem. I am stumped on the coding. Here is what I have.

counter:
  my_custom_counter:
    name: Swamp Cooler Low hours
    restore: true
    initial: 0
    step: 1

This does work but I’m not confident i have the format correct to capture the hours the motor has ran on low for the Low and high Entities. If i made another counter for High it would be the same format but a 2nd custom counter correct?

@ nickrout
yes the motor is in Home Assistant. Im using an esp32 running ESPHome that drives a relay for the pump and 2 contactors for low and high. Low and High are interlocked with delays set when switching from low to high and back.

@ tom_l

I believe this is solution. Here is what I have.

#  Swamp Cooler Hour Meter
#sensor:
  - platform: history_stats
    name: Swamp Cooler Low Hour Meter
    entity_id: switch.swamp_cooler_low
    state: 'on'
    type: time
    start: '{{ 0 }}'
    end: '{{ now() }}'
    
  - platform: history_stats
    name: Swamp Cooler High Hour Meter
    entity_id: switch.swamp_cooler_high
    state: 'on'
    type: time
    start: '{{ 0 }}'
    end: '{{ now() }}'

How do i get the entire history? Currently it shows the following run time which has to be more than ~12 hrs since its been running all summer.

Swamp cooler hrs

It’s showing about 5 days. How long is your logger history kept for?

@ tom_l

I have been reading and checking the following but am not sure where the keep_days log setting is located. Is this located in log book, logger or system log?

Recorder: https://www.home-assistant.io/integrations/recorder/#purge_keep_days

Sorry I shouldn’t use logger and recorder interchangeably. My fault.

Thank you! I updated my config below. Hopefully 365 is not too much data to store.

# Number of days to keep for Hour meter. 
recorder:
  purge_keep_days: 365
  include:
    entities:
      - sensor.swamp_cooler_high_hour_meter
      - sensor.swamp_cooler_low_hour_meter

Lastly is more detail needed for the Low and High Entity? I see this warning on Lovelace.

This entity does not have a unique ID, therefore its settings cannot be managed from the UI.

That means they are manually added sensors rather than discovered sensors. At this stage only discovered sensors can be managed from the UI.

You added them manually, thus you have to manage them manually (using yaml rather than the UI).

Got it. Thank you!

FYI: with those recorder includes you are not saving history for anything else.

So recorder stores all data and controls what history displays? Is that the right way to think of it.

If so I will move the included/excluded entities, domains, etc from history to recorder.

Has anyone seen issues setting recorder for 365 days other the possibility of slow performance.

It depends on how much you have to record. How big is your database now?

It’s much better (by a factor of 1/2 the size) than it used to be. bdraco has done some excellent optimisation in the last couple of releases.

The database file is sitting at 580MB as of today.

You can now add:

unique_id: your_unique_id_here

to your manually created entity in configuration.yaml to solve this problem

Since when?

Also if this is true be careful. This may have ramifications if you ever delete the sensor’s yaml. I just removed the id: key from all my manually created automations because of this: What the heck is up with not deleting my automations?

Under ‘Configuration Variables’

Not where, when. When was this introduced?

The documentation was 4 August https://github.com/home-assistant/home-assistant.io/pull/14052

1 Like