Yaml configuration for item with map transform and no channel

Started migrating my textual configuration to the new YAML format. Have read up on the documentation and tested a few things, but wondered if anymore could help out. I have the following item without any channel that I use for a rule:

Number	SceneItem				"[MAP(scene.map):%s]"

Is there a way to reuse the map file, either via the label or as a tranform in the channel?

Are transform dependent on having a channel all the time?

Espen

Transformations can be applied in a number of places:

  • in a Channel configuration
  • a transformation Profile
  • in a rule
  • Sitemap label
  • Item definition

It’s the last one that’s relevant.

Since .items files were created there has been a whole lot of changes to how openHAB lets you control how the state of an Item is formatted before it’s displayed. This means that the label field of an Item in a .items file is now really a shorthand for defining a stateDescription. One field of the stateDescription is the pattern and that’s what the stuff between [ ] becomes.

Looking at the docs for the Item definition in the new YAML file format we see

format A short form for the stateDescription → pattern metadata, equivalent to the format enclosed in square brackets in the DSL item label.

So just add a format property to your Item definition and put what you currently have between [ ] as the value (without the brackets).

format: MAP(scene.map): %s

Yes, you can use the format hield.

I hope you know the YAML format can be generated automatically for you, MainUI provides features to export existing item(s) to YAML (or DSL) format.

2 Likes

@rlkoshak Thanks

@Lolodomo I tried the “Copy File Definition” initially, but that only gives me the following:

version: 1
items:
SceneItem:
type: Number

So the label and format part is completly missing, hence my search for how this was suppose to work.

Also looks like there cannot be a space between “:” and “%s” in the format, so this works

format: MAP(scene.map):%s

Maybe the problem is that you have no label before [ in your DSL définition. Not sure it is valid

Try setting “xxx [MAP
]” to check how it behaves.

I will check myself.

You are correct, by adding something more than “MAP(scene.map)”, the Copy File Definition works, and gives me:

version: 1
items:
SceneItem:
type: Number
label: Label
format: MAP(scene.map):%s

Not sure I will call this a “bug" in the copy file definition feature, but I am probably not the only one that have created such Scene items.

In case the mapping in your original DSL définition is really considered and not ignored, yes I would say there is a bug in YAML generation.

Looking at the code, I can confirm there is a bug in DSL and YAML generators as I ignore the format when there is no label , while DSL/YAML item providers accept it.

I will submit a fix.

2 Likes

Fix proposed:

Edit: fix is now merged.