# Mes stats ne survivent pas au reboot

**URL:** <https://forum.hacf.fr/t/mes-stats-ne-survivent-pas-au-reboot/61606>\
**Category:** Entraide Home Assistant\
**Tags:** aide\
**Created:** [Avril 22, 2025, 3:40 UTC](https://forum.hacf.fr/t/mes-stats-ne-survivent-pas-au-reboot/61606 "2025-04-22T15:40:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bentou](https://forum.hacf.fr/user_avatar/forum.hacf.fr/bentou/32/13874_2.png) [@bentou](https://forum.hacf.fr/u/bentou)\
**Post date:** [Avril 22, 2025, 3:40 UTC](https://forum.hacf.fr/t/mes-stats-ne-survivent-pas-au-reboot/61606/1 "2025-04-22T15:40:40Z")

</div>

Bonjour,

j'ai un petit souci de compteur

j'ai suivi le post [Obtenir le temps d'utilisation d'un appareil électrique sur une période donnée](https://forum.hacf.fr/t/obtenir-le-temps-dutilisation-dun-appareil-electrique-sur-une-periode-donnee/18130) de Syl20 pour quantifier l'utilisation de la Télé par mes ados "qui la regardent jamais"

templates.yaml

```auto
######### For Cumul TV on ######################################################
- sensor:
      - name: temps_tv_today
        device_class: duration
        state: "{% set hours = states('sensor.temps_allumage_tv_today') | float %} 
        {% set minutes = ((hours % 1) * 60) | int %}
        {{ '%02ih %02im'%(hours // 1, minutes) }}"
        #friendly_name: temps_tv_today
        unique_id: "ui_temps_tv_today"
      - name: temps_tv_hier
        device_class: duration
        state: "{% set hours = states('sensor.temps_allumage_tv_hier') | float %} 
        {% set minutes = ((hours % 1) * 60) | int %}
        {{ '%02ih %02im'%(hours // 1, minutes) }}"
        #friendly_name: temps_tv_hier
        unique_id: "ui_temps_tv_hier"
      - name: temps_tv_semaine
        device_class: duration
        state: "{% set hours = states('sensor.temps_allumage_tv_semaine') | float %} 
        {% set minutes = ((hours % 1) * 60) | int %}
        {{ '%02ih %02im'%(hours // 1, minutes) }}"
        #friendly_name: temps_tv_semaine
        unique_id: "ui_temps_tv_semaine"
      - name: temps_tv_mois
        device_class: duration
        state: "{% set hours = states('sensor.temps_allumage_tv_mois') | float %} 
        {% set minutes = ((hours % 1) * 60) | int %}
        {{ '%02ih %02im'%(hours // 1, minutes) }}"
        #friendly_name: temps_tv_mois
        unique_id: "ui_temps_tv_mois"
######### END Cumul TV on ######################################################

```

sensors.yaml

```auto
# For Cumul TV on ------------------------------
- platform: history_stats
  name: temps_allumage_tv_today
  entity_id: media_player.tv_tv_salon
  state: "idle"
  type: time
  start: "{{ now().replace(hour=0, minute=0, second=0, microsecond=0) }}"
  end: "{{ now() }}"

- platform: history_stats
  name: temps_allumage_tv_hier
  entity_id: media_player.tv_tv_salon
  state: "idle"
  type: time
  end: "{{ now().replace(hour=0, minute=0, second=0, microsecond=0) }}"
  duration:
    hours: 24

- platform: history_stats
  name: temps_allumage_tv_semaine
  entity_id: media_player.tv_tv_salon
  state: "idle"
  type: time
  start: "{{ as_timestamp( now().replace(hour=0, minute=0, second=0, microsecond=0) ) - now().weekday() * 86400 }}"
  end: "{{ now() }}"

- platform: history_stats
  name: temps_allumage_tv_mois
  entity_id: media_player.tv_tv_salon
  state: "idle"
  type: time
  start: "{{ now().replace(day=1, hour=0, minute=0, second=0, microsecond=0 ) }}"
  end: "{{ now() }}"
# END Cumul TV on ------------------------------

```

 ![image](https://forum.hacf.fr/uploads/default/original/3X/f/8/f8908382f2b11690609c17339d00b63a3b09ed5f.png)  
 ![image](https://forum.hacf.fr/uploads/default/original/3X/3/f/3fc3e5efc518fb8d56bf131c55c7464a18c0d9c0.png)

et quand je reboote:  
tout est à zéro...

 ![image](https://forum.hacf.fr/uploads/default/original/3X/2/5/2513805ed601da99dcff3b2842e420b6a43be662.png)

qu'est ce qui va pas ???

---

<div class="post-metadata">

**Author:** ![WarC0zes](https://forum.hacf.fr/user_avatar/forum.hacf.fr/warc0zes/32/137471_2.png) [@WarC0zes](https://forum.hacf.fr/u/WarC0zes)\
**Post date:** [Avril 22, 2025, 4:06 UTC](https://forum.hacf.fr/t/mes-stats-ne-survivent-pas-au-reboot/61606/2 "2025-04-22T16:06:10Z")

</div>

Salut,  
je n'est pas remarqué ce problème. Par contre, je suis en version 2025.4.2 du core.

```yaml
  - platform: history_stats
    name: Temps Allumage Ordinateur
    unique_id: "temps_allumage_ordinateur"
    entity_id: sensor.ordinateur_en_fonctionnement
    state: 'on'
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0, microsecond=0) }}"
    end: "{{ now() }}"

  - platform: history_stats
    name: Temps Allumage Télévision
    unique_id: "temps_allumage_television"
    entity_id: sensor.television_en_fonctionnement
    state: 'on'
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0, microsecond=0) }}"
    end: "{{ now() }}"

  - platform: history_stats
    name: Temps Allumage Frigo
    unique_id: "temps_allumage_frigo"
    entity_id: sensor.frigo_en_fonctionnement
    state: 'on'
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0, microsecond=0) }}"
    end: "{{ now() }}"

```

 ![image](https://forum.hacf.fr/uploads/default/original/3X/d/2/d28fdb5c1fb171670c9ab43a76030e3b69b24200.png)

 ![image](https://forum.hacf.fr/uploads/default/original/3X/2/0/20caf2e83ba093c040caa5de6537265c8f3a9dc9.png)  
 ![image](https://forum.hacf.fr/uploads/default/original/3X/8/c/8c12c3c5820a3be9d819f49cfbbd1dc520b864db.png)
