Point of post: To answer the question “Is there something wrong deep within Home Assistant, some protections that can be added, or am I just doing something dumb?”
I’ve got an automation or automation/integration combo that appears to send Home Assistant into a difficult to recover from cycle of restarts.
Integration:
Automation:
alias: Update OpenUV
description: ""
trigger:
- platform: time_pattern
minutes: /10
condition:
- condition: sun
after: sunrise
before: sunset
before_offset: "+00:45:00"
- condition: template
value_template: >-
{% set updates_per_day = 30 %}
{% set automation_last_triggered = state_attr('automation.update_openuv',
'last_triggered') %}
{% set next_setting_as_today = state_attr("sun.sun", "next_setting") |
as_timestamp | timestamp_custom("%H:%M") | today_at %}
{% set next_rising_as_today = state_attr("sun.sun", "next_rising") |
as_timestamp | timestamp_custom("%H:%M") | today_at %}
{% set hours_to_update = (next_setting_as_today - next_rising_as_today) |
today_at | as_timestamp | timestamp_custom("%H") | int + 1 %}
{% set updates_per_hour = updates_per_day / hours_to_update %}
{% set minutes_per_update = (60 / updates_per_hour) | int + 1 %}
{{
automation_last_triggered == None
or (
now() - state_attr('automation.update_openuv', 'last_triggered')
) >= timedelta(hours = 0, minutes = minutes_per_update)
}}
action:
- service: homeassistant.update_entity
target:
entity_id:
- sensor.openuv_current_uv_index
data: {}
mode: single
Causes this:
Well, when I was able to finally disable the script and rebooted numerous times the above history settled down. No other changes made aside from disable and reset (after having had to do this multiple times while debugging, I narrowed it down to this).
The above script is similar to the one in the docs, except that it attempts to approximate the length of the current day’s daylight hours and split up the quota to fit within that timespan. This is different from the example in the docs which takes the longest daylight hours and uses that throughout the year.
Aside from restarting the Home Assistant server every 10 minutes (at the beginning) and then every 2 minutes at its most frequent, there are a number of factors which make this difficult to recover from.
Disabling the Integration doesn’t stop the restarts.
When the server comes back up, simply disabling the automation doesn’t work. It appears to be disabled, but then the server restarts and the automation is enabled again.
I think the way to get around this is to disable the automation and then quickly “Shut down the server” from the restart menu options. It hasn’t worked first time for me and I’ve repeated it in order to get the timing right.
Disabling parts of the automation does stay set between resets, but doesn’t prevent the next server restart from happening.
Another compounding factor is that every time the server restarts it uses up 1 more of the quota. When the quote has been used the entities are no longer considered to be provided by the Integration. So this results in additional errors in the automation where it says that it can’t update “sensor.openuv_current_uv_index” because it doesn’t exist. I don’t think this contributes to the above issue since the quota resets every day and there will be a period of time where the entity does exist.
I haven’t counted (or checked the quota) to know if the drop from 10 minutes restarts to 2 minute restarts is related to the entity no longer existing.
In the action I tried automation_last_triggered
as a variable and inline to see if there was a difference and both caused server restarts.
I wouldn’t have expected this automation to have such a profound impact on the server.
Is there something wrong deep within Home Assistant, some protections that can be added, or am I just doing something dumb?