Selection transition to Switch item...help

Hi,
i have Zwave LC13 thermostatic radiator valve devices that are set via an selection item in between 10 and 28 degree. I only need to to say FULL SPEED or FULL STOP.
After some time i now realize that selection is too cumbersome for daily change so my hope/idea is to remove the selection item and transform it somehow to ON OFF swithc item? So if it is OFF it would be 10Degree and if it is ON it would be my current 28Degree.

I’m sorry but i’m completely clueless what is required. From what i know about Openhab mostly it can all be done in one step…somehow Switch item and mapping but i’m not sure if this could fit the requirement or if still a rule like below needs to be in place?

Right now it looks like this:

Sitemap:
Selection item=LivRoSelect mappings=[0="10°C", 1="28°C"]
Rule:
rule "Heating TempSelect" when Item LivRoSelect received command then switch(receivedCommand) { case 0 : LC13thermoLivRo_Setpoint.sendCommand(10) case 1 : LC13thermoLivRo_Setpoint.sendCommand(28) } end

lk

And what seems to be the problem?
What is the definition of the item LivRoSelect? I assume it’s a Number item.
You put the receivedCommand between brackets which will make it into a boolean true or false

Rewritten rule so that is can be read:

rule "Heating TempSelect"
when
    Item LivRoSelect received command
then
    switch receivedCommand {
        case 0 : LC13thermoLivRo_Setpoint.sendCommand(10)
        case 1 : LC13thermoLivRo_Setpoint.sendCommand(28)
    }
end

That’s not what ( ) does. Like { }, ( ) is a way to define a context, only the context is a little different. It’s kind of like a way to say “treat everything between the () as one thing.” Another way to look at it is that it’s a way to control order of operations, just like in math.

That’s why, for example, if you want to call .intValue on a Number Item’s state you need the parens.

(MyNumber.state as Number).intValue

The parens force the cast to Number first and then you can call .intValue.

You see the parens involved with an if statement because you need the conditionals to evaluate before the if statement so the parens force that to happen.

In the context of the switch statement, it’s kind of a noop (i.e. does nothing). But, in this case you may need to do something. receivedCommand is a State and not necessarily a Number. I don’t know if the Rules engine will be smart enough to treat it as a Number or not. So I would keep the parens and cast receivedCommand to Number.

switch(receivedCommand as Number) {

Why so complicated?
Doesn’t that work?

Switch item=LC13thermoLivRo_Setpoint mappings=[10="10°C", 28="28°C"]

No Rule.

3 Likes

Tried that one, but it does not really work / Openhab does not like it at all.

I now did a switch item that is related to a rule…
seems to work in iOS but the webbrowser+Classic UI makes the GUI almost not respond…something is going on, but i have no idea why. The rule itself is not that komplex i guess…

rule “Heater TempSelect”
when
Item LRsel_Switch received command
then
switch(receivedCommand) {
case OFF : LC13thermoLivRo_Setpoint.sendCommand(10)
case ON : LC13thermoLivRo_Setpoint.sendCommand(28)
}
end

I use that quite often, it works!

What did you exactly do and what did openhab complain about?

1 Like

I used your entry unchanged:

Switch item=LC13thermoLivRo_Setpoint mappings=[10="10°C", 28="28°C"]

however from that moment on i received massive error messages in the openhab.log file.

  • the Classic UI looked completely destroyed…

STrange as you say it definitely works and i would love this one as it looks most efficient.

2019-12-17 22:36:11.218 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'EntryEGPresence' for widget org.eclipse.smarthome.model.sitemap.sitemap.Text
2019-12-17 22:36:11.220 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'EntryEGPresence' for widget org.eclipse.smarthome.model.sitemap.sitemap.Text
2019-12-17 22:36:11.223 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.sitemap.Text
2019-12-17 22:36:11.225 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'LivingRoomPresence' for widget org.eclipse.smarthome.model.sitemap.sitemap.Text
2019-12-17 22:36:11.227 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'LivingRoomPresence' for widget org.eclipse.smarthome.model.sitemap.sitemap.Text
2019-12-17 22:36:11.229 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'LivingRoomPresence' for widget org.eclipse.smarthome.model.sitemap.sitemap.Text
2019-12-17 22:36:11.231 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.233 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'Misc' for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.235 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'Misc' for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.236 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'Misc' for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.239 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.241 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'SwitchBox' for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.242 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'SwitchBox' for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.244 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'SwitchBox' for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.247 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.249 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'PowerTotal' for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.251 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'PowerTotal' for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.253 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'PowerTotal' for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.255 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.257 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'PufferState' for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.258 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'PufferState' for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.260 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'PufferState' for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.266 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.267 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'MyESPs' for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.269 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'MyESPs' for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.271 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'MyESPs' for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.274 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.276 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'SafeBox' for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.278 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'SafeBox' for widget org.eclipse.smarthome.model.sitemap.sitemap.Group
2019-12-17 22:36:11.279 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item 'SafeBox' for widget org.eclipse.smarthome.model.sitemap.sitemap.Group

Yes, this difinitely works. I use it for all my lights with discrete numbers (10,25,50,75,100).

I need to see the lines around the sitemap refreshing. The only critical i see are the double quotes, maybe the forum used some different ones.

Works like a charm, even in ClassicUI (I use BasicUI, but these are interchangeable. Screenshot from ClassicUI, i just installed it):

image

These are all the same technology, just the ALERT is a string item:

Switch item=AZDL_TOGGLE label="[MAP(de.map):%s]"
Switch item=AZDL_DIMM label="" mappings=[10="10",25="25",50="50",75="75",100="100"] 			
Switch item=AZDL_COLORTEMP label="Farbtempertatur" mappings=[100="warm",50="neutral",0="kalt"]
Switch item=AZDL_ALERT label="Alarm" mappings=["NONE"="Aus","SELECT"="Kurz","LSELECT"="Lang"]