Converts Home Assistant YAML automations to pyscript, a Python scripting framework for HA that uses decorators instead of YAML automation declarations. This uses an AI to accelerate the conversion for complex setups.
Go to HA Developer Tools → Actions and run pyscript.generate_stubs, then sync to your machine:
rsync -rv ha:config/pyscript/modules/stubs/ modules/stubs
rsync -rv ha:/root/config/automations.yaml ./originals/At runtime the pyscript interpreter ignores imports whose top-level package is stubs, so you can safely add from stubs.pyscript_builtins import ... lines for type hints without affecting execution.
Go to HA Developer Tools → Template and render this template, then save the output as originals/entity_ids.csv:
{% for entity in states %}
{{ entity.entity_id }}, {{ device_id(entity.entity_id) }}
{%- endfor %}Run the skill:
/ha-pyscript-converter
The skill:
- Runs
analyze_automations.pyto cluster automations by shared entities - Guides grouping decisions (one file per room/system)
- Converts each group to a
.pyfile, merging related automations into single functions
scripts/analyze_automations.py:
- Parses
originals/automations.yaml - Clusters automations by shared trigger/target entities using union-find
- Generates pyscript skeleton code for each group (decorators, conditions as guards, actions,
task.sleepfor delays,if/elif/elsefor choose) - Marks device UUIDs and ZHA commands with
# TODOwhere human verification is needed - Writes one
.pyskeleton file per cluster intotmp/
Reference files used during conversion:
references/patterns.md— Complex pattern examples: toggle pairs, door sensors, multi-device buttons, timer patterns, light level dispatch, ZHA button identification, motion-activated lighting, and morereferences/trigger-mapping.md— Exhaustive before/after mapping tables for every trigger type (state, numeric_state, time, time_pattern, sun, event, ZHA), condition type, and action type
Go through the generated # TODO comments. ZHA event IDs require manual lookup — check the event logger filtering for zha_event. If you see this in the logs, the event trigger type is wrong:
[custom_components.pyscript.trigger] trigger file.gaurav.gaurav_light_button_alt got event trigger, but not active
[custom_components.pyscript.trigger] trigger file.gaurav.gaurav_light_button_alt waiting for state change or event
rsync -rv ./pyscript/ "ha:/root/config/pyscript"Then reload pyscript via HA Developer Tools → Actions → pyscript.reload. You must do this when adding a new file.
Once converted, you can delete automations.yaml from HA to disable the old automations.