Trying to track the number of hours a certain temperature threshold is exceeded

Modify your History Stats Sensor to record from the start of the day (midnight) to the current time. The today_at() filter reports the start of the day.

- platform: history_stats
  name: "High Temperature Hours"
  entity_id: binary_sensor.high_temperature_alert_binary
  state: "on"
  type: time
  start: "{{ today_at() }}"
  end: "{{ now() }}"

This will now report the number of high temperature hours for the current day. To accumulate this value on a daily/weekly/monthly/yearly basis, use the Utility Meter integration. It stores its data in a separate table in the database that is exempt from purging and meant for long-term storage.

There’s an example here:

2 Likes