Switch item - display on sitemap as text with mappings

I have a switch item, which I want to display on sitemap as a text item. i.e. I want to know the status of the switch, but I don’t want to control it.

Also I want to use mappings to report the status of a switch using different words, i.e. ON = home, OFF = away.

When I do this, OpenHAB Designer gives me an error. Any ideas?

I think this should work by using a Text widget along with standard mappings=[].

1 Like

I thought so, but this item / sitemap line doesn’t work:

Item:

        Switch   Welcome_Mat_AtHome     "Mat [%s]"                                      {netatmo="camera=583e0cc469f740182d8c3978#4576c290-a4ca-4f80-9c97-27e471267c33#OutOfSight"}

Sitemap:

	Text item=Welcome_Mat_AtHome mappings=["ON"="Home", "OFF"="Away"]

It stills shows the word “ON” and breaks the rest of the sitemap…

1 Like

Try;

[ON="Home", OFF="Away"]

Yep - tried that, same thing. Strange that mappings don’t seem to work for text widgets…

Yeah - just check my whole config and I don’t have a single Text widget using mappings - so I guess it is either a bug or an omission. The same technique of using a virtual String item which you update via a rule would work (but is far less elegant of course!).

Yeah mappings are only sor Switch or Selection items.

Are you expecting people/users to want to press the switch mapping but not want them to actually change anything?

If so, you could use a proxy switch item and a rule that updates the proxy switch state (and thus the mapping), but doesn’t do anything when the proxy item state is changed via the sitemap proxy switch item.

Thanks Paul

I’m not expecting users to press the switch at all - it’s just there for display purposes. The netatmo binding uses switch type to report presence, not to set presence. I would usually use a number type for something like that.

I will try a proxy item with a rule - all I need is to show different words “Home” and “Away” instead of “ON” and “OFF”…

You should do the mapping in .items:

Switch   Welcome_Mat_AtHome     "Mat [MAP(home.map):%s]" 

home.map:

ON=Home
OFF=Away
-=-
undefined=-
uninitialized=-
NULL=-
5 Likes

Thanks Udo - that does it!

I have a use case for this feature (mappings for a sitemap Text entry)

I have Switch Items controlling lights, motion triggered etc. They can also be controlled from Sitemap buttons normally.
However, the lights can also be controlled from wall switches. I have rules to detect that, and set an associated manual mode Item (one for each lighting zone). While manual mode is in effect, I disable motion control and also want to disable UI buttons for that zone. The user on the wallswitch is in charge!

So I have two lines in sitemap for each light zone, one a normal Switch with buttons, one a Text version of the same item without buttons, and select between them using visibility controlled by the manual-mode Item.
So far so good, working as wanted and displaying ON and OFF as required.

But for informative reasons, I would like to change the Text display of the light zone switch state from e.g. “ON” to “Manual mode ON”.
I can’t do that in sitemap, Text not allowed mappings.
I don’t want to do that in the Switch Item, because I want it to display normally when not in manual mode.

Cannot think of a mapping based solution here, and not only do I not want to create a dozen more dummy items and rules just to get this effect, it simply doesn’t seem like the correct approach when this is just what mappings are intended for?

Why not using the Label? In Sitemap:

Text item=MyItem label="MyItem Manual Mode [%s]" visibility=[MyItemManual==ON]
2 Likes

Didn’t think of that! Not quite the same visual effect, but good enough for me. Thanks!!

	Switch item=U1gangway visibility=[U1gangway_manual!=ON]
	Text item=U1gangway label="Unit1 gangway (manual mode) [%s]" visibility=[U1gangway_manual==ON]

Edit - and with a littl experimentation

	Text item=U1gangway label="Unit 1 gangway [manually %s]" visibility=[U1gangway_manual==ON]

displays name to the left and manually ON to the right

Yes, that’s right :wink: … aligned…

Hello Guys,
I have a simple problem which I want to solve with as little code as possible.
Problem: my KNX switch item is actually not a switch but a logical status.
Doing this:

Switch Rauchmelder_OG_Tim_Fehler_Batterie "OG Tim Batterie: [MAP(rauchmelder.map):%s]" <battery> (gRauchmelder) { knx="<(10)31/3/14" } 

and in the sitemap:

Group item=gRauchmelder label="Rauchmelder"

results in:
Screenshot from 2017-12-08 08-57-00

So I dont want and need the actual switch button but only the text and the icon. The icon change itself is working out of the box. I want to avoid rules if possible to achieve this.

Does anyone have an Idea how to achieve this?

When using a Group element in a sitemap, the items in the group will be displayed with their corresponding element type.
https://docs.openhab.org/configuration/sitemaps.html#element-type-group

You will need to replace the Group element with the individual items. Putting them in a Block will give the same visual appearance as a Group element, and using Text elements should give the effect you want for the items.

Text label="Rauchmelder" {
    Text item=OG_Eltern_Batterie
    Text item=OG_Tim_Batterie
    Text item=Rauchmelder_OG_Tim_Alarm
}
1 Like

Hello Scott,
that does the trick, thank you very much.

You are very welcome, Marco!

Hi @Udo_Hartmann, maybe you can solve my problem: I want the text displayed to depend on the sitemap (I use one sitemap per language I support). For this, I would really have liked mappings for Text as they reside in the sitemap and I could have simply sent an integer… Any clever trick? I could use a selection but that looks stupid as the item is read-only…

Sorry, did not read correct…

I didn’t get the problem, though. What do you mean by “the text”? Do you have an actual example?

Maybe it would be better to open a new thread instead of seizing an old one :wink: