Problem to switch group when members>1

I want to switch on/off all the lamps with one click. The lamps are switched via remote sockets and exec.binding.
Testing the config I started with only one lamp belonging to the group ALS. All ok at this stage.
Strangely, when I had added more lamps to the group, the group:switch didn’t work anymore. Also the “testing” lamp refused to react. (I just saw the unresolved post “Switch group with exec binding” that addresses the same issue).

The commands are sent to the lamps in the right way:

2016-02-28 23:03:01.856 [INFO ] [runtime.busevents ] - Nr11100_1 received command OFF
2016-02-28 23:03:01.928 [INFO ] [.o.b.exec.internal.ExecBinding] - executed commandLine 'sudo /opt/openhab/configurations/brennenstuhl/off 11100 1’
2016-02-28 23:03:01.948 [INFO ] [runtime.busevents ] - Nr11100_2 received command OFF
2016-02-28 23:03:01.955 [INFO ] [.o.b.exec.internal.ExecBinding] - executed commandLine ‘sudo /opt/openhab/configurations/brennenstuhl/off 11100 2’
… and so on

The configuration looks as follows:
Items:
Group:Switch:OR(ON, OFF) ALS “Alle Lampen [(%d)]” (All)//ALS = Alle Lampen schalten
Switch Nr11100_1 “Sofa” (ALS,EG_Wohnen, Lampen) {exec=">[OFF:sudo /opt/openhab/configurations/brennenstuhl/off 11100 1] >[ON:sudo /opt/openhab/configurations/brennenstuhl/on 11100 1]"}
… more of that kind in ALS group
Sitemap:
Switch item=ALS label=“Alle Lampen schalten” mappings=[OFF=“Aus”,ON=“An”] icon=“light-on” //ALS = Alle Lampen schalten

Strange or is there an explanation (and fix) for this?

Thanks in advance
Hans

Every time I have or see others have any sort of problem with the Exec binding my first step is to see what the exec is returning. The only way to see that is to move the exec from the Exec binding to executeCommandLine in a rule which is where you can capture the results from the command.

Item:

Switch Nr11100_1 "Sofa" (ALS,EG_Wohnen,Lampen)

Rule:

rule "Nr11100_1 Triggered"
when
    Item Nr11100_1 received command
then
    var String cmd
    if (Nr11100_1.state == ON) 
        cmd = "sudo /opt/openhab/configurations/brennenstuhl/on 11100 1"
    else
        cmd = "sudo /opt/openhab/configurations/brennenstuhl/off 11100 1"

    val String results = executeCommandLine(cmd, 5000)
    logInfo("Nr11100_1", results)
end

Nine times out of ten, something seemingly innocuous changed in your environment that is preventing the openhab user or whatever user OH is running under from correctly executing the command. Or perhaps timing is an issue and the on and off scripts do not like to be executed at the same time.

Hi Rich,
thanks for your hint which is bringing me closer to the solution I guess. I tried out your scripts and “Sofa” worked alright without any flaws.
As I am new at openHAB I have fiddled around with items only so far. Your reply made me googleing for how to do rules.
In fact a blog recommends to use rules in order to switch a group of 433 MHz switches with the exec.binding (my hardware setup). With rules he argues we can give the transmitter the necessary rest in between the different signals to the switches.
I had a try with it (building on and it doesn’t work - of course. The rule is not called up (like it was the case before with your item/rule). The OFF exec is sent without the delay as defined in the rule.

Log:

2016-02-29 23:00:42.116 [INFO ] [.o.b.exec.internal.ExecBinding] - executed commandLine 'sudo /opt/openhab/configurations/brennenstuhl/off 11100 1’
2016-02-29 23:00:42.164 [INFO ] [runtime.busevents ] - Nr11100_1 received command OFF
2016-02-29 23:00:42.172 [INFO ] [.o.b.exec.internal.ExecBinding] - executed commandLine 'sudo /opt/openhab/configurations/brennenstuhl/off 11100 2’
2016-02-29 23:00:42.190 [INFO ] [runtime.busevents ] - Nr11100_2 received command OFF
2016-02-29 23:00:42.203 [INFO ] [.o.b.exec.internal.ExecBinding] - executed commandLine 'sudo /opt/openhab/configurations/brennenstuhl/off 11100 3’
2016-02-29 23:00:42.255 [INFO ] [runtime.busevents ] - Nr11100_3 received command OFF

Rule:

rule "Switch them all at once OFF"
when
Group ALS received OFF
then
ALS?.members.forEach[Switch|
sendCommand(Switch, OFF)
Thread::sleep(2000)
]
end

Item:

Group:Switch:OR(ON, OFF) ALS “Alle Lampen [(%d)]” (All)

Sitemap:

Switch item=ALS label=“Alle Lampen aus” mappings=[OFF=“Alle aus”]

I would be very happy about some more advice of what I do wrong.
Thank you!
Hans

Group ALS received command OFF

Thank you again for helping out.
I added “command” as you told me. Apparently there is something more wrong in my files above. Still the rule is not called up.

Much appreciated
Hans

Get rid of the “?” in your “ALS?.members…” line. Add some logging to the rule. Without logging we don’t know whether the rule is indeed not triggering or if there is something else wrong.

Rule looks like this now (logInfo included):

rule "Switch them all at once to OFF"
when
Group ALS received command OFF
then
ALS.members.forEach[Switch|
sendCommand(Switch, OFF)
Thread::sleep(2000)
]
logInfo(“ALS”, results)
end

openhab.log gives me:

2016-03-01 22:49:42.188 [INFO ] [.o.b.exec.internal.ExecBinding] - executed commandLine 'sudo /opt/openhab/configurations/brennenstuhl/off 11100 1’
2016-03-01 22:49:42.213 [INFO ] [.o.b.exec.internal.ExecBinding] - executed commandLine 'sudo /opt/openhab/configurations/brennenstuhl/off 11100 2’
2016-03-01 22:49:42.241 [INFO ] [.o.b.exec.internal.ExecBinding] - executed commandLine 'sudo /opt/openhab/configurations/brennenstuhl/off 11100 3’
2016-03-01 22:49:42.282 [INFO ] [.o.b.exec.internal.ExecBinding] - executed commandLine 'sudo /opt/openhab/configurations/brennenstuhl/off 00111 1’
2016-03-01 22:49:42.318 [INFO ] [.o.b.exec.internal.ExecBinding] - executed commandLine 'sudo /opt/openhab/configurations/brennenstuhl/off 00111 2’
2016-03-01 22:49:42.380 [INFO ] [.o.b.exec.internal.ExecBinding] - executed commandLine ‘sudo /opt/openhab/configurations/brennenstuhl/off 00111 3’

Apparently the rule is not executed?

First of all, you need to tell whether the rule is being triggered you need a log statement as the first thing the rule does, not the last.

Secondly, what is results? In the context of this rule results doesn’t exist, it is meaningless, and will almost certainly generate an error. The second argument to a log statement needs to be a String and it should be meaningful.

Thirdly, another error I missed before is the “when” clause. Is should be “Item ALS received command OFF”, not “Group …”.

Fourthly, another maybe error I missed before is your use of Switch as a variable name. Switch is a special word in the Rules language and I’m not sure it is valid to override it like this.

rule "Switch them all at once to OFF"
when
    Group ALS received command OFF
then
    logInfo("ALS", "ALS rule OFF triggered")
    ALS.members.forEach[switch| 
        logInfo("ALS", "Turning off " + switch.name)
        sendCommand(switch, OFF) 
        Thread::sleep(2000) 
    ]
    logInfo("ALS", "End of ALS rule reached")
end

Another potential error is that I don’t know if that is how a Group:Switch is supposed to work. Typically when you define a Group:Switch it will appear on your sitemap as a Switch Item and when you trigger it it will send the command to all of the members. You want to override that behavior so you can put a sleep in between each command to the individual switches. Just creating a Rule will not cancel the normal behavior of the Group.

Instead of a Group use a Dummy Switch (i.e. a Switch that isn’t bound to anything). So your new Group will be:

Group ALS (All)

The dummy switch will be:

Switch ALS_Switch "Alle LAmpen [(%d)]" (All)

Your new Sitemap line will be:

Switch item=ALS_Switch label="Alle Lampen aus" mappings=[OFF="Alle aus"]

And the Rule trigger will be

when
    Item ALS_Switch received command OFF
then

Hi RIch,

After capitalizing the switch-terms in the rule the script works fine.

rule "Switch them all at once to OFF"
when
Item ALS_Switch received command OFF
then
logInfo(“ALS”, “ALS rule OFF triggered”)
ALS.members.forEach[Switch|
logInfo(“ALS”, "Turning off " + Switch.name)
sendCommand(Switch, OFF)
Thread::sleep(2000)
]
logInfo(“ALS”, “End of ALS rule reached”)
end

Thank you for your support. One more milestone taken towards home automation :slightly_smiling:

After weeks I suddenly get error messages:

2016-04-23 10:17:19.978 [INFO ] [org.openhab.model.script.ALS ] - ALS rule OFF triggered
2016-04-23 10:17:20.695 [INFO ] [org.openhab.model.script.ALS ] - Turning off Nr11100_1
2016-04-23 10:17:20.704 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ‘Auf Knopfdruck alle Lampen aus’: Could not invoke method: org.openhab.model.script.actions.BusEvent.sendCommand(org.openhab.core.items.Item,java.lang.String) on instance: null

Here is the rule as it has been working flawlessly until now.

rule "Auf Knopfdruck alle Lampen aus"
when
Item ALS_Switch received command OFF
then
logInfo(“ALS”, “ALS rule OFF triggered”)
ALS.members.forEach[Switch|
logInfo(“ALS”, "Turning off " + Switch.name)
sendCommand(Switch, OFF)
Thread::sleep(2000)
]
logInfo(“ALS”, “End of ALS rule OFF reached”)
end

What is there?

“Switch” might be an overloaded term. Try using something less likely to conflict with an already taken keyword.

Try using the sendCommand method instead of the sendCommand action

NOTE: To properly format code wrap your code with back ticks.

```
your code
```
ALS.members.forEach[ sw |
    sw.sendCommand(OFF)
    Thread::sleep(2000)
]

Switching from sendCommand method to sendCommand action put all back to normal again. No error messages anymore!
Thank you very much for the tip.

I’m glad it worked. And just for clarity of future readers, you changed from the sendCommand action (i.e. sendCommand(sw, OFF)) to the sendCommand method (i.e. sw.sendCommand(OFF)).