Launch external editor for YAML files

  1. Web UI on whatever FE the user is operating on is configured to edit with an external editor (VS Code, GVim, Emacs, Notepad, etc.)
  2. Action on said FE requests a file to be edited (i.e. editing a dashboard component for example)
  3. HA server fetches or generates the content and gives the FE UI the file content to be edited.
  4. FE UI receives the content (as it does now for UI editor editing) and (after saving it into a temporary file if required) opens the configured editor for editing.
  5. FE UI waits for the editor to complete.
  6. User edit and then saves the file and closes the editor.
  7. When editor completes (i.e. the process closes) the FE reads the temporary file for the changes, deletes it and then submits the edited content back to the server.

I meant do you have a practical example.
I don’t remember seeing this feature in any other software.

I’m not sure a browser is allowed to download a file, launch a program, then upload the changed file without user intervention. Seems to be tricky security wise…

2 Likes

Which “External” editor do you have in mind ?, you do know that it somehow has to connect to HA ( Which basically is a linux-based webserver ), and there a “limited” ways allowed for this, such as add-ons like samba-share or SSH( with SFTP ) … this, you need to install first of all, for any external access, with samba-share you can use any editor i.e notepad++ Or you can use winscp, and connect over SSH(with SFTP) , and in winscp, you can in term configure External Editor
It’s as simple as this, you popup your favorite editor, which is already configured to access the files you want to edit.

As Chris explained cards/views etc are actually json, most config-files are plain yaml .

I agree that in specific the card-editor is horrible small , should open in full-view-size, i prefer raw editor is some cases, how ever i always save the views ctrl-a ctrl-c, paste in notepad++

In notepad++ i can make certain larger changes , then ctrl-a ctrl-c, and paste/overwrite cards/views

Other config files i access mainly through SMB/CIFS

As it’s a webview you are “phasing” cards(and mainview) etc are in this case mainly build upon.js class’es etc.
So someone could build a more comprehensive/advance file-editor( as an ADD-ON/Integration ) (i don’t need this to weight down my installation)(however yes card-editor in full-view, is desirable). Some card developers ad features to the UI editor, some has keep it “available” as file-editor options, and it will always be like this.

So if someone should build-in a click-option to an external editor, this has to include the ability to

  1. copy the yaml-code
  2. export it to some editor, on another node(IP) ( with user access to this “Windows Machine” ? )
  3. receive this yaml-code, from this external-source/user-account
    4 paste/overwrite it (preferable) in right place ( meaning keeping a connection to the specific card you are editing, in the webview ) Keep Dreaming

(or is it just specifically for raw editor mode, you find it unbearable to edit, and cumbersome to hit ctrl-a ctrl-c) ?

It doesn’t really matter. Any editor which can open a file, edit it and then save it.

The default/built-in YAML/configuration editor is just a “local” (i.e. to the web FE client) editor run in the browser.

You are thinking about this the wrong way around. The existing web UI editor does not use any kind of sharing or remote file access protocol to edit YAML/configuration files. The HA web UI client is given the content from the HA server which it edits and then sends back. The web UI is not given a remote file share (I.e. CIFS path, or ssh/sftp URL, et.) to load the file from.

It doesn’t matter what their source content is. Their source content (i.e. json) is not what the web UI editor is given to present the user with to edit. In my experience it’s always YAML. My point is that I don’t want to edit the source (i.e. json) files. I want to edit exactly the content that the web UI editor is given but I want to edit it in my own editor, not the web UI editor.

Frankly that’s the least of the issues. The fact is that the web UI is about as basic an editor as you can get. There are sooooo much better editors out there that will lint for you as you edit, have far better navigation, search and replace, etc.

Just the fact that everyone is super comfortable and efficient in their own editors
and should not have to devolve themselves down back into an editor from the 80s.

There you go. You have made my case for me. :slight_smile:

That’s entirely and completely the wrong approach. The last thing we need is yet another editor. There are already tons of them and everyone has their favourite. We don’t need yet another one that doesn’t do everything everyone wants (whereas everyone’s existing favourite editor already fills that gap) anyway.

It’s all editing in HA. The bottom line is that the editor in HA is super basic, like a throw-back to the 80s. There are many many way better editors and we don’t need to invent a new one. We just need a way to leverage the existing massive pool editors where everyone has one they love and are super comfortable and efficient using.

