[SOLVED] Hab panel multi selection widget: only first selection works with rule?

I don’t think HABPanel is the cause, please try the following:

rule "scene"
when
  Item AllLightsSwitchGroupAmbient received command
then
  switch (receivedCommand.toString) {
    case "WOHNZIMMER" : {
      WohnzimmerSceneGroup.sendCommand("uPJnmIlnGampnc9")
      logInfo("myRule_Wohnzimmer", "value receivedCommand is {}", receivedCommand.toString)
     }
    case "OFFICE": {
       OfficeSceneGroup.sendCommand("wld0q4iKiCQNo46")
       logInfo("myRule_Office", "value receivedCommand is {}", receivedCommand.toString)
    }
  default: {
      logInfo("myRule_default", "value receivedCommand is {}", receivedCommand.toString)
    }
  } 
  logInfo("myRule", "value WohnzimmerSceneGroup is {}", WohnzimmerSceneGroup.state)
  logInfo("myRule", "value OfficeSceneGroup is {}", OfficeSceneGroup.state)
end
1 Like

Thanks @opus Exact same behaviour. First one works, second choice does not.

2021-01-23 20:15:46.278 [INFO ] [.core.model.script.myRule_Wohnzimmer] - value receivedCommand is WOHNZIMMER

2021-01-23 20:15:46.281 [INFO ] [org.openhab.core.model.script.myRule] - value WohnzimmerSceneGroup is uPJnmIlnGampnc9

2021-01-23 20:15:46.283 [INFO ] [org.openhab.core.model.script.myRule] - value OfficeSceneGroup is Gj-j0tfTxuh68e6

==> /var/log/openhab/events.log <==

2021-01-23 20:15:46.271 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'AllLightsSwitchGroupAmbient' received command WOHNZIMMER

2021-01-23 20:15:46.280 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'WohnzimmerSceneGroup' received command uPJnmIlnGampnc9

2021-01-23 20:15:46.282 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'WohnzimmerSceneGroup' predicted to become uPJnmIlnGampnc9

==> /var/log/openhab/openhab.log <==

2021-01-23 20:15:47.766 [INFO ] [hab.core.model.script.myRule_default] - value receivedCommand is  OFFICE

2021-01-23 20:15:47.769 [INFO ] [org.openhab.core.model.script.myRule] - value WohnzimmerSceneGroup is uPJnmIlnGampnc9

2021-01-23 20:15:47.771 [INFO ] [org.openhab.core.model.script.myRule] - value OfficeSceneGroup is Gj-j0tfTxuh68e6

Ok. In this case I have no clue.
The code looks correct to me and I would have expected it to work.

I have relocated this thread to the habpanel section and hope someone has an idea. Maybe it is really a bug.

Just a minute here.
You CANNOT issue a command and then immediately look at the target Item state to see if it happened.
This stuff is asynchronous - sendCommand posts the request off to the openHAB bus,
That may or may not eventually do something to do the Item state - but it takes time.
Meanwhile the rule code just carries on.

When you logInfo item.state, any command won’t have been actioned yet.

Go look in your events.log to see if commands are issued.

You’ve maybe got a space e.g." OFFICE"
You can check

default: {
      logInfo("myRule_default", "value receivedCommand is x{}x", receivedCommand.toString)
    }

if it turns out that way, then make the rule foolproof

switch (receivedCommand.toString.trim) {
1 Like

Wow, so receivedCommand.toString.trim did the trick with no further changes to the rule. I honestly have no idea why this leads to working for the second choice in this case but you helped me to get it working finally :slight_smile: Thank you so much @rossko57

All .trim does is remove spaces from the beginning or end of a string.
switch/case looks for exact matches, " FRED" does not match “FRED”
Looks like HABpanel is sending " OFFICE", you can prove that with a careful logInfo.
It’ll be doing that because it thinks its been asked to do that.
Looking at an earlier widget screenshot, I see
WOHNZIMMER, OFFICE
and I think that looks suspicious.
Try
WOHNZIMMER,OFFICE

2 Likes