Are there any plans to introduce custom items with more than 2 states?
I’d like to be able to define controls that can have multiple states (a simple dropdown to select the values would be nice). A good example would be a custom control to control the heating mode (ON, OFF, AUTO, BEDTIME, etc).
string myCustomItem
...
rule "4 states"
when
Item myCustomItem changed
then
switch(myCustomItem.state.toString) {
case "ON":
Do something...
break;
case "OFF":
Do something ...
break;
...
}
end
It may ‘work’ with those item types, however only the ‘String’ item type shows the currently selected item text next to the item in the sitemap (if you click ‘Auto’ for example, ‘Auto’ shows next to the item). This is preferable to me as I like to know what the state of the ‘option’ is.
I would use a Number item for scenes though, I think this may a be useful feature for selecting scenes, as a workaround for openhabs refusal to add scenes natively, and I wouldn’t care about knowing the state since I would be using the options as buttons effectively.
If anyone is using string items for options in sitemaps, be aware you have to compare for the string literal of the state in your rules markup (ie. check for state==“0” instead of state==0). It can be confusing because openhab reports them as if they were actual numbers in the log. openhab, should, in my opinion, surround string states with quotes.