History stats - sensor not found

Hi

I want to get the number of hours a valve is in heating. Looks like i cant do it directly with history stats, so the solution is to create a template for that state

I have created this in my configuration.yaml

template:
  - binary_sensor:
      - name: "BT estudio heating"
        unique_id: bt_estudio_heating
        state: >
          {{ state_attr('climate.bt_estudio', 'hvac_action') == 'heating' }}
          
sensor:
  - platform: history_stats
    name: "BT Estudio heating today"
    entity_id: binary_sensor.bt_estudio_heating
    state: "on"
    type: time
    start: >
      {{ now().replace(hour=0, minute=0, second=0, microsecond=0) }}
    end: >
      {{ now() }}

All the yaml seem to be ok, it reloads correctly, but when trying to create an entity card

type: entities
title: Heating today
entities:
  - entity: sensor.bt_estudio_heating_today
    name: Estudio

That entity is not found

Any idea what am i doing wrong?

Thanks

If that’s your first history stats, you need to fully restart HA after adding the yaml.

1 Like