History Stats Help Please

Hi Guys

I am very new to HA and need some help please.

I need to see how long my irigation runs on certain sections of my garden, I have to switch the taps manually.

So I want the counter to start counting each time I turn on the borehole pump and then reset the timer to 0 when I switch it off.

Below is my current code but it does not zero after I switch it off.

  • platform: history_stats
    type: time
    name: Borehole On Time
    entity_id: switch.sonoff_1001f9cbc5
    state: “on”
    start: “{{now().replace(hour=0).replace(minute=0).replace(second=0) }}”
    end: “{{now()}}”

Your assistance will be much appreciated

Thank you

https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

Hi

Please explain reason for your reply as I believe there is nothing wrong with my post. I could not find a solution on another post.

This is unreadable. Please format it correctly so we can see the indentation. It is very important in YAML.

Thank you will do so shortly.

You have configured it to return the total number of hours the switch is on from midnight until the current time. As such, it will reset at midnight.

You will need to use the last_changed property in order to get the behavior you want.

...
start: "{{ states.switch.sonoff_1001f9cbc5.last_changed | default(now()) }}"
end: "{{ now() }}"
1 Like

Hi Didgeridrew

Thank you will try that now.