Best way to count how many hours a day the climate entity is in heating mode

Hi everyone. I’m trying to create a sensor that counts how many the Ecobee is in heating mode. Here’s the Ecobee climate entity:

When in heating mode, the havc_action changes to heating from idle. My current thought is to create a binary template sensor that turns true with state_attr('climate.lvrm_ecobee', 'hvac_action') == 'heating', and create a statistic integration to count how many hours the binary sensor is true each day.

Just wonder if anyone has a better way of doing that. It would be nice if statistic can be used on attributes, yet I haven’t found a way for that.

Thanks!

Your description is how I do it.

- platform: history_stats
  name: Heating Hours Today
  entity_id: binary_sensor.heating_on
  state: 'on' 
  type: time
  start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
  end: '{{ now() }}'

Yes that’s what I’m doing now. It’s just that I’m looking for a way to collect statistics right from the attribute. If that’s not possible I’m also fine with an extra entity.