I was thinking about using a xiaomi button to change the light brightness and color temperature on one or more hue lights, by using the long press function. Did anybody try this?
So you want to use “long press” like a slider to turn brightness or color up?
Next question what about turn down the brightness or color?
Yes I was thinking about that, so during pres it would gradually change. When stopping I would reverse the effect to the opposite, or change it with double click or single click.
I did it!
Gosh so glad and happy it works
My rule increases light by 10% each 400ms. If it reaches 100 I do a reset and put it to 0. Of course you can change that bottom to 10 if you dont want to switch it off.
You can take out the logInfos. They were good to see where my faults were, e.g. I did not define the state as DecimalType at first.
Only real problem is the timelag and once it seems the release didnt go through, but nice light show
rule "XiaomiSwitch2"
when
Channel "mihome:sensor_switch:158d00015f2ae8:button" triggered
then
var actionName = receivedEvent.getEvent()
switch(actionName) {
case "SHORT_PRESSED": {
logInfo("test","1 state" + tradfri_0220_gwb072bf27be41_65545_brightness.state )
if ( tradfri_0220_gwb072bf27be41_65545_brightness.state == 0 ) {
logInfo("test","1" + tradfri_0220_gwb072bf27be41_65545_brightness.state)
sendCommand(TodesStern_Brightness , ON)
}
else if ( tradfri_0220_gwb072bf27be41_65545_brightness.state > 0) {
logInfo("test","2" + tradfri_0220_gwb072bf27be41_65545_brightness.state)
sendCommand(TodesStern_Brightness , OFF)
}
}
case "DOUBLE_PRESSED": {
logInfo("test","3")
}
case "LONG_PRESSED": {
logInfo("test","4")
SwitchLRPressedLong = true
while (SwitchLRPressedLong){
brightnessLR = (tradfri_0220_gwb072bf27be41_65545_brightness.state as DecimalType).intValue
logInfo("test","wz long " + tradfri_0220_gwb072bf27be41_65545_brightness.state + " " + brightnessLR)
brightnessLRTarget = brightnessLR + 10
logInfo("test","wz long " + tradfri_0220_gwb072bf27be41_65545_brightness.state + " " + brightnessLR)
if (brightnessLRTarget > 99) {
brightnessLRTarget = 0
}
logInfo("test","wz long 2 " + tradfri_0220_gwb072bf27be41_65545_brightness.state + " " + brightnessLRTarget)
sendCommand(TodesStern_Brightness , brightnessLRTarget)
Thread::sleep(400) // experiment with the value to control dimming speed
}
}
case "LONG_RELEASED": {
SwitchLRPressedLong = false
logInfo("test","5 long released")
}
}
end
Oh dont forget to initialize the variables at the beginning of the rulefile
var boolean SwitchLRPressedLong = false
var int brightnessLR = 0
var int brightnessLRTarget = 0
Well done!
How do you trigger LONG_PRESSED or LONG_RELEASED?
Pres the for an extended time
I have aqara Switches, and no matter how long I press them I wont get this trigger …