Need help with history_stats after update

Prior to 2022.5 I had an automation that told me how long the heating had run for that day.

alias: Heating Runtime Notification
description: ''
trigger:
  - platform: time
    at: '23:59'
condition:
  - condition: numeric_state
    entity_id: sensor.heating_run_time_today
    above: '0'
action:
  - service: notify.tg_house_group
    data:
      title: Heating Runtime Notification
      message: >-
        Heating runtime today: {{
        state_attr('sensor.heating_run_time_today','value') }}
mode: single

This doesn’t work after the update - because the value attribute has been removed.
Does anyone have any Jinja code I can use to convert the state of this sensor back to a hh:mm format ?

 - platform: history_stats
   name: Heating Run Time Today
   entity_id: switch.house_boiler
   state: "on"
   type: time
   start: "{{ now().replace(hour=0,minute=0,second=0) }}"
   end: "{{ now() }}"

Could this help?

1 Like

It explains why value was removed - but the only example code in there, converts the value to minutes. I need some code to get hours and minutes. Thanks for the pointer though.

{{ (timedelta(hours=states('sensor.heating_run_time_today') | float(0)) | string)[:-3] }}
2 Likes

Thank you, I knew one of the experts would be able to solve that.

In case anyone else is after something similar - my automation now looks like this:

alias: Heating Runtime Notification
description: ''
trigger:
  - platform: time
    at: '23:59'
condition: []
action:
  - if:
      - condition: numeric_state
        entity_id: sensor.heating_run_time_today
        above: '0'
    then:
      - service: notify.tg_house_group
        data:
          title: Heating Runtime Notification
          message: >-
            {% set x = (timedelta(hours=states('sensor.heating_run_time_today')
            | float(0)) | string)[:-3] %} {% set t = x.split(":") %} {% set h =
            t[0] %} {% set m = t[1] %} Heating runtime today: {{ h }}h{{ m }}m
    else:
      - service: notify.tg_house_group
        data:
          title: Heating Runtime Notification
          message: 'Heating runtime today: NONE'
mode: single
1 Like