Update all YAML to newest syntax

I’m slightly OCD and don’t like looking at all the red in VSCode.

Considering HA can perfectly understand YAML both old and new, it can also save automations/script into YAML with new syntax.

Is it possible to get HA to re-save all automation/script(/config) in the new syntax with a few clicks?

Don’t want to individually change something trivial and click save for 100+ automations and more scripts to get everything right.

1 Like

Home assistant never alters your yaml. This is a policy. Even when integrations are imported into the UI automatically after an update it is left up to you to remove the redundant yaml.

You will need to use VSCode’s bulk find and replace feature. Click somewhere in your automation file then Ctrl+f

Untitled

Took me about 2 minutes do do all my automations and scripts.

Make sure you have a backup of your files before starting in case something goes wrong.

After making the changes make sure to do a config check before reloading or restarting and check the log file for errors.

Make sure you have the “match whole word” option selected.

Note: all of these have two spaces at the beginning of the find and replace words. They just don’t show up on the forum.

It is important to do it in this order:

Find trigger: replace with triggers: can be done all at once

Find platform: replace with trigger: can be done all at once

Find action: replace with actions: can be done all at once

Find service: replace with action: can be done all at once

Find condition: replace with conditions: single step this one.

Be careful with that last one (conditions). It has the potential to find false positives if you don’t use lists for single conditions. It is best to use the find button and check each one before using the single replace button. e.g.

a false positive will be detected here:

  condition:
    condition: time # do not change this one
    weekday:
      - tue

However it would not falsely detect this one:

  condition:
    - condition: time # the '-' will protect this from find (no two spaces in front)
      weekday:
        - tue
4 Likes

Hi wyx087,

Also I did a video If you that would help.

SirGoodEnough just published the post How to Migrate Home Assistant 2024.8 & 2024.10 YAML Changes on their blog:

1 Like

In my case, platform: made a mess. It got into my light_group, packages (These might have been OK), espHome, camera, media_player, and TTS .
I have altered search and replace strings from yours, don’t have to watch the video, it’s in the blog post or video description as well what I suggest.

1 Like

HA doesn’t alter configuration.yaml.

But HA does alter a single automation entry in automations.yaml when saving an automation change in GUI. Similarly when saving a script edit done in GUI, it changes scripts.yaml. Best of all it saves it in the new syntax. But it will require going through all automation/scripts one by one.

It would be easy to add something to do this using one/few button press for all automations/scripts. Perhaps in the YAML page.

Unfortunately, I’ve made changes during 2024.09 using GUI and some service are actions. So I can’t find./replace all :frowning:

Since 95 % of my automations are based on blueprints - replacing keywords was rather fast: mainly had to search in blueprints.
It will take more time when we will need to replace to plurals in trigger-based template sensors.
And I am looking forward to get a very desired feature: blueprints for template sensors. Using blueprints will allow us to reuse a code more effectively.

1 Like

You need to separate those. One file for manual and one for GUI.

I get what you are saying but I personally like having all automation in the automations.yaml file. I do have a manual file but only put proper manual automations such as start up actions, where I will never need to go and change it unless changing core configuration whilst sitting at computer. The GUI automation editor has seen incredible improvements last few years and it is very usable now, able to do most things from mobile.

But I still want to look at automations.yaml in VScode from time to time, for example before doing a git commit. The syntax marking makes it very difficult to see actual changes.

The other way to look at it, HA can and do update a few of the yaml files, it’s easy to add a button in Dev-tools - YAML page to do the update for all areas that HA already modifies.

It’s just an idea to make YAML syntax changes over last 2 releases painless for the end user. A button such as “update to latest syntax”. Whilst I get many people are tinkerers, I don’t like the idea of “what are we fixing today” when the change can be automated.

After all, isn’t automation why we are all here?

I’ve figured it out.

Because the syntax changes for adding plural are all on first tab level, it can be easily done using "\n " notation in combination with number of spaces, and tick regex.

image

So previously service: now action: will not be picked up by the search and replace.
It will also allow easy search and replace all for condition:.
platform: and service: searches need to have single space otherwise the term in OP wouldn’t be picked up.
Also added quote marks because markdown didn’t show your leading spaces.

Therefore, I’d do the following, order doesn’t matter:

Find “\n trigger:” replace with “\n triggers:” can be done all at once

Find " platform:" replace with " trigger:" can be done all at once

Find “\n action:” replace with “\n actions:” can be done all at once

Find " service:" replace with " action:" can be done all at once

Find “\n condition:” replace with “\n conditions:” can be done all at once

4 Likes

To add on this, specifically search for

trigger:

with a new line for trigger:, action: and condition:. This will help with situations where the word can be the key of a list, or the key of a value (especially in the case of condition:)

EDIT: Only after typing this did I realize that @wyx087 described exactly this in the comment above, oops :slight_smile:

1 Like