Calculate Time of a Switch in a certain state

Based on the example you provided, it can in fact run the next day, before sunrise. It blurs the definition of ‘daily’. Nevertheless, I do agree that, given the way it works and the possibility of certain events occurring right up to midnight, it can’t backfill the remaining hours with a time machine so it’s obligated to run the following day (in the wee hours).

So if no one uses the pool and there’s no heating, it would start does its 8-hour run, eight prior to sunrise (in other words, a few hours before midnight). Is that correct?

It’s an interesting technique to flexibility schedule the pump’s run-time and I’m simply trying to understand how and when it does its magic.

For me I meant daily as from sunrise today, to sunrise tomorrow morning, sorry to confuse.

Yes

1 Like

How can I reset History Stats sensor to “0” at midnight?

It already does that, that’s what start does.

Mine goes over 8HRs incrementally. That’s the point, it doesn’t reset. Config - exactly as you provided, Petro.

It will go over 8 hours incrementally, it’s tabulating the hours that the device has been on since midnight. What’s the value after midnight?

The switch doesn’t turn off after 8 HRs either. Automation is exactly like you suggested.
After midnight the hours counter just increases.

Are there errors in your logs, the fact that it doesn’t trigger shows me that you’ve done something wrong in the copy of the configuration. Can you please post your logs and the configuration you’ve used.

There is no single line in the logs for the sensor that counts hours, unfortunately.

Heres my config:

  - platform: history_stats
    name: Swimpool Filtration ON
    entity_id: switch.swimpool_filtration
    state: "on"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"

And Automation:

alias: Swimpool Filtration
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.swimpool_filtration_on
    above: '8'
condition: []
action:
  - service: switch.turn_off
    target:
      entity_id: switch.swimpool_filtration
mode: single

1 Like

Sorry to bump up this article but can the history stats config above be used to track the time a sensor gives a negative value throughout the day, a “state: negative”?

It seems it is only valid for fixed states, but you can create a template binary_sensor that is true when your sensor is < 0, then use that new binary sensor in the history stats