WTH comments disappear from yaml editor?

Sometimes we have old scripts or automations that were created in yaml, but can now be edited in the gui. Or some portion of a new script or automation requires yaml (or jinja…)

Whenever you just open the script or automation in the gui - even accidentally - let alone save, close, and re-open, it removes all comments.

If I put a comment in my code, it’s because I wanted to remind myself of something - perhaps years after I originally wrote it. Just leave comments alone.

1 Like

Wasn’t this why the alias option was introduced for each block of yaml?

1 Like

Can alias: be used outside of automations? E.g. dashboards and cards?

Sorry to ask, but I searched and only found reference under the automations doc.

You can add any option and add some text.
But you may loose UI editor (some people cannot live w/o it):


Saved in json:
image

1 Like

10-4, that’s a good trick. I do prefer UI as an option though.

I’ll tuck this one away. Thank you!

Storage for automations is currently in YAML though?

Jamming reminders into the title of automations, trigger items and action titles is really limiting. How about a multi line comment in automations or entity definitions so I can remember why I did something or what I changed, etc?

Indeed, also as old-skool user of HA, I wish to edit my YAML files manually sometimes, instead of using the GUI. I use comments, line and multilines, to track changes, help find automations, scripts etc.

Please find a way to keep these comments, I need to restore backup files to often now…

1 Like

I guess it’s not an option to use a different JSON library that does support comments? It’s definitely true that “stock” JSON does not, but I’ve encountered a number of JSON parsers/libraries bend the rules and allow them anyway. That said, I have no idea what all that might affect, so possibly a much bigger change than it sounds like on the surface.

The most practical option is the one petro mentioned above:

This is relatively simple to implement, should not affect existing JSON, and does not require a new JSON library.

Yep, fair enough. I guess I was imagining one that would be API-compatible so it could just be dropped in, but obviously there’s no guarantee that what HA is currently using has such a variant available. :grinning:

Could there not be a “comment” item available in the automation editor, which takes a string and does precisely nothing with it?

That way, it would be visible in the YAML as well (and in the JSON, should anyone look at that). Not as easy as adding a YAML comment, for those that edit YAML directly, but maybe HA could convert them on save…

1 Like

Anything that is supported in the YAML can be shown pretty trivially in the UI. So the answer is yes, given petro’s option is implemented first.


EDIT: I misunderstood the question. Petro’s suggestion is comments as a field for any JSON object, whereas yours is to have a JSON object that is just for comments. This could be useful as well.

This field already exists, called alias

I don’t think unikitty is referring to an alias field within an action, but rather an action that only contains an alias. Essentially a dummy action. There would be no dropdown arrow. Just text. Like this:

I currently mimic this functionality by putting a call to script.turn_on with no entities. I then change its alias and disable it. Essentially it becomes a comment

1 Like

Or just set a delay of 0.1s (or less) if your automation is not super time critical. That way you won’t have to remember to disable it, and any potential future changes to HA will not throw an error :wink:

1 Like

Even if we added the yaml keyword / GUI field “comment” and had the limitation that there can only be one - it would still be better than nothing.
This field in the GUI should be a multiline field which is put as multiline in the yaml incl the line breaks. It would be a great help being able to put 2-4 lines of text with thing to remember related to a script or an automation.
The alias fields today are OK for one liner few word comments. I just find them confusing because they used to also mean something more specific as I remember it. I understand it is not possible to preserve random comments and out them back the same place again

1 Like

I think there’s a version of JSON that does comments. Although I’m not sure why we are translating back and forth between YAML and JSON instead of just picking one and sticking with it.

1 Like

Every now and then I think “ahh the gui editors have gotten a lot better, maybe I should move off of yaml”.

No comments is an ongoing deal breaker for me though.

Made the mistake of editing in the gui once and lost all my comments. Luckily I was backed up.

Great suggestion, voted.
One of my first posts on HA forums How to keep # comments in frontend YAML files?