My Items File is:
//Boton Mesita Salon
Number Switch_Battery { channel=“mihome:sensor_switch:158d0001xxxf8d:batteryLevel” }
Switch Switch_BatteryLow { channel=“mihome_sensor_switch_158d000xxx1f8d:lowBattery” }
rule "Xiaomi Switch Mesita Salon separado 1 click "
when
Channel “mihome_sensor_switch_158d0001xxxf8d:button” triggered SHORT_PRESSED
then
var actionName = receivedEvent.getEvent()
switch(actionName) {
case "SHORT_PRESSED": {
SalonColor_OnOff.sendCommand(OFF)
}
}
end
rule "Xiaomi Switch Mesita SALON DOBLE click "
when
Channel “mihome_sensor_switch_158d0001xxxf8d:button” triggered DOUBLE_PRESSED
then
if (SalonColor_OnOff.state == OFF) {
SalonColor_OnOff.sendCommand(ON)
} else {
SalonColor_OnOff.sendCommand(OFF)
}
end
As vzorglub mentioned, please use code fences, it makes it a lot easier to read your code.
As for your issue.
Firstly, if you use 'triggered SHORT_PRESSED", you don’t have to check the received event, because it will only trigger on that event.
And also, there is a syntax error in your channel I think.
“mihome_sensor_switch_158d0001xxxf8d:button” should be “mihome:sensor_switch:158d0001xxxf8d:button”
Note the ‘:’ colon after mihome, rather than an underscore. The same after switch.
So your rule should effectively be:
rule "Xiaomi Switch Mesita Salon separado 1 click "
when
Channel “mihome:sensor_switch:158d0001xxxf8d:button” triggered SHORT_PRESSED
then
SalonColor_OnOff.sendCommand(OFF)
end
And it should work I believe.
An even better way for both rules:
rule "Xiaomi Switch Mesita Salon separado clicks "
when
Channel “mihome:sensor_switch:158d0001xxxf8d:button” triggered
then
var actionName = receivedEvent.getEvent()
switch(actionName)
{
case "SHORT_PRESSED":
{
SalonColor_OnOff.sendCommand(OFF)
}
case "LONG_PRESSED":
{
if (SalonColor_OnOff.state == OFF)
{
SalonColor_OnOff.sendCommand(ON)
}
else
{
SalonColor_OnOff.sendCommand(OFF)
}
}
}
end
Braces might be too much for single lines, but its easier to read for this example.
Then you’ll have to check logs, and see if there are any errors listed.
If you can’t see any errors, perhaps add a logInfo or two in your rule to check up to where it executes.
But check for errors first, most likely there is an error somewhere.