Dear Home Assistant developers,
I prefer working with YAML files for my automations due to the flexibility and readability they offer. However, I’m experiencing a significant issue when modifying automations through the UI:
The Problem:
When I edit an automation that was originally written in YAML (with careful formatting, blank lines, and comments) via the UI and save it, all formatting is lost. The automation gets rewritten as a long, unreadable blob without:
Blank lines between different sections
Comments that explain what certain parts do
Proper indentation and structure
Example:
yaml
BEFORE (readable):
alias: “Evening living room lighting”
description: “Turn on lights at sunset”
Sunset trigger
trigger:
- platform: sun
event: sunset
Lighting actions
action:
- service: light.turn_on
target:
entity_id: light.living_room_table
data:
brightness: 200
Slow dimming over 30 minutes
- service: light.turn_on
target:
entity_id: light.living_room_ambient
data:
brightness: 150
transition: 1800
AFTER UI edit (unreadable):
alias: Evening living room lighting
description: Turn on lights at sunset
trigger:
- platform: sun
event: sunset
action: - service: light.turn_on
target:
entity_id: light.living_room_table
data:
brightness: 200 - service: light.turn_on
target:
entity_id: light.living_room_ambient
data:
brightness: 150
transition: 1800
Consequences:
Automations become difficult to maintain
Comments (and thus context) are lost
Collaboration becomes more challenging
Finding specific components takes more time
Desired Solution:
I would like to propose that the UI respects the existing YAML structure when automations are saved. Ideally:
Preserve blank lines between logical sections
Maintain comments in their original positions
Keep the original indentation where possible
Alternative Solution:
A setting option to choose between “compact YAML” (current behavior) and “readable YAML” (formatted with comments).
This would significantly improve the workflow for many users who utilize both YAML and the UI!