Skip to content

Commit d1c82a5

Browse files
authored
Merge pull request #1581 from CCOSTAN/feature/ha-yaml-dry-verifier-skill
Add Home Assistant YAML DRY Verifier Codex skill
2 parents 243f660 + 081da0a commit d1c82a5

5 files changed

Lines changed: 501 additions & 0 deletions

File tree

codex_skills/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Codex skills stored in-repo so they can be shared with the community. These are
2525
## Skills
2626

2727
- `homeassistant-dashboard-designer/`: Constrained, button-card-first Lovelace dashboard design system + YAML lint helper.
28+
- `homeassistant-yaml-dry-verifier/`: Home Assistant YAML DRY verifier to detect redundant triggers/conditions/actions/sequence blocks and suggest refactors.
2829
- `infrastructure-doc-sync/`: Session closeout workflow to update AGENTS/README/Dashy shortcuts/Infra Info snapshot consistently after infra changes.
2930

3031
### Notes
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
name: homeassistant-yaml-dry-verifier
3+
description: "Verify Home Assistant YAML for DRY and efficiency issues by detecting redundant trigger/condition/action/sequence structures and repeated blocks across automations, scripts, and packages. Use when creating, reviewing, or refactoring YAML in config/packages, config/automations, config/scripts, or dashboard-related YAML where duplication risk is high."
4+
---
5+
6+
# Home Assistant YAML DRY Verifier
7+
8+
Use this skill to lint Home Assistant YAML for repeat logic before or after edits, then refactor repeated blocks into reusable helpers.
9+
10+
## Quick Start
11+
12+
1. Run the verifier script on the file(s) you edited.
13+
2. Review repeated block findings first (highest confidence).
14+
3. Refactor into shared scripts/helpers/templates where appropriate.
15+
4. Re-run the verifier and then run your normal Home Assistant config check.
16+
17+
```bash
18+
python codex_skills/homeassistant-yaml-dry-verifier/scripts/verify_ha_yaml_dry.py config/packages/life360.yaml --strict
19+
```
20+
21+
Scan a full directory when doing wider cleanup:
22+
23+
```bash
24+
python codex_skills/homeassistant-yaml-dry-verifier/scripts/verify_ha_yaml_dry.py config/packages config/automations
25+
```
26+
27+
## Workflow
28+
29+
1. Identify target YAML:
30+
- Prefer changed files first.
31+
- Include adjacent package/script files when the change might duplicate existing logic.
32+
33+
2. Run verifier:
34+
- Use `--min-occurrences 2` (default) for normal checks.
35+
- Use `--strict` when you want non-zero exit if duplication is found.
36+
37+
3. Prioritize findings in this order:
38+
- `FULL_BLOCK`: repeated full trigger/condition/action/sequence blocks.
39+
- `ENTRY`: repeated individual entries inside those blocks.
40+
- `INTRA`: duplicate entries inside a single block.
41+
42+
4. Refactor with intent:
43+
- Repeated actions/sequence: move to a reusable `script.*`, pass variables.
44+
- Repeated conditions: extract to template binary sensors or helper entities.
45+
- Repeated triggers: consolidate where behavior is equivalent, or split by intent if readability improves.
46+
47+
5. Validate after edits:
48+
- Re-run this verifier.
49+
- Run Home Assistant config validation before reload/restart.
50+
51+
## Dashboard Designer Integration
52+
53+
When dashboard or automation work includes YAML edits beyond card layout, use this verifier after generation to catch duplicated logic that may have been introduced during fast refactors.
54+
55+
## Output Contract
56+
57+
Always report:
58+
- Total files scanned.
59+
- Parse errors (if any).
60+
- Duplicate groups by kind (`trigger`, `condition`, `action`, `sequence`).
61+
- Concrete refactor recommendation per group.
62+
63+
## References
64+
65+
- Read `references/refactor_playbook.md` for concise DRY refactor patterns.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
interface:
2+
display_name: "HA YAML DRY Verifier"
3+
short_description: "Find redundant HA YAML logic"
4+
default_prompt: "Use $homeassistant-yaml-dry-verifier to verify Home Assistant YAML for DRY violations, redundant triggers/actions/conditions, and refactor opportunities."
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Home Assistant YAML DRY Refactor Playbook
2+
3+
Use these patterns after verifier findings.
4+
5+
## Repeated Actions or Sequence
6+
7+
- Move common action chains into a reusable script (`script.<name>`).
8+
- Use script fields/variables instead of duplicating payload variants.
9+
- Keep each automation focused on trigger + routing, not full action implementation.
10+
11+
## Repeated Conditions
12+
13+
- Promote shared logic into helper entities (`input_boolean`, helper groups) or template sensors.
14+
- Replace long repeated `and` chains with a single meaningful condition entity when practical.
15+
- Keep per-automation overrides small and explicit.
16+
17+
## Repeated Triggers
18+
19+
- Merge equivalent triggers into one automation when the resulting behavior stays clear.
20+
- If actions diverge, keep separate automations but centralize shared actions in scripts.
21+
- Avoid copy-paste time/state triggers that only differ by one minor field; parameterize if possible.
22+
23+
## Intra-Block Duplicates
24+
25+
- Remove exact duplicate entries inside the same trigger/condition/action list.
26+
- Keep only one canonical copy of each entry.
27+
28+
## Validation Loop
29+
30+
1. Run verifier.
31+
2. Refactor.
32+
3. Run verifier again.
33+
4. Run Home Assistant config check before reload/restart.

0 commit comments

Comments
 (0)