History_stats stopped working

I have a wyze motion sensor named wyzem02 and made a history_stats like below

  • platform: history_stats
    name: Wyze2Motion5m
    entity_id: binary_sensor.wyzem02
    state: “on”
    type: count
    end: “{{ now() }}”
    duration: 00:05:00

This entity Wyze2Motion5m records the number of times the motion sensor is “on” for the past 5 minutes.

It works perfect for long time, but suddenly it stopped working today after I pulled the latest home assistant container (Home Assistant Core 2022.5.3). When the motion sensor is triggered, it doesn’t change from 0 to 1. Anyone know what could be the issue in the latest HA container?
There is no error in log.

So this is an issue with your motion sensor not the History Stats integration?

Motion sensor triggered ok. But the history_stats Wyze2Motion5m didn’t change from 0 to 1.

Do you have any errors related to the recorder in your log?

Have you excluded the motion sensor from the recorder?

hate to hijack a thread, but i am having similar issues where i am not getting any data on history_stats sensors… I created a sensor to see if my AC was on heat or cool. here is what i have as that sensor sensor.

    - name: "HVAC Activity Upstairs"
      unique_id: ui_template_hvac_activity_upstairs
      state: > 
        '{{ state_attr("climate.upstairs_thermostat", "hvac_action") }}'

Looking at the developer tools, it is capturing the states as either ‘idle’, ‘heating’, or ‘cooling’:

I also looked at the history for it and i see it is capturing data:

i then created the daily sensors for ‘heating’ and ‘cooling’ as below:

# Thermostat Day
  - platform: history_stats
    name: Thermostat Heating Today Upstairs
    entity_id: sensor.hvac_activity_upstairs
    state: 'heating'
    type: time
    start: '{{ now().replace(hour=0, minute=0, second=0) }}'
    end: '{{ now() }}'

  - platform: history_stats
    name: Thermostat Cooling Today Upstairs
    entity_id: sensor.hvac_activity_upstairs
    state: 'cooling'
    type: time
    start: '{{ now().replace(hour=0, minute=0, second=0) }}'
    end: '{{ now() }}'

they always show 0.0 on the stats, i would expect them to be showing some rolling total throughout the day. I am sure i am missing something on my end, but i can’t figure out what it is.

Looks like there might be an issue. Could you folks please add your configurations (correctly formatted) to this:

1 Like

I don’t think so, look at his states, they have quotes. There shouldn’t be quotes.

Normal string states do not have quotes inside the state. It’s just the word.


Oh. Good eyes.

@sebby This:

      state: > 
        '{{ state_attr("climate.upstairs_thermostat", "hvac_action") }}'

Should be:

      state: > 
         {{ state_attr("climate.upstairs_thermostat", "hvac_action") }} 

Quotes outside the template are only required when using single line templates, like this:

      state: '{{ state_attr("climate.upstairs_thermostat", "hvac_action") }}'
1 Like

No I didn’t see any errors from the log. Also it is not excluded from recorder.
It was working fine for more than 1 year. It stopped working since I did the update of the latest container. No change on the configuration.

post a screenshot of your binary sensor in developer tools → states page. You have @sebby have different issues.

Here is the screenshot for the motion sensor.

can you post a screenshot of it in the table below, not in the set state box

@petro & @tom_l thank you!!! you guys are amazing, really appreciate all you do!

ok here it is

Based on your current configuration and the screenshots, it should be working. Are you positive it’s not working? It’s only looking at the last 5 minutes. The only other suggestion I could see causing the problem is that your duration is not in quotes.

After further checking carefully, I found that it is actually working but with delay on the updating Wyze2Motion5m.

Here are the trigger entries on the motion sensor:

Cleared (no motion detected)
8:46:16 AM - 8 seconds ago

Detected motion
8:45:34 AM - 1 minute ago

Cleared (no motion detected)
8:43:11 AM - 3 minutes ago

Detected motion
8:42:29 AM - 4 minutes ago

Below is the history graph on Wyze2Motion5m:

As can see there is delay about 40+ seconds.
I have same setup for two motion sensors, they all behave same (delay updating on the history_stats entities).

I have a similar problem, after updating to version 2022.5.3 history stats stopped counting

  - platform: history_stats
    name: Ogrzewanie dzisiaj Pompa
    entity_id: switch.pompa_ciepla_t06
    state: "on"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"

other similar entities in history stats are also silent

13.05.2022 - it’s working

Do you notice any delay on the history_stats entities?

Excuse me Guys
I try to do the same thing with my Netatmo Thermostat. Have the daily duration of heating mode.
I have

- platform: history_stats
  name: Thermostat Actif
  entity_id: sensor.statut_netatmo
  state: "heating"
  type: time
  start: "{{ now().replace(hour=0, minute=0, second=0) }}"
  end: "{{ now() }}"


- sensors:
    - name: "statut_netatmo"
      friendly_name: 'Statut Thermostat'
      unique_id: 9dd89288-41d4-46ca-acc5-d03e462ae987
      value_template: "{{ state_attr('climate.salon', 'hvac_action') }}"

And i have always

What’s wrong?
Is there a syntax problem?

Have you Restarted HA? Is recorder: in configuration.yaml?