1 Like

I know how it works , and above “section” also , you on the other hand, doesn’t seems to know that it’s build that way, by the devs of core and frontend, to give people a basic choice, in the early days of HA im sure they edited in VI etc. OR, there favorite editor, maybe GUI based, and “pasted” or transferred through SSH

Correct, long live C/P … or the fact that by a few click you can install samba-share, or SSH(w. SFTP)

PS: I and probably most people like the fact that when you edit a card, you see the result(most of the times) before you even save it, so you can keep “correcting” adding until it looks like you want, How on earth do you want to accomplice this on an external Editor ? , You don’t !, so we are back to Raw editor mode only.
As you sounds like an “experienced” computer user, with ability to write code, i have hard to understand how a few keyboard touch, can be such a pita for you, it’s done in 2-3 seconds

Beside, after you save it the first time ( on the Unit you edit from ) it’s there !, you don’t have to open the View, before you are done and want to paste/overwrite the old, there you saved 1.5 seconds, you can edit it how many times you want, without disturbing you HA instance.
As a bonus you got your self an extra backup

I’m reading that it is JSON internally → I’d also wish to be able to work with YAML anyway.

The problem is a classic legacy issue here I guess:

  • I don’t think there are technical benefits of the conversion
  • I assume JSON was first internally, YAML was added layer for the UI

To fix it:

  • Let’s imagine SFTP/Samba as yet another UI :wink: Well, we shouldn’t imagine: CLI is a kind of UI. Anyway…maybe the YAML file could get (re)generated/parsed/synchronised with the JSON file → so that people can edit the YAML file, while keeping the backwards-compatible JSON layer.
  • Or better: just get rid of the JSON layer at all, just use YAML internally as well.

The why(s):

  • would allow to use an editor of choice for YAML
  • I want to git-version-control: I’m not tracking the internal JSON file (yet) → I’d wish to track the user-editable YAML file
  • if getting rid of JSON entirely, no more problem with HA deleting YAML comments

Well, not quite. It’s javascript code that exchanges with HA through http.

Might be hard to grasp, but the “file” (which is itself already a YAML representation of a JSON content, as said above) is not actually local at all. It is its http/css representation that you see in the browser, and there is no way to “open” that content in a local editor.

If you don’t grasp the difference, I understand your request, but it’s technically much more different than “the webui is just another editor”.

The fact that you cannot find a real-life example of an implementation of your request might be a hint, here :wink:

Bottom-line: We discuss all day, but the only actual option you have in the foreseeable future is Samba or SSH/vscode for actual YAML files, and nothing for specifically the dashboards source code (besides copy/paste in a better editor, which is what I do).

Basically, there is no YAML-file for the View/cards, and the “website(View), and cards” is highly build upon .js , which makes the under-lying .json a perfect fast and more secure choice, as it also have to communicate with a bunch or various API’s

I can agree upon JSON was “first”, and therefore long ahead in both the ability to fast parsing heigher security, better support for various languages etc, and as mentioned, Most API’s HA is communicating with are using JSON, for the very same reason, compact, fast and secure parsing.
Rebuilding the Whole underlying system And the external communication, seems to me like starting over from scratch, even thou one doesn’t “get around” the fact, that you have to build for communication with external JSON API’s

Think Again

I would say, Yalm was only added because of it’s easy to read and write structure, for configuration files ( that basically wha it’s current good for ) You have to convert it ! , into i.e JSON, and the “stuff” eventually have to end up in a HTML/.js combined webside
So what you see in Raw Editor mode is basically just an .js editor, which convert the JSON into Yaml

Beside it’s more or less the only “file” ( you guys want to rebuild the whole system for )

You can access all other yaml-configuration files And.js files etc. through ssh/ftp/samba-share, That is The Way most/all system-administrators access their web-server, if not working locally in the serveroom ( read your comfy couch, or fav. chair )

More over there are a “fully featured” Add-Onn
" Fully featured Visual Studio Code (VSCode) experience integrated in the Home Assistant frontend " , beside the basic options mentioned above

Nope. Initially, everything was YAML.

Then UI configuration was added (basically, the .storage directory, where UI-backed dashboards actually reside) and JSON was choosen as its supporting format, for whatever reason.

Ok, i don’t know about HA’s history, but i believe JSON was “born” before YALM, And as mentioned used in probably most external API’s

The format, sure, but that was not what @DvdNwk was talking about.

1 Like

I’d say, not a big issue. If you want to keep JSON at the backend, and want to present YAML for the user → you just convert JSON->YAML. And they do.

U’re saying they do that at the client side (js: in the user’s browser) → the solution would be to do it on the server side (python [?]: in the HA Core [?]; node js [?]; I haven’t read the internals yet; whatev). This way it could be available for both the Lovelace UI and anything else.

I’m starting to think you don’t know what you’re talking about. JSON and YAML are just data formats, serialization formats → there are no “security” differences between them.

Unless you know some security issue with YAML specific to HA’s parser implementation, then it would require an immediate fix, but in general there shouldn’t by any.

hey, it’s a big one. I’d guess about half of the “code” generated by the user is the Lovelace configuration (the other half being automations, etc). So you’re saying I’m only allowed to edit / version control only half of the stuff I want, not “just one file”.

BTW, same goes for example to Helpers created in the UI → they are also JSONs in the hidden storage. Same issue.

Yep, I’m mounting HA’s filesystem via SSHFS and edit configuration.yml etc using PyCharm.

Yep. But again: not for the lovelace/helpers/i_dont_know_how_much_more - as it is JSON and “internal .storage”.

And I’d have to open the web page with the addon every time I want to change something, which is slow to me. My PyCharm IDE is open 24/7 :wink:

Yes that is what “they” do, in raw editor-mode

