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

Hi,

I think I have an error in my rule, which is not firing, maybe someone can give me a hint:
I have a multi-state switch in habpanel which I want to control different hue scenes with in different rooms.
Hence I have for every room a different string to control the scene which should fire:

rule "Ambient Lighting Multi-Room"

when

    Item AllLightsSwitchGroupTEST received command 

then 

switch(AllLightsSwitchGroupTEST.state) {

        case "WOHNZIMMER":

          WohnzimmerSceneGroup.sendCommand("uPJnmIlnGampnc9") 

        case "SCHLAFZIMMER":

          SchlafzimmerSceneGroup.sendCommand("RAUVTF2yWhIGteB")

        case "KITCHEN": 

            KitchenSceneGroup.sendCommand("UOZLNugWZqJKHUJ")

        case "OFFICE":

            OfficeSceneGroup.sendCommand("wld0q4iKiCQNo46") 

    }

end

So question is what is the best way to set the strings for the scenes here? I am asking because the orginating switch in habpanel is an item like this:

Items are like this: 

    Switch AllLightsSwitchGroupTEST "Wohnung Farbige Beleuchtung Alle RĂ€ume" { homekit="Switchable" }

String SchlafzimmerSceneGroup "Schlafzimmer Szene Gruppe" { channel="hue:group:0017882202f2:6:scene" }
String WohnzimmerSceneGroup "Wohnzimmer Szene Gruppe" { channel="hue:group:0017882202f2:4:scene" }
String OfficeSceneGroup "Office Szene Gruppe" { channel="hue:group:0017882202f2:8:scene" }
String KitchenSceneGroup "KĂŒche Szene Gruppe" { channel="hue:group:0017882202f2:5:scene" }

The basic rules for this already work fine for all rooms at once but I think the first rule above is not firing because it does not get a string in the first place correct?

rule "Ambient Lighting All Lights ON"

when

    Item AllLightsSwitchGroupTEST received command ON

then

{

            WohnzimmerSceneGroup.sendCommand("uPJnmIlnGampnc9") 

            SchlafzimmerSceneGroup.sendCommand("RAUVTF2yWhIGteB")

            KitchenSceneGroup.sendCommand("UOZLNugWZqJKHUJ")

            OfficeSceneGroup.sendCommand("wld0q4iKiCQNo46") 

         }   

end
1 Like

Like you wrote in the title of the topic the rule might not fire because you didn’t cast the sate to a String

Try

switch(AllLightsSwitchGroupTEST.state.toString) { ... }

A rule like yours (with a toString) is working for me.

Thanks mate, I adapted this rule like this before but the rule doesnt fire at all.

rule "Ambient Lighting Multi-Room"

when

    Item AllLightsSwitchGroupTEST received command 

then 

switch(AllLightsSwitchGroupTEST.state.toString) {

        case "WOHNZIMMER":

          WohnzimmerSceneGroup.sendCommand("uPJnmIlnGampnc9") 

        case "SCHLAFZIMMER":

          SchlafzimmerSceneGroup.sendCommand("RAUVTF2yWhIGteB")

        case "KITCHEN": 

            KitchenSceneGroup.sendCommand("UOZLNugWZqJKHUJ")

        case "OFFICE":

            OfficeSceneGroup.sendCommand("wld0q4iKiCQNo46") 

    }

end

The item itself works but not with this rule, the log doesnt say anything
 Any ideas?

I believe the problem is that your item is a switch, which can only accept OnOff commands (unless that has changed in OH3?). You need to change it to a string, and then your original case statement should work.

Furthermore you should add some logInfo's to debug your code.


Additionally you can add a default to your switch to debug further:

switch (System_SSH_LetzteFehlgeschlageneIP.state.toString) {
        case "1", case "2" : { text = text + "(1)" }
        case "3" : { text = text + "(3)" }
        case "4" : { text = text + "(4)" }
        case "5" : { text = text + "(5)" }
        default: { text = text + "(6)" }
    }
2 Likes

Thanks so that did the trick, I changed the item to string and the rule now accepts it:

2020-12-30 10:34:25.618 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'AllLightsSwitchGroupAmbient' received command  WOHNZIMMER

BUT I think my logic is twisted here:

After the item received the command WOHNZIMMER it should send a command to another item but I think the command WOHNZIMMER in this case will always only be received by the above source (AllLightsSwitchGroupAmbient) item right?

Because in this case when I pick WOHNZIMMER in habpanel for the item AllLightsSwitchGroupAmbient, it should fire WohnzimmerSceneGroup.sendCommand("uPJnmIlnGampnc9")

rule "Ambient Lighting Multi-Room"

when

    Item AllLightsSwitchGroupAmbient received command 

then 

switch(OfficeSceneGroup.state.toString) {

        case "ALL":

          WohnzimmerSceneGroup.sendCommand("ON") 

        case "WOHNZIMMER":

          WohnzimmerSceneGroup.sendCommand("uPJnmIlnGampnc9") 

        case "SCHLAFZIMMER":

          SchlafzimmerSceneGroup.sendCommand("RAUVTF2yWhIGteB")

        case "KITCHEN": 

            KitchenSceneGroup.sendCommand("UOZLNugWZqJKHUJ")

        case "OFFICE":

            OfficeSceneGroup.sendCommand("wld0q4iKiCQNo46") 

    }

end

