How to turn ON/OFF Hue Lights with Xiaomi Switch?

hue
Tags: #<Tag:0x00007fe058a39c70>

(Janinho82) #1

Hi! I Tried to do the Rule with different options but any run…guess I do something wrong and I need help.

My Hue Things File is:

Bridge hue:bridge:1 [ ipAddress=“192.168.31.xxx”, userName=“lWFDHzMMtm4Ivq5DxxxxxxxxxxBP0XG0LzH1xRYi” ]{
0100 bulb1 [ lightId=“hue:0100:00178812e354:1:brightness” ]
0100 bulb2 [ lightId=“hue:0100:00178812e354:2:brightness” ]
0210 bulb3 [ lightId=“hue:0210:00178812e354:3:color” ]
}

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” }

// Hue Philips Salon Color
Switch SalonColor_OnOff { channel=“hue:0210:00178xxxe354:3:color” }
Dimmer SalonColor_Temperature { channel=“hue:0210:00178xxxe354:3:color_temperature” }
Color SalonColor { channel=“hue:0210:00178xxxe354:3:color” }
Dimmer Light1_ColorTemp { channel=“hue:0210:00178xxxe354:3:color_temperature” }
String Light1_Alert { channel=“hue:0210:0017xxxe354:3:color” }
Switch Light1_Effect { channel=“hue:0210:00178xxxe354:3:color” }

And my Rule file is:

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


(Vincent Regaud) #2

Hello, could you use the code fences, please?


(Carel Van Hemert) #3

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.


(Janinho82) #4

Thanks for your reply but after I change it still not working… :frowning:


(Carel Van Hemert) #5

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.