HA does unwanted yaml reformatting

Recently while editing Lovelace yaml I noticed that when I order yaml items in specific order, after reopening editor those items are re-ordered (in a manner I don’t like).

I could accept that eventually. What I cannot accept is the fact, that commented lines disappear. Really? Do we have another “smart” application which “knows better”?

3 Likes

Yes, that’s a known issue that isn’t really an “issue”. It’s just the way it is.

The script and automation editors act the same way.

That’s why a lot of people don’t use the UI editors.

But if you don’t use the GUI automations does it preserve the formatting?
I thought it doesn’t.

I’m not understanding what you are asking.

If you don’t use the GUI editors then that means you are writing everything out manually so the formatting would be preserved along with any comments.

So I think the answer is yes.

1 Like

Actually it is issue. GUI editor switches into code editor on its own when it is not able to support custom code. This is OK. But damaging my work without any warning is worst practice ever application can do to a user. There is no single reason to do that this way. If they wanted to prevent manual code changes in the GUI, they could have disable this code editor at all.

Thank you for pointing to possibility of editing lovelace.yaml in file editor. but it’s often the overkill comparing to editing selected part of code in GUI editor, seeing results immediately etc.

I really don;t understand some design decisions. One day they will be re-evaluated proving lot of resources wasted and lot of users upset.

It’s not damaging your work, it’s just putting the keys in alphabetical order.

1 Like

If I made an effort to order those items in the way I want, it’s damaging my work. For those who asks why I want to reorder items: I prefer to have card type at the top of card definition. Bottom is “too late”.
Removing comments is damaging my work.
Doing it without any warning is just disrespect (next to bad design)

1 Like

Then you need to do yaml mode.

The raw config editor is saved in json, so no comments and when it is validated and saved in to json, the next time you open the raw editor it loads all the keys back in alphabetical order.

If you believe that there should be more ‘warning’ as to how it works then submit a pull request to update the docs :slightly_smiling_face:

2 Likes

Why should I do anything? HA has enough bad-design defenders to defend itself.

No one is defending it, simply explaining to you how and why it works that way.

Personally, I don’t like having it alphabetically sorted. However, I don’t have the programming skills to do anything about it. All that I can do is make a Feature Request and hope someone who does have the required skills make it stop sorting.

I’ve learned to live with Lovelace’s YAML sorting. However, I find it unacceptable for automations so I never use the Automation Editor.

2 Likes

I agree with you. That’s why I don’t use any of the UI editors. :wink:

It’s just as easy, if not easier, to write things out in yaml.

2 Likes

Yeah it mangles everything By-Design. It’s not a bug. If you don’t like what the GUI does then your only choice is to use YAML.

2 Likes

Got it. Since I’m a programmer I used to use editors too. But we live in 21th Centaury. GUI has been invented for some reasons. Source code editors provide various helpers and assistance for writing keywords or object names. What cannot be said about HA’s one.

Since I’m not using yaml mode yet: does this mode provides real time preview of edited card? Can I edit single card or I have to edit whole lovelace definition at once?

Yeah… since where the mangling everything is not a bug? AFAIK applications have been invented to help users, not otherwise.
The fact something is done by design doesn’t mean it’s good design.

Please consider to read it again then.
BTW when I wrote app should warn about loosing what user wrote, I mean it literally. Putting it to docs is better than nothing but still not enough (I believe it’s obvious why)

1 Like

no

yes.

you edit the cards as a yaml file so you just edit the portion of that file that you want. Just like any other text document that you would edit.

Thanks for quick answer

So why is this method even considered useful?
I could understand yaml mode as alternative for skilled HA users as extension to GUI mode. not a replacement for a cost of loosing most important part of GUI builders: preview

Well, for one you’ve already answered part of it in this thread - comments and formatting

another reason is it allows you to split your configuration up into manageable chunks using !include files and that isn’t possible with the UI editors. Everything gets put into one monolithic file. So if you do want to manually edit the raw yaml files for the configuration you made thru the UI you are going to have to wade thru your complete configuration hunting for the piece you want to edit. And remember, since there are no comments and the formatting gets jacked up then you will be looking at a wall of text too find the one thing you want.

Lastly, writing the yaml by hand isn’t really as hard as people make it out to be.

The loss of real time previews hasn’t ever been a big deal to me. I write the code, save it, refresh the lovelace UI and see the results. It takes literally seconds to do that and it’s not that burdensome for the aforementioned benefits I get from manually editing things.

I agree with @maxym. Lovelace is a GUI creator. The GUI editor in Lovelace is great for quick prototyping. After a couple of weeks, you come back to reuse the code and its is jumbled mess. It like using vi or vim for text editing.

I use the following custom card and yaml mode editing, for the best of both worlds

Yes, it’s obvious. But it’s like to give you alternative: either to walk or use bicycle which can go backwards only. It will be faster but lets say, less straight forward :wink:
Still don’t get it why such design decisions. Sometimes it seems like devs are doing everything to make things harder or against established standards. I only believe that it’s intermediate state as result of incremental development.

Thanks for info about this addon!!!

I need to revisit that addon. I already use yaml and cut/paste into the GUI editor so I can play in the GUI as well as maintaining YAML. Works for me but I should try that addon for simplicity.

Since it’s by design.

Your opinion.
If you don’t like what the GUI editor does (I sure don’t) don’t use it. I don’t except for quick experiments but no one is forcing you to use the GUI editor (yet)

1 Like