Closed VDRainer closed 4 years ago
I have been having a similar issue (Home Assistant won't restart). I suspected pyscript might be the culprit, but haven't been able to nail it down yet.
Could you try pyscript 0.30
instead of 0.31
? For 0.30
it only supports yaml
configuration.
Could this be related to issues I was discussing with @raman325 in the config-flow PR #39? See the comments over the last ~24 hours.
Also, please turn debugging on for pyscript
. Is there any log file output that mentions pyscript
on startup?
@craigbarratt , sorry, same behavior in 0.30.
Also, please turn debugging on for
pyscript
. Is there any log file output that mentionspyscript
on startup?
Sorry, forgot debugging. Will give it another try later, maybe tomorrow
Ok, thanks for confirming 0.30
has the same problem.
Is pyscript loading or running any scripts? The debug output should be helpful.
Ok, here's all about pyscript debug log from a HA start to restart.
2020-10-15 23:34:05 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for pyscript which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.
2020-10-15 23:34:22 INFO (SyncWorker_6) [homeassistant.loader] Loaded pyscript from custom_components.pyscript
2020-10-15 23:34:23 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for pyscript which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.
2020-10-15 23:34:23 INFO (MainThread) [homeassistant.bootstrap] Domains to be set up: {'waste_collection_schedule', 'pyscript', 'recorder', 'mqtt', 'zeroconf', 'automation', 'script', 'cover', 'broadlink', 'input_number', 'media_player', 'camera', 'switch', 'http', 'apcupsd', 'input_datetime', 'weather', 'panel_custom', 'scene', 'blitzortung', 'logger', 'websocket_api', 'ipp', 'system_health', 'device_automation', 'binary_sensor', 'config', 'utility_meter', 'shell_command', 'python_script', 'input_boolean', 'frontend', 'deconz', 'api', 'variable', 'modbus', 'image', 'speedtestdotnet', 'persistent_notification', 'zone', 'browser_mod', 'dwd_weather', 'onboarding', 'esphome', 'auth', 'group', 'hacs', 'tag', 'search', 'history', 'notify', 'mobile_app', 'kodi', 'input_select', 'tts', 'sensor', 'updater', 'system_log', 'logbook', 'map', 'lovelace', 'climate', 'person', 'sun', 'light', 'ios', 'device_tracker', 'stream', 'webhook', 'alert'}
2020-10-15 23:34:34 DEBUG (MainThread) [custom_components.pyscript.global_ctx] reading and parsing /home/homeassi/.homeassistant/pyscript/wz_desk_motion_light.py
2020-10-15 23:34:47 DEBUG (MainThread) [custom_components.pyscript] adding state changed listener and starting triggers
2020-10-15 23:34:47 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger file.wz_desk_motion_light.wz_desk_motion_light is active <Task pending name='Task-7759' coro=<Function.run_coro() running at /home/homeassi/.homeassistant/custom_components/pyscript/function.py:217>>
2020-10-15 23:34:47 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger file.wz_desk_motion_light.wz_desk_motion_light: watching vars {'binary_sensor.motion_group'}
2020-10-15 23:34:47 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger file.wz_desk_motion_light.wz_desk_motion_light waiting for state change or event
2020-10-15 23:35:10 DEBUG (MainThread) [custom_components.pyscript.state] state.update({'binary_sensor.motion_group': 'on', 'binary_sensor.motion_group.old': 'off'}, {'trigger_type': 'state', 'var_name': 'binary_sensor.motion_group', 'value': 'on', 'old_value': 'off'})
2020-10-15 23:35:10 DEBUG (MainThread) [custom_components.pyscript.state] notify_var_get var_names={'binary_sensor.motion_group'}, new_vars={'binary_sensor.motion_group': 'on', 'binary_sensor.motion_group.old': 'off'}, notify_vars={'binary_sensor.motion_group': 'on'}
2020-10-15 23:35:10 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger file.wz_desk_motion_light.wz_desk_motion_light got state trigger, running action (kwargs = {'trigger_type': 'state', 'var_name': 'binary_sensor.motion_group', 'value': 'on', 'old_value': 'off'})
2020-10-15 23:35:10 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger file.wz_desk_motion_light.wz_desk_motion_light waiting for state change or event
2020-10-15 23:35:10 DEBUG (MainThread) [custom_components.pyscript.eval] file.wz_desk_motion_light.wz_desk_motion_light: calling unique("wz_desk_motion_light", {})
2020-10-15 23:35:10 DEBUG (MainThread) [custom_components.pyscript.eval] file.wz_desk_motion_light.wz_desk_motion_light: calling sleep("180.0", {})
2020-10-15 23:35:11 DEBUG (MainThread) [custom_components.pyscript.state] state.update({'binary_sensor.motion_group': 'off', 'binary_sensor.motion_group.old': 'on'}, {'trigger_type': 'state', 'var_name': 'binary_sensor.motion_group', 'value': 'off', 'old_value': 'on'})
2020-10-15 23:35:11 DEBUG (MainThread) [custom_components.pyscript.state] notify_var_get var_names={'binary_sensor.motion_group'}, new_vars={'binary_sensor.motion_group': 'off', 'binary_sensor.motion_group.old': 'on'}, notify_vars={'binary_sensor.motion_group': 'off'}
2020-10-15 23:35:11 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger file.wz_desk_motion_light.wz_desk_motion_light got state trigger, but not active
2020-10-15 23:35:11 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger file.wz_desk_motion_light.wz_desk_motion_light waiting for state change or event
2020-10-15 23:35:22 DEBUG (MainThread) [custom_components.pyscript.state] state.update({'binary_sensor.motion_group': 'on', 'binary_sensor.motion_group.old': 'off'}, {'trigger_type': 'state', 'var_name': 'binary_sensor.motion_group', 'value': 'on', 'old_value': 'off'})
2020-10-15 23:35:22 DEBUG (MainThread) [custom_components.pyscript.state] notify_var_get var_names={'binary_sensor.motion_group'}, new_vars={'binary_sensor.motion_group': 'on', 'binary_sensor.motion_group.old': 'off'}, notify_vars={'binary_sensor.motion_group': 'on'}
2020-10-15 23:35:22 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger file.wz_desk_motion_light.wz_desk_motion_light got state trigger, running action (kwargs = {'trigger_type': 'state', 'var_name': 'binary_sensor.motion_group', 'value': 'on', 'old_value': 'off'})
2020-10-15 23:35:22 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger file.wz_desk_motion_light.wz_desk_motion_light waiting for state change or event
2020-10-15 23:35:22 DEBUG (MainThread) [custom_components.pyscript.eval] file.wz_desk_motion_light.wz_desk_motion_light: calling unique("wz_desk_motion_light", {})
2020-10-15 23:35:22 DEBUG (MainThread) [custom_components.pyscript.eval] file.wz_desk_motion_light.wz_desk_motion_light: calling sleep("180.0", {})
2020-10-15 23:35:23 DEBUG (MainThread) [custom_components.pyscript.state] state.update({'binary_sensor.motion_group': 'off', 'binary_sensor.motion_group.old': 'on'}, {'trigger_type': 'state', 'var_name': 'binary_sensor.motion_group', 'value': 'off', 'old_value': 'on'})
2020-10-15 23:35:23 DEBUG (MainThread) [custom_components.pyscript.state] notify_var_get var_names={'binary_sensor.motion_group'}, new_vars={'binary_sensor.motion_group': 'off', 'binary_sensor.motion_group.old': 'on'}, notify_vars={'binary_sensor.motion_group': 'off'}
2020-10-15 23:35:23 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger file.wz_desk_motion_light.wz_desk_motion_light got state trigger, but not active
2020-10-15 23:35:23 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger file.wz_desk_motion_light.wz_desk_motion_light waiting for state change or event
2020-10-15 23:35:31 DEBUG (MainThread) [custom_components.pyscript.state] state.update({'binary_sensor.motion_group': 'on', 'binary_sensor.motion_group.old': 'off'}, {'trigger_type': 'state', 'var_name': 'binary_sensor.motion_group', 'value': 'on', 'old_value': 'off'})
2020-10-15 23:35:31 DEBUG (MainThread) [custom_components.pyscript.state] notify_var_get var_names={'binary_sensor.motion_group'}, new_vars={'binary_sensor.motion_group': 'on', 'binary_sensor.motion_group.old': 'off'}, notify_vars={'binary_sensor.motion_group': 'on'}
2020-10-15 23:35:31 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger file.wz_desk_motion_light.wz_desk_motion_light got state trigger, running action (kwargs = {'trigger_type': 'state', 'var_name': 'binary_sensor.motion_group', 'value': 'on', 'old_value': 'off'})
2020-10-15 23:35:31 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger file.wz_desk_motion_light.wz_desk_motion_light waiting for state change or event
2020-10-15 23:35:31 DEBUG (MainThread) [custom_components.pyscript.eval] file.wz_desk_motion_light.wz_desk_motion_light: calling unique("wz_desk_motion_light", {})
2020-10-15 23:35:31 DEBUG (MainThread) [custom_components.pyscript.eval] file.wz_desk_motion_light.wz_desk_motion_light: calling sleep("180.0", {})
2020-10-15 23:35:33 DEBUG (MainThread) [custom_components.pyscript.state] state.update({'binary_sensor.motion_group': 'off', 'binary_sensor.motion_group.old': 'on'}, {'trigger_type': 'state', 'var_name': 'binary_sensor.motion_group', 'value': 'off', 'old_value': 'on'})
2020-10-15 23:35:33 DEBUG (MainThread) [custom_components.pyscript.state] notify_var_get var_names={'binary_sensor.motion_group'}, new_vars={'binary_sensor.motion_group': 'off', 'binary_sensor.motion_group.old': 'on'}, notify_vars={'binary_sensor.motion_group': 'off'}
2020-10-15 23:35:33 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger file.wz_desk_motion_light.wz_desk_motion_light got state trigger, but not active
2020-10-15 23:35:33 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger file.wz_desk_motion_light.wz_desk_motion_light waiting for state change or event
2020-10-15 23:35:34 DEBUG (MainThread) [custom_components.pyscript] stopping triggers
Here's the one script i'm playing with at the moment.
@state_trigger("binary_sensor.motion_group == 'on'")
#@time_active("range(sunset - 20min, sunrise + 20min)")
def wz_desk_motion_light():
# Terminate task before running a new one
task.unique("wz_desk_motion_light")
#log.info(sensor.random_color.split(',')[3])
if input_boolean.night_time == 'on' and sensor.bh1750_illuminance < input_number.motion_light_sonoff_01:
if light.schreibtisch_gu10 != "on":
x = sensor.random_color.split(',')[3]
y = sensor.random_color.split(',')[4]
light.turn_on(entity_id="light.schreibtisch_gu10",
brightness=140,
xy_color=[y,y])
task.sleep(input_number.motion_timer_sonoff_01)
if switch.dim_milight_gu10 == 'off':
light.turn_off(entity_id="light.schreibtisch_gu10")
I also tried it without a script in the pyscript folder, issue persists.
On 0.31.
#configuration.yaml
# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
# Text to speech
tts:
- platform: google_translate
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
logger:
default: info
logs:
homeassistant.components.cloud: debug
custom_components.pyscript.file: debug
custom_components.pyscript: debug
pyscript:
allow_all_imports: true
Logs:
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setting up pyscript
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setup of domain pyscript took 0.0 seconds
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setting up binary_sensor
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setup of domain binary_sensor took 0.0 seconds
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setup of domain tag took 0.2 seconds
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setup of domain input_boolean took 0.2 seconds
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setup of domain input_text took 0.1 seconds
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setup of domain input_select took 0.1 seconds
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setup of domain input_datetime took 0.1 seconds
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setup of domain input_number took 0.1 seconds
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setting up tts
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setup of domain zone took 0.1 seconds
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.updater
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setup of domain tts took 0.0 seconds
2020-10-15 21:50:56 INFO (SyncWorker_4) [homeassistant.loader] Loaded notify from homeassistant.components.notify
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setup of domain zeroconf took 0.2 seconds
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setting up mobile_app
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setting up ssdp
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setup of domain ssdp took 0.0 seconds
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setup of domain mobile_app took 0.0 seconds
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setting up notify
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setup of domain notify took 0.0 seconds
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setting up default_config
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.setup] Setup of domain default_config took 0.0 seconds
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.components.notify] Setting up notify.mobile_app
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.bootstrap] Home Assistant initialized in 1.15s
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.core] Starting Home Assistant
2020-10-15 21:50:56 INFO (SyncWorker_5) [homeassistant.components.zeroconf] Starting Zeroconf broadcast
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.core] Timer:starting
2020-10-15 21:50:56 DEBUG (MainThread) [custom_components.pyscript] adding state changed listener and starting triggers
2020-10-15 21:50:56 INFO (MainThread) [homeassistant.components.updater] Submitted analytics to Home Assistant servers. Information submitted includes {}
--- PRESSED RESTART ---
2020-10-15 21:51:20 DEBUG (MainThread) [custom_components.pyscript] stopping triggers
2020-10-15 21:51:20 INFO (MainThread) [homeassistant.components.websocket_api.http.connection.139842994864480] Connection closed by client
No pyscript files in pyscript directory at all.
No other integrations activated other than pyscript. Clean, default install.
The same issue is exhibited when running HASS on the command line. CTRL-C produces the "stopping triggers" log line... and then nothing after that until a second CTRL-C is pressed, at which point the "KeyboardInterrupt" exception is thrown.
Ok, thanks, now I understand what the issue is. I thought it was not correctly restarting from the command-line (ie, quit and re-start hass
manually), but you mean is doing a restart from the web interface. Yes, ^C not exiting the first time looks like a symptom of the same problem.
I can recreate this now. Thanks - now off to debugging...
Tested the same in my play vm with Home Assistant OS. I don't think the problem is noticeable in Hassio because the container is terminated by the supervisor.
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] waiting for services.
2020-10-16 00:18:04 ERROR (MainThread) [homeassistant.components.hassio.handler] Timeout on /homeassistant/restart request
Just pushed a fix: cd87d2e. Please try the master version.
That fixed it for me! Thanks!
@VDRainer - looking at your code, there are a couple of places where you should cast state variables to int
or float
since in HASS all state variables are coerced into strings.
For example, this comparison:
sensor.bh1750_illuminance < input_number.motion_light_sonoff_01
should be:
float(sensor.bh1750_illuminance) < float(input_number.motion_light_sonoff_01)
(or int()
), and this call
task.sleep(input_number.motion_timer_sonoff_01)
should be (although the string argument appears to work in this case):
task.sleep(float(input_number.motion_timer_sonoff_01))
Issue is fixed, HA restarts. Thanks for this component and the fast fix.
there are a couple of places where you should cast state variables to
int
orfloat
since in HASS all state variables are coerced into strings.
But it works. :smile:
EDIT: You're right. It didn't raise an error, but it didn't work.
I'm running HA 0.116.3 in a python3.8 venv on Ubuntu 18.04. Installed pyscript via HASS and tried both options, UI Integration and
pyscript
in configuration.yaml.First script runs very well and i like it. BUT I cannot restart HA anymore. It looks like HA stops because there are no more new lines in home-assistant.log but my screen session where the hass process runs shows tons of tracebacks and i have to kill the process.
After removing from integration or in configuration.yaml, HA restart works normal.