Thank you very much for this, I know this will solve all my timer when I get it working, but I have been scratching my head for a few days. Added input_text, 2x automations and the pythonscript, after enabling a test timer for 30 minutes and restart HA via configuration > Server Controls > Server Management > restart, but the timer came back as idle. I would say out of 10 restart there maybe 1 time the timer will be resume okay, so that proved all scripts and yaml were added correctly.
Does anyone encounter such problem ?
Things I have tried and noticed:
-
after timer enabled and counting down, checked input_timer.active_timers state do indicate “test_timer 1595269963”. the state is registered, so the 1st automation work
-
with HA logger default set to “info”, reboot system and home-assistant.log show
2020-07-20 10:41:52 INFO (SyncWorker_0) [homeassistant.components.python_script] Executing active_timers_resume.py: {}
so the 2nd automation also work and called the pythonscript
-
I added couple logger.info line to the pythonscript to see if it read the value back correctly and here are some clue
When timer didn’t resume
2020-07-20 11:13:59 INFO (MainThread) [homeassistant.setup] Setting up python_script
2020-07-20 11:14:01 INFO (MainThread) [homeassistant.setup] Setup of domain python_script took 2.2 seconds.
2020-07-20 11:14:24 INFO (SyncWorker_2) [homeassistant.components.python_script] Executing active_timers_resume.py: {}
2020-07-20 11:14:24 INFO (SyncWorker_2) [homeassistant.components.python_script.active_timers_resume.py] active timers resume script ran
2020-07-20 11:14:24 INFO (SyncWorker_2) [homeassistant.components.python_script.active_timers_resume.py] ts= <state input_text.active_timers=; editable=False, min=0, max=255, pattern=None, mode=text, friendly_name=Active Timers @ 2020-07-20T11:14:02.986849-07:00>
Timer resumed correctly
2020-07-20 11:42:54 INFO (MainThread) [homeassistant.setup] Setting up python_script
2020-07-20 11:42:57 INFO (MainThread) [homeassistant.setup] Setup of domain python_script took 2.6 seconds.
2020-07-20 11:43:19 INFO (SyncWorker_0) [homeassistant.components.python_script] Executing active_timers_resume.py: {}
2020-07-20 11:43:19 INFO (SyncWorker_0) [homeassistant.components.python_script.active_timers_resume.py] active timers resume script ran
2020-07-20 11:43:19 INFO (SyncWorker_0) [homeassistant.components.python_script.active_timers_resume.py] ts= <state input_text.active_timers=test_timer 1595270700; editable=False, min=0, max=255, pattern=None, mode=text, friendly_name=Active Timers @ 2020-07-20T11:42:58.526629-07:00>
2020-07-20 11:43:19 INFO (SyncWorker_0) [homeassistant.components.python_script.active_timers_resume.py] timers= ['test_timer 1595270700']
2020-07-20 11:43:19 INFO (SyncWorker_0) [homeassistant.components.python_script.active_timers_resume.py] duration= 101
so seems like even the input_text.active_timers show the value in the developer tools > states, it is not saved properly. Thus, upon bootup, the script read an empty state, which caused the timer not to resume. And when the state were saved, it will read back properly and resume correctly.
-
Look into HA database noticed input_text.active_timers change and update instantantly whenever the state of the timer is changed
SELECT * FROM "states" WHERE "domain" LIKE 'input_text' ORDER BY "last_changed" DESC
-
Look into file system /.storage/core.restore_state and I believe this is where the pythonscript is getting the states from. And within the input_text.active_timers section, the state was never updated immediately. It update the state in random period.
Base on what I have found, if the input_text.active_timers state wasn’t updated correctly witin the .core.restore_state file, the timer may not resume properly.
Is it my HA configuration problem that causing the core.restore_state file not updating as often ?