History Stats sensor stopped working out of the blue

Hello all, I defined this entity to keep track of what percentage of the day a switch was turned on by an automation…

  - platform: history_stats
    name: NVR_FAN_Running_Percentage
    entity_id: switch.sonoff
    state: 'on'
    type: ratio
    end: '{{ now() }}'
    duration:
        days: 1

it worked like that for more that a year, but yesterday it started acting weird, instead of showing a percentage it shows a negative value for some seconds, and then refreshes and shows a very high value (almost 100%) for some other seconds, is not the same values all the time so I think is doing something… but I don’t know what.

I have several history stats running, and they are all borked. My TV has been on for -8hours and I’ve been in bed for 15 hours.

Anyone else getting odd results?

Same to me…after June update my history stats sensors are no longer reliable.
Hope it will be fixed soon.

I did a hard reset of the HA host and now it’s working… has been for the last 15 hours without problems, maybe you can try that. Also second Jun update just came out.

Same as I said to Roadkill, try a hard reset of host, that seems to have worked for me

That is terrible advice.

Performing a hard reset of the host (yanking the power) is a sure fire way to corrupt something and should only ever be an absolute last resort.

Use the Host Reboot option in the Settings > System > Hardware > 3 dots menu if a Host reboot is required.

Which it should only very rarely be. A Home Assistant restart is all that is required in 99% of cases. It can be found in the Settings > Top Right or Developer Tools > Yaml menus.

Thanks tom, I was looking for that for a while, before doing the hard reset, but couldn’t find it, I agree with you that is a bad idea to do it that way, but new interface made very difficult to find the host options, never thought it will be on that context menu… not being able to find it made me think it was removed and discouraged but I tried the HA reset twice and it didn’t work…

I didn’t know where it had moved to until recently either. I had to use the CLI.

I suspect it was made less obvious to prevent people confusing a reboot with a restart.