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