rule "EBEDLO"
when Item ebedlo_12 received command
then switch (receivedCommand)
{
case "on1": { mqtt=">[raspberrypi:cmnd/ebedlo_k/POWER1:command:*:default],
<[raspberrypi:stat/ebedlo_k/POWER1:state:default]" }
case "on2": { mqtt=">[raspberrypi:cmnd/ebedlo_k/POWER2:command:*:default],
<[raspberrypi:stat/ebedlo_k/POWER2:state:default]" }
}
end
rule "EBEDLO"
when
Item ebedlo_12 received command
then
switch (receivedCommand) {
case "on1": sonoffT1_1.sendCommand(ON)
case "on2": sonoffT1_2.sendCommand(ON)
}
end
In fact, you won’t need other items or the rule at all, just the two items sonoffT1_1 and sonoffT1_2, just link them to Switch widgets in your sitemap.
rule "EBEDLO"
when
Item ebedlo_12 received command
then
switch (receivedCommand) {
case 1 : sonoffT1_1.sendCommand(ON)
case 2 : sonoffT1_1.sendCommand(OFF)
case 3 : sonoffT1_2.sendCommand(ON)
case 4 : sonoffT1_2.sendCommand(OFF)
}
end
In this code I have four button, is this possible, to only two buttons shows? One press turn on second press turn off, and the second swich is the same?
Sure. There is possibly some trouble.
Let’s try this:
Change the number item:
Number ebedlo_12 "Ebédlő" <light> (mL,LR,gLight) { autoupdate="false" }
The sitemap:
Switch item=ebedlo_12 mappings=[1="1", 2="2"]
the rule:
rule "EBEDLO"
when
Item ebedlo_12 received command
then
switch (receivedCommand) {
case 1 : sonoffT1_1.sendCommand(if(sonoffT1_1.state != ON) ON else OFF)
case 2 : sonoffT1_2.sendCommand(if(sonoffT1_2.state != ON) ON else OFF)
}
end
Of course you don’t have any information about the actual status. An option for this:
change the rule to
rule "EBEDLO"
when
Item ebedlo_12 received command
then
var Number status = 0
switch (receivedCommand) {
case 4 : sonoffT1_1.sendCommand(if(sonoffT1_1.state != ON) ON else OFF)
case 5 : sonoffT1_2.sendCommand(if(sonoffT1_2.state != ON) ON else OFF)
}
Thread::sleep(300) // give openHAB some time...
if(sonoffT1_1.state == ON) status += 1
if(sonoffT1_2.state == ON) status += 2
ebedlo_12.postUpdate(status)
end
So, the status is in the label itself, therefor we have to use visibility to switch between different labels. As we need numbers 0 to 3 for status, we now need other numbers (4 and 5) to send the command.