Syntax Highlighting for yaml files

Good news everyone:
I created a json schema for the openHAB yaml files and uploaded it to schema store.
That means you can now easily get structural highlighting and auto complete for yaml files in your favorite IDE.

I’ve added the conf/yaml path as a default for openHAB configurations so some IDEs should automatically detect the format.
If the file is in a different path you can still manually select it for syntax highlighting.

We can use this thread to both discuss issues and to share setup steps for IDEs.

Tutorials

Pycharm (or any other Jetbrains IDE)

VsCode

PyCharm (or any Jetbrains IDE)

There are two ways: selecting the highlighting in the IDE or linking the schema directly from the config file

Select it for a file

Open the yml file. In the bottom right click on this box

grafik

Start typing “openhab” and select from list

Automatically link the file to the schema

At the top of the file enter

# $schema: https://www.schemastore.org/openhab-5.1.json

That way the file will always and automatically validated against the schema

Thx a lot, it is working:

One thing to note: the YAML extension needs to be installed in VSC to make it work :sweat_smile:

This seems to work only for installations with the default path in /conf/yaml, not for manual installation in /opt/openhab/conf/yaml

Is there any chance to also get the actual state of an item?

Strange. Imho it should work for both paths since I’m globbing with
**/conf/yaml/**/*.yml and **/conf/yaml/**/*.yaml

Unfortunately not. It just checks if the file structure is valid.

I checked again:

The “Select it for a file” does work, the " Automatically link the file to the schema" does not.

runtimeInfo:
  version: 5.1.1
  buildString: Release Build
locale: de-DE
systemInfo:
  configFolder: /opt/openhab/conf
  userdataFolder: /opt/openhab/userdata
  logFolder: /opt/openhab/userdata/logs
  javaVersion: 21.0.8
  javaVendor: Debian
  osName: Linux
  osVersion: 6.12.48+deb13-amd64
  osArchitecture: amd64
  availableProcessors: 2
  freeMemory: 117798632
  totalMemory: 1029701632
  uptime: 69927
  startLevel: 100

YAML from Red Hat…

Here my (working) part of settings:

		"yaml.schemas": {
			"https://www.schemastore.org/openhab-5.1.json": [
				"file:///etc/openhab/yaml/**/*.yml",
				"file:///etc/openhab/yaml/**/*.yaml"
			]
		}

That is not what I meant.
I was talking about

which does not work (for me)

Ah. yes, this part is not working for me either.

This only works for a JetBrains IDE (e.g. Pycharm) and not VSCode.


It would be nice if you or Udo could make a step by step guide for VSCode.
I could link it from the first post so it would work as index where we have the guides for the different IDEs.

Sure.

  1. Install the YAML plugin in VS Code through Marketplace (Contributor is Red Hat)
  2. For automatic scheme, go to settings - plugins - YAML and open the settings.json for Yaml:Schemas.
    Please be aware that there are a bunch of different options to load settings, i.e. user, folder, workspace and much more I can’t remember :slight_smile: It depends on how you use VS Code which is the right place to configure, so chose wisely.
  3. set the yaml.schemas to look like this:
"yaml.schemas": {
    "https://www.schemastore.org/openhab-5.1.json": [
        "file:///etc/openhab/yaml/**/*.yml",
        "file:///etc/openhab/yaml/**/*.yaml"
    ]
}
  1. If your $OPENHAB_CONF is pointing to another folder than /etc/openhab/, please change the path accordingly.
  2. Check whether json format is still valid (missing comma, etc.)

Try it out by creating a test.yml file in $OPENHAB_CONF/yaml/ or a subfolder of this path.

1 Like