That’s because you’re calling the wrong item in your switch statement. :wink:

This should be:

switch(AllLightsSwitchGroupAmbient.state) {

Also, since the item is now a string, you don’t need .toString.

1 Like

It takes time for a command to affect the state of an Item (if it ever does), these are not the same thing in openHAB.
You could arrange some kind of delay after triggering from the command before examining the state of whichever Item you expect to be altered.
or
You could directly examine the command in your rule.

Implicit variable receivedCommand

1 Like

Still do not quite get it, you mean I have to work with a delay in my rule because otherwise it will not be ececuted because of the .state?

Currently it’s like this:

2021-01-10 17:15:07.103 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'AllLightsSwitchGroupAmbient' received command  WOHNZIMMER

2021-01-10 17:15:07.112 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘iphone12battery’ changed from 27.000001072883606 to 25.999999046325684

2021-01-10 17:15:09.428 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘AllLightsSwitchGroupAmbient’ received command WOHNZIMMER

rule "scene"
when
Item AllLightsSwitchGroupAmbient received update
then
switch (AllLightsSwitchGroupAmbient.state)
{
case "WOHNZIMMER" : sendCommand(WohnzimmerSceneGroup,"uPJnmIlnGampnc9")
}
end

But the rule does not fire even at this point after receiving the command. So you’re saying I need a delay there? Thanks for your help

Is that a Group type Item?

You generally need to be careful triggering rules from Group state updates, because they can happen more often than you expect. A Group state is calculated from the aggregated states of its members.

However - I would guess you have a more basic problem with that though - a Group has no state unless you tell it how to calculate from member states, i.e. define a Group subtype and an aggregation function.
Left to default, a Group state never updates at all.
Even if you send the Group commands.

I have little idea what you are trying to do, what you expect to happen. I can see pitfalls in your rules.

Let me give example of how openHAB works and you may see some light for yourself.

  1. Send a command to a Group type Item.
    after a short time -
  2. openHAB will pass the command to a group member Item.
    after a short time -
  3. openHAB will pass the command to the next member Item etc. etc.
    after some variable time -
  4. A member Item may respond to the command and update or change it’s state
    after some time -
    4-A. If the Group has an aggregate function, it will recalculate and update its own state, derived from all member states.
    after some time -
  5. Another member Item may respond to command and update its state
    after some time -
    5-A. The Group may update, if aggregation defined.

You can trigger a rule at various points in this chain of events - but of course the chain may not yet have finished when your rule runs.
For example, if you trigger off Group command almost certainly nothing else has happened yet.

When do you need to “do stuff”?

Thanks @rossko57, I had read about the Group Type issue and have a String here.
The reason was to just have some kind of helper item that gets passed state to be able to select different commands by the habpanel selection widget :slight_smile:

String AllLightsSwitchGroupAmbient "Wohnung Farbige Beleuchtung Alle RĂ€ume 2" { homekit="Switchable" }

Maybe there is a complete different approach and I am looking in the wrong style here?
I thought, that with the habpanel selection widget I want to be able seperately choose to fire seperate commands independant from the original Switch item in habpanel (like above in the rule)

So let’s try to workout what you need to happen.

Your post #2 looks pretty good to me, once Item type sorted out; triggering from command from UI and using switch-case to select an action to take.
The problem with it was using state not command, you want to switch-case on the receivedCommand directly.

I’ve now realized the Item with Group in the name is not a Group.
You don’t care about it’s state at all, really (though you might use it in your UI)

Hi @rossko57

I have changed it to receivedCommand and the logic is clear now but still I cannot get it work and did not find that much docs regarding receivedCommand?

rule "scene"

when

Item AllLightsSwitchGroupAmbient received update

then

switch (AllLightsSwitchGroupAmbient.receivedCommand)

{

case "WOHNZIMMER" : sendCommand(WohnzimmerSceneGroup,"uPJnmIlnGampnc9")

}

end

Log:

2021-01-23 11:04:53.779 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'ambientlighting-3' failed: 'receivedCommand' is not a member of 'org.openhab.core.library.items.StringItem'; line 63, column 9, length 43 in ambientlighting

That’s what was suggested, however you are using received update, that way the rule doesn’t have the variable receivedCommand, hence the error!

So is it then received command ?

Sorry, I am a little bit confused by the rules DSL

Same error when I am using received command instead of update

rule "scene"

when

Item AllLightsSwitchGroupAmbient received command

then

switch (AllLightsSwitchGroupAmbient.receivedCommand)

{

case "WOHNZIMMER" : sendCommand(WohnzimmerSceneGroup,"uPJnmIlnGampnc9")

}

end

Thanks for your help

receivedCommand is in implicit variable, it “belongs” to the rule not the Item, it is the command that triggered the rule.

switch (receivedCommand)

“Implict variables” -

1 Like

Missed that part of the error, sorry!

Okay, I have changed it again, the command is received but the case item does not get fired:

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

rule "scene"

when

Item AllLightsSwitchGroupAmbient received command

then

switch (receivedCommand)

{

case "WOHNZIMMER" : sendCommand(WohnzimmerSceneGroup,"uPJnmIlnGampnc9")

}

end

So, WohnzimmerSceneGroup does not change like it supposed to do.
When I test WohnzimmerSceneGroup as a switch in habpanel, it does fire though.

Still puzzled :frowning: