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:
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
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
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)" }
}
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
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.
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
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.
Send a command to a Group type Item.
after a short time -
openHAB will pass the command to a group member Item.
after a short time -
openHAB will pass the command to the next member Item etc. etc.
after some variable time -
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 -
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.
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
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)
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
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
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.