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…
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.
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
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
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
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.
You mean JSON5. It has been created so that JSON can be used as a “configuration language” which it hasn’t beed designed for.
From what I gather HA internally uses JSON as storage format. Another thing JSON hasn’t been designed for But from my experience JSON works quite well for storing data. Though I wouldn’t want use it for data sizes of hundreds of MB.
JSON may be able to support comments. These comments are ignored by the JSON parser. But these info are not stored when JSON is parsed and therefore cannot really be restored back to the original value. JSON also doesn’t guarantee the field orders.
As it has been proposed few posts above, maybe additional fields shall be added to the JSON, which indicate the comments, and then restored back.
Most likely the best would be to:
HA stores the original version of the input data in the backend
HA in parallel parses the input data to the existing format and stores the JSON for the purpose of internal processing
Whyt would be wrong with saving original yaml files, too…? Thus we’d keep all comments, and in case of “mess something up” when changing our dashboards (for example) restore with copy/paste from a backup would be soooo easier… config yaml is saved, templates’s yaml’s are saved…etc… why are dashbords yaml’s not?
I mean yaml as i see it when i edit , for example my dashboard: when looking raw editor i see yaml, not json. Why is that yaml not saved? As i understand it’s re-compiled from json each time i open it, which is waste of time, resources….
Probably because these files are not supposed to be edited by users.
I got an opposite opinion: all UI-managed things should be kept in json, along with automations and scripts. Use yaml-config if you need to manage it yourself.
Hm…but a lot of people do edit those pages…
Are you suggesting that all people should change to UI ? That’s pretty … well, impossible, i’d say,since 50% of custom things doesn’t (fully) support UI… card mod is just one of them…
I think that’s why raw editor option is there: to be edited by users, otherwise it would be unreachable…or not?
I don’t mean editing automations, scripts… made in UI - i mean things like dashboard, cards etc… all these we can edit in UI (but mostly basics) and yaml (advanced). And here is where we come to a “problem”: why this is not also saved as yaml copy? This way we would be able to insert and keep comments.
An example: majority of my cards are made with custom button card. It’s UI is non-existent. But sometimes it would be nice to have comments so i can remember what i did years ago…
Saving two copies is never going to be the solution.
It seems like we are just talking in circles now. There really isn’t anything new to add to this discussion. We know why the comments are lost and have a couple of potential solutions.
If you like the idea of keeping comments, vote for this WTH.
I do not think that a yaml copy should be created. Instead, a way to store comments in json should be found (and it should support multiline comments).
To conclude:
All UI-managed things should be saved as json (including automations and scripts - which are now saved as yaml and some people are trying to edit their files).