Weird thing with history stats reseting

Hi, still learning with HA, and with a lot of searches, I set up a history stat for knowing how much TV is viewed in a month, that’s an easy one. With that I get a value, but not in hours minute format, so I search for a template to convert that value.

It worked perfect but after some time, the counter doesn’t go on, it reset about a day or so of hours watched.

This is what I have set up:

- platform: history_stats
  name: TV ON
  entity_id: media_player.sony_bravia_tv
  state: "playing"
  type: time
  start: '{{ now().replace(day=1).replace(hour=0).replace(minute=0).replace(second=0) }}'
  end: '{{ now() }}'

- platform: template
  sensors:
    tv_on_days:
      friendly_name: "Horas TV mes"       
      value_template: "{{ state_attr('sensor.tv_on','value') }}"  

Thank you!

Someone who can help?

Thanks!

The sensor will only output what’s in the database. If you’re using a default setup, home assistant only stores 10 days of information. After 10 days, when a new days worth of data is added, it will chop off the oldest day. You’ll end up with a history graph that looks like this:

1 Like

That was it @petro, I figure it out later, looking for the recorder config.

Thank you as always.

1 Like