HowTo use an Item.state as the label of another item?

Hi,
I’d like to something like this:

String MyDisplayItem “Sometext: [%s]”

However I want to use the state of another (Text-)Item instead of “Sometext”. Is that possible?

There is no official way to change the label other than changing the .items or .sitemap files. You could use a templating tool to regenerate your sitemap from a rule, but that’s very involved. Or you could write your own custom UI using the REST API, but that’s also very involved.

1 Like

Thanks for the reply.
That’s what I expected.
I’ll probably stick with the template approach using a rule. However the formatting is what I have to deal with. I did like the separation between the description and the actual value. The rule is working, now onto the formatting.

Hello,
you didn’t say what the value of your second item can be. My recommendation would be to create multiple sitemap elements (with different label texts) and only show the one you want to present in the moment by the help of visibility. http://docs.openhab.org/features/sitemap.html#visibility

Here is one example from my Kodi media center sitemap area where I’m showing a different label depending on if I’m watching a movie or a TV series:

Text item=KodiTitle label="Episode Title [%s]" visibility=[KodiTitleShow != ""]
Text item=KodiTitle label="Title [%s]" visibility=[KodiTitleShow == ""]
1 Like

Sorry for the missing info.
I’m trying to show a string and a number. Like Name of Shop and Price.

Both are held in items and both can change. I do not want to show them both with a description. All I want to display is the name and the corresponding price. Right now I have them separated by spaces (could be better)… To have one left the other right justified would be the ideal version, but that seems not possible.

If you are not able to name a counted set of label names, no. There is no clean way I can think of to set label names at runtime.

That’s what I understood from @wa to.
Thanks for the help.

Closed

BTW:
Reading your code, I figured (or beter learned) that “visibility” can not be used on charts only. That solves my other question