Daily total - More reliable method?

I don’t know why, but I keep having issues with my automation that sums the hourly runtimes I get from my PLC controller. It was working fine today until I rebooted my HA to add a trusted network.

Every hour this automation should run. If I use the automation troubleshooting toll in the Supervisor, It looks like it is running each hour, but the values are not updating. I don’t think these are candidates for the history sensor as the values reset to zero by my PLC each hour. I also pasted the individual sensors into the Developer Tools - template and proved the sensors all have data.

Is there a better/more reliable method to accomplish this? Thank you in advance.

alias: update daily runtime values
id: 5e31c463-e485-45ed-b173-38e0004ba403
initial_state: true
trigger:
  platform: time_pattern
  hours: '*'
  minutes: '59'
  seconds: '40'
action:
  - service: input_number.set_value
    data_template:
      entity_id: input_number.sump_pump_daily_runtime
      value: |-
        {%- if (now().hour == 23 ) -%}
          0
        {%- else -%}
          {{ states('sensor.current_hour_runtime')|float + states('input_number.sump_pump_daily_runtime')|float }}
        {%- endif -%}
  - service: mqtt.publish
    data_template:
      topic: home_assistant/sump_pump_daily_runtime
      payload: |-
        {%- if (now().hour == 23 ) -%}
          0
        {%- else -%}
          {{ states('sensor.current_hour_runtime')|float + states('input_number.sump_pump_daily_runtime')|float }}
        {%- endif -%}
      retain: true
  - service: input_number.set_value
    data_template:
      entity_id: input_number.hvac_daily_runtime
      value: |-
        {%- if (now().hour == 23 ) -%}
          0
        {%- else -%}
          {{ states('sensor.HVAC_Current_Hour_Runtime')|float + states('input_number.hvac_daily_runtime')|float }}
        {%- endif -%}
  - service: mqtt.publish
    data_template:
      topic: home_assistant/hvac_daily_runtime
      payload: |-
        {%- if (now().hour == 23 ) -%}
          0
        {%- else -%}
          {{ states('sensor.HVAC_Current_Hour_Runtime')|float + states('input_number.hvac_daily_runtime')|float }}
        {%- endif -%}
      retain: true
  - service: input_number.set_value
    data_template:
      entity_id: input_number.water_usage_yesterday
      value: |-
        {%- if (now().hour == 23 ) -%}
          {{ states('sensor.flume_sensor_jane_ln_current_day') }}
        {%- else -%}
          {{ states('input_number.water_usage_yesterday') }}
        {%- endif -%}
  - service: mqtt.publish
    data_template:
      topic: home_assistant/water_usage_yesterday
      payload: |-
        {%- if (now().hour == 23 ) -%}
          {{ states('sensor.flume_sensor_jane_ln_current_day') }}
        {%- else -%}
          {{ states('input_number.water_usage_yesterday') }}
        {%- endif -%}
      retain: true
  - service: input_number.set_value
    data_template:
      entity_id: input_number.yesterdaykwh
      value: |-
        {%- if (now().hour == 23 ) -%}
          {{ states('sensor.daily_energy') }}
        {%- else -%}
          {{ states('input_number.yesterdaykwh') }}
        {%- endif -%}
  - service: mqtt.publish
    data_template:
      topic: home_assistant/kwh_yesterday
      payload: |-
        {%- if (now().hour == 23 ) -%}
          {{ states('sensor.daily_energy') }}
        {%- else -%}
          {{ states('input_number.yesterdaykwh') }}
        {%- endif -%}
      retain: true

You don’t sound sure; is it or is it not triggering at 20 seconds before every hour?

Do you mean you are examining the automation’s trace in Configuration > Automations?

Yes, Logbook shows the automation triggering every hour.

The trace shows it actually ran properly last hour and updated the daily runtime for the one sensor as it should.

I just can’t figure out why it doesn’t always execute properly.

The automation continues to run hourly and execute properly. I’m not sure why it wouldn’t update values for the five hours after I restarted HA yesterday, but appears to be working fine now.

As I stated before, if anyone has a better idea how to perform this hourly update, I would appreciate hearing about it.