Think what you want, but we are talking about “average” people editing editing, and doo to the flexibility of Yaml, it could be (actually does) causes i.e crashes of the system, people who can’t start their system, and even possible to create vulnerabilities, so it’s a wise thing to keeping it to JSON( beside the performance benefits ), in the back-end ( Having YAML in back/front-end( for other than simple config-files) is " not allowed commend here ! "

Right, i do have a “view” over 2000 rows ( so i do wish for a “search-box in header” of raw-editor-mode )( even thou i have all my views/cards externally(yaml) from my first HA(2021) until now ( however the “version control” is limited to “sort in order#created” ) :slight_smile:
My Version-control does not occur in my HA-system, it’s resides on external device ( Where do you have your “version-control” ? )

True, this relative new feature, could need an “improvements” which i think eventually will come ( there has been some already, since it’s resent “birth” ) however as they mostly are “templates” it does fit better in JSON format, i.e do the better performance

Yes as above, and .storage can be a “dangerous” place to open(lock) files in external editors ( absolutely not recommended !) , it’s a little cumbersome to edit i.e device-registry etc. when / if that is needed, but again, keep in mind the system is intended for a wide “audience” , which files do you suggest should be easy accessible/editable for everyone ?, with the impact this can (Already) cause ?

No you don’t you open/access your shared folders(samba), from/on your “working device”( where you have your external editor) 24/7
With i.e winscp(configured to use your "external"preferred editor), same, a double-click on your desktop 24/7, over secure SSH, from anywhere
( ps: i know you don’t keep your “version” control on your HA-Unit :wink: , meaning you are working on another device, where you have your preferred editor, if it doesn’t support converting YAML to JSON, use an online tool

Don’t feel pity, because you have to RAW-edit your view in a basic editor, on the HA, when you have multiple options, probably a majority of the user-base, avoid even raw-editor, because they don’t have the knowledge that many others have when it come to programming/editing

So as you self mentions, there are options(several), and as long as My system is function, i could care less, how it’s build, as long as the devs to some extend have it’s wide user-base, and security/stability in mind( which i have the feeling that they do their best to )

Yes, im still “confused”, you, or in specific brianj don’t want few “enhancements” in the “raw-editor” mode , however you do want to edit yaml , from/on an external Device and external Editor
How ever you “bend” it, there needs to be some kind of “communication” between the HA’s web-UI, HA’s Front-end, and Core, and a “Secure” such, which there are already several options for.
Yes you need “credentials” , verification, to access the HA resources, your personal linux/windows(external editor) account, don’t make it through, unless you have configured an i.e Integration/add-on. ( you even have to lock in(with your HA-admin-account), from your external browser, to be able to edit “locally” )
And please don’t suggest a builtin-option, where anyone, from their random “preferred” phone-app/windows editor, should be able to just click/touch( double-tap ) to access your (secure) homeautomation/web-server, with the , interference, lock of files and vulnerability, this in any ways will implies
Many people find the need, and there are some viable options, yet another integration/add-on could be yet another option … And that is actually what OP’s “request” is, " yet another option "

True, would be convenient ( skip basic-file-editor, skip-ssh/ftp/samba/VS-Code-Editor, skip-raw-editor-mode , because what people want is YAML-only( no matter the under-lying factors ), and just a button " Open External Editor ", i think most people can relate to that is a “simple/easy” solution

cd /homeassistant && git init

I don’t think having to parse YAML vs having to parse JSON would be any kind of performance bottleneck.

And if it was a slight issue, there’s always caching for the rescue (and sometimes more problems :smile:).

I don’t know about the files → I haven’t got into the internals that much yet.

For me personally: I’d love to have everything managed by configurable and git-trackable config files.
Most importantly, as I’ve already mentioned: the Lovelace config and Helpers.
But eventually anything else: installed integrations, General->Settings… anything that I change with my mouse on the Web UI, I’d like to see in my version control tracking.

The end goal being: if I want to configure a new machine hosting HA, I’d just git pull && reboot.
If I want to get back to any kind of historical state of HA, I’d just git checkout <revision> && reboot.

But that’s most likely if I were living in a dream world → as more and more is pushed towards Web UI → even things that used to be YAML–configurable, they are not anymore…

I do: see above :stuck_out_tongue: I back it up to github, but I edit the configs / git commit “directly” on the HA–Unit (“directly” in quotes, because – as I’ve mentioned before – it is actually via SSHFS lets say “tunneling”).

I guess HA-OS is not your preferred install, sounds like you need Supervised, or Docker

And yes, i would also love to easily be able to poke around everywhere, but i “felled” back into HA-OS quite quick, do to stability/easiness :slight_smile:

I’m using HAOS. I may try Docker in the future. But that’s a sidetopic to a sidetopic :slight_smile:

Is it ?, both you and OP could use your preferred editor, with another HA install Type, and easily gain access to the whole “packet”, for editing and version control

AFAIU, OP is wishing for a WebUI button that would launch edit YAML with a preferred editor on their (client) computer.

There are a few mixed issues here:

  • editing YAML config files in a preferred editor – SSH/Samba access solves it → no need for changing HAOS to let’s say Docker
  • Lovelace config being actually JSON translated to YAML “temporarily” in the Web UI – neither SSH/Samba nor Docker solves it
  • what the OP wants → for me not exactly what I’d like to use, but a step forward, if I can’t get lovelace YAML via SSH :wink: would allow to edit with a preferred editor, but still lacking version-control tracking (unless i’d track internal JSON files)

Yes that is what you should do, and ofcause not only, i even edit some “plug-ins” like cards ( .js ), so what ever filetype you want version control on please do.

With HAOS, your can easily track everything under /config (/ homeassistant ) , that include all Custom-Component(integrations) and custom-cards, beside the .json in .storage.
Most add-ons config-files your need i.e Advance SSH Add-on to access, as they are in separate Docker-containers, you find your config-files for i.e add-ons under /supervisor.

Basically you installed a server build on python, using json, js and yaml (most likely for easy readability ) but that’s not for the functionality ( it’s just config-files )
You are asking for a rebuild of everything, every integrations you want to use yaml, and every add-on also, etc. , and easy access to everything , from external source/editor( Will never happen with HAOS !)

You and OP should consider optional install-type, supervised/docker, and get use to edit json ( and hope for a “costly” workaround for i.e dashboard etc to intermediate storage in yaml-file-format, as for i.e automation.yaml etc )

That is a “hard” one even to discuss, for people who don’t “create/contribute” to this open source platform, even more because it involves all components( you want file-versions on, and in yaml format ), native as well as custom

I don’t know why i even commends on this topic, as im sure even OP knows, he want external access to another OS/Server/front-end without any form but a click on a button, to launch his external file editor, And no “new inventions” … well beside you actually wants to access a secured server, Externally, with no flaws

They do not. What you see in the frontend when you click edit in yaml is serialized objects. It’s not actually yaml. There is no conversion that’s done.