Swiches with mapping: error in WEB-UIs (Basic+Classic)

I have the following items defined in my sitemap which all are displaying the state of the same switch:

	Switch	item=EMD_07_05			label="SWITCH V1"				           
	Switch	item=EMD_07_05			label="SWITCH V2 []"   mappings=[OFF="Off",ON="On"]		
	Switch	item=EMD_07_05			label="SWITCH V3 []"   mappings=[ON="On"]					

All three items are displayed correctly in off and on state within the Andoid app:
1_Andoid_off

2_Andoid_on

Same on iOS iPad:

But BasicUI and ClassicUI are making an error when displaying version 3 of the switch (with only a mapping for “ON”):

Here BasicUI:

And the same for ClassicUI:

The same behaviour is for a contact instead of a switch.

Currently I’m using openHAB 2.5.0 Build #1727, but it was the same for older versions.

Not really. You are only defining ON here.

Switch	item=EMD_07_05			label="SWITCH V3 []"   mappings=[ON="On"]

There are no other options presented. This is a configuration issue, not a bug. OH is flexible enough to permit you to “shoot yourself in the foot” because it assumes you know what you are doing.

I think the complaint is that the single button version does not “light up” as anticipated.

Does it change if refresh the browser? How about if you click the button?

clear browser cache? Chrome is really bad about that. Try a different browser?

It’s the same for all browsers
 Refreshing also doesn’t change anything.
I can switch on the switch by clicking on “ON”, but “ON” will never get highlighted.

I would expect a Switch by definition would need more than one state. In fact, OpenHAB documentation describes it like this:

Switch Item, used for anything that needs to be switched ON and OFF

This is a Switch widget in a UI. It need not be associated with a Switch type Item, and is commonly used with Number or String types. When mappings are used, it may take into account one or ten different recognizable states.

1 Like

Can confirm this behaviour with OH2.4

I have some one-button switches in my sitemap - never noticed this (lack of) effect because I use visibility= as well to alter text

Switch item=test_motion_U1gate mappings=[ON="Detect"] visibility=[motion_U1gate!=ON]
Switch item=test_motion_U1gate mappings=[ON="Motion!"] visibility=[motion_U1gate==ON]

but even in that case the button should really “light up” red, and it doesn’t.

I would log a github issue for BasicUI & ClassicUI

No, you can just use one Mapping and, in this case, when you press the button it will send the ON command to the Item. I use this for my garage door openers as the control mimics a momentary push button.

@andreas_furrer68, honestly, I’ve noticed this behavior for about as long as I’ve been using OH. I never gave it much attention as it never was a problem for me. But an Issue should probably be filed.

1 Like

It used to work like you expected in the old version of the Ios App. You could use a switch item and show it as a single mapped button that would be shown as on if the switch had the mapped state. But one of the app developers told me that that actually was the bug.

Johannes

1 Like

You are right
 I just updated my iOS version and now it changed the behaviour

I can‘t understand why


Yep I also used the supposed ‘bug’ as a feature in my sitemap :see_no_evil:

I also think it is more clearly for informing about an active state of some things


It has nothing to do with autoupdate

1 Like

I think the misunderstanding is that weren’t expecting the button to turn off when we pressed it again. So not like a momentary push button. Instead we were expecting the button the to behave just the same with one mapping as with 2 or 10 mappings. Meaning it is highlighted when the corresponding item is in the state that the button in the sitemap is mapped to. I don’t understand why it should behave differently when there is one mapping versus 2 or more. Which is how the Ios App used to behave. Now it’s kind of counter intuitive when a mapping gets highlighted to the corresponding item state but only for 2 or more mappings but the behavior with a single mapping is inconsistenct.
Johannes

1 Like

Yes, this is also my oppinion.

The use a switch without mapping, simple as that.

We had the discussion before. There is several use cases were one has a switch item that only ever gets switched to one state in the ui by the user and there is no point in switching it off as it either switches itself off or gets switched when another item gets switched through a rule or nothing happens at all. So there is a point in having the possibility to have a button In a ui that is kind of one way and only gives the possibility to switch something to one state but not manually to another. But the user might want to know if it is still switched to the mapped state or if it changed state. So yes there is use cases where you don’t want to show a two way switch although the underlying item has multiple states. I would have thought that use cases like this ard what mappings are for. And I come back to my consistency argument as it just isn’t the expected highlight behavior if you use mappings otherwise.
Johannes

1 Like

I understand your intention, but the underlying UI element does not work that way.

To achieve what you want, you will have to use the visibility attribute. Just make two switches with one mapping, switch visibility depending on item state and ignore interaction for one of them.