you properbly already made the code for this, but there is my old code:
for light change:
rule "Xiaomi Cube change light"
//two cube modes changed by flip 90 degress 0 = intensity, 1 = color
when
Item CubeAngel changed
then
if (CubeMode.state == 0) // change intensity
{
logInfo("rules", "Cube - Xiaomi Cube change light rule - intensity mode")
// for hue lights
gLights_color_hue.members.forEach[ s |
//logInfo("rules", "Current item "+ s.name)
var HSBType CurrentState
var DecimalType Current_H
var PercentType Current_S
var PercentType Current_B
CurrentState = s.state as HSBType
Current_H = CurrentState.hue
Current_S = CurrentState.saturation
Current_B = CurrentState.brightness
//logInfo("rules", "Current CurrentIntBritness "+ Current_B)
//need to have a variable witht the state
var Number Angel = CubeAngel.state
var Number New_B = Current_B + Angel
//set limits
if (New_B >= 100) { New_B = 100 }
if (New_B <= 0) { New_B = 0 }
//logInfo("rules", "New_B:" + New_B)
var String color = Current_H + "," + Current_S + "," + New_B
s.sendCommand(color)
]
//logInfo("rules", "--------------None hue lights--------------------")
// for miHome and Yeelights
gLights_Britness.members.forEach[ s |
//logInfo("rules", "Current item " + s.name + "state: " + s.state)
var Number Current_B
if(s.state == NULL){
//logInfo("rules", "set britness to 20 ")
Current_B = 20}
else { Current_B = s.state }
//logInfo("rules", "Current CurrentIntBritness "+ Current_B)
//need to have a variable witht the state
var Number Angel = CubeAngel.state
var Number New_B = Current_B + Angel
//set limits
if (New_B >= 100) { New_B = 100 }
if (New_B <= 0) { New_B = 0 }
//logInfo("rules", "New_B:" + New_B)
//new DecimalType()
//s.sendCommand(new DecimalType(New_B))
//sendCommand.s(New_B)
s.sendCommand(New_B)
]
}
if (CubeMode.state == 1) // change color
{
logInfo("rules", "Cube Xiaomi Cube change light rule color mode")
logInfo("state", "Cube new angel "+CubeAngel.state)
gLights_color.members.forEach[ s |
var HSBType CurrentState
CurrentState = s.state as HSBType
//CurrentState = Vindue_Color.state as HSBType
var DecimalType new_H = CurrentState.hue
var DecimalType CurrentIntColor = new_H
//logInfo("rules", "Current CurrentIntColor "+CurrentIntColor)
//need to have a variable witht the state
var Number Angel = CubeAngel.state
var Number NewIntColor
NewIntColor = CurrentIntColor + Angel
//set limits
if (NewIntColor > 255) {
//logInfo("rules", "NewIntColor > 255 substracting 255 : " + NewIntColor)
NewIntColor = NewIntColor -255 }
if (NewIntColor < 0) {
//logInfo("rules", "NewIntColor < 0 adding 255: " + NewIntColor)
NewIntColor = NewIntColor + 255 }
//logInfo("state", "NewIntColor "+NewIntColor)
var String RGB
//var HSBType hsb = HSBType::fromRGB(NewIntColor.intValue,100,100)
RGB = NewIntColor + ",100,20"
s.sendCommand(RGB)
]
}
end //-----------------------------------------------
Volume on chromecast:
rule "CubeChangeVolume: Xiaomi Cube flip180 (mode 2) and change angel "
when
Item CubeAngel received update
then
if (CubeMode.state == 2) // change volume, triggered by flip 180
{
logInfo("rules", "CubeChangeVolume: Xiaomi Cube flip180 (mode 2) and change angel")
//get current Volume
//var Number CurrentIntVolume = CC_all_audioGroup_Volume.state
//use stue anlæg as referance
var Number CurrentIntVolume = CC_all_audioGroup_Volume.state
//logInfo("rules", "CC_all_audioGroup_Volume: "+CC_all_audioGroup_dimmer.state)
if (CurrentIntVolume == NULL) {CurrentIntVolume = 0}
logInfo("state", "Cube new angel "+CubeAngel.state)
//logInfo("rules", "Current CurrentIntVolume "+CurrentIntVolume)
//logInfo("state", "Cube new angel "+CubeAngel.state)
//need to have a variable witht the state
var Number Angel = CubeAngel.state
var Number NewIntVolume = CurrentIntVolume + (Angel / 4)
//NewIntVolume = java.lang.Math.floor(NewIntVolume)//allow only whole numbers
//set limits
if (NewIntVolume > 100) { NewIntVolume = 100 }
if (NewIntVolume < 0) { NewIntVolume = 0 }
CC_all_audioGroup_Volume.sendCommand(NewIntVolume)
//CC_All_Volume_Dimmer.members.forEach[ s | s.sendCommand(NewIntVolume) ]
}
end
pause via free fall chromcast:
rule "CubeFreeFallAndMove: freefall "
when
Channel 'mihome:sensor_cube:158d0001135c14:action' triggered
then
var actionName = receivedEvent.getEvent()
switch(actionName) {
case "FREE_FALL": { //pause/play CC
if (CC_all_audioGroup_control.state == PLAY) {
//CC_all_audioGroup_control.sendCommand(PAUSE)
CC_All_Player_Control.members.forEach[ s | s.sendCommand(PAUSE)
]
}
else //CC_all_audioGroup_control.sendCommand(PLAY)
CC_All_Player_Control.members.forEach[ s | s.sendCommand(PLAY) ]
}
}
end
Proxy item control:
rule "Cube proxy rule CubeAngelWhite1"
when
Item CubeAngelWhite1 received update
then
CubeAngel.state = CubeAngelWhite1.state
end
rule "Cube proxy rule CubeAngelWhite2"
when
Item CubeAngelWhite2 received update
then
CubeAngel.state = CubeAngelWhite2.state
end
Change radio channel via cube on chromecast
rule "Xiaomi Cube change Radio channel"
//two cube modes changed by flip 90 degress 0 = intensity, 1 = color, 2 sound level, 3 = radio channel
when
Item CubeAngel changed
then
if (CubeMode.state == 3) // change channel
{
logInfo("rules", "Cube - Xiaomi Cube change Radio channel - cube mode 3")
//CONFIRM mode 10004=check 10002 =vælgradio
logInfo("state", "Cube new angel "+CubeAngel.state)
//need to have a variable witht the state
var Number CubeAngel = CubeAngel.state
var String ChannelURL
var String ChannelName
//set limits
if (CubeAngel > 360) { CubeAngel = 360 }
if (CubeAngel < -360) { CubeAngel = -360 }
// 4 channels
// 1: 0-90
// 2: 90 +
// 3: 0- (-90)
// 4: -90 +
if (CubeAngel < -90) { NbChromcastRadioChannelNumber.sendCommand(4) }
else if (CubeAngel > -90 && CubeAngel <= 0) {NbChromcastRadioChannelNumber.sendCommand(3)}
else if (CubeAngel > 0 && CubeAngel <= 90){ NbChromcastRadioChannelNumber.sendCommand(2)}
else if (CubeAngel > 90){ NbChromcastRadioChannelNumber.sendCommand(1)}
logInfo("rules","Radio channel = " + NbChromcastRadioChannelNumber.state)
// get interpede channel number
}
end //-----------------------------------------------
flip and move modes:
rule "Xiaomi Cube flip "
when
Channel 'mihome:sensor_cube:158d0001135c14:action' triggered or
Channel 'mihome:sensor_cube:158d0001108110:action' triggered
then
//logInfo("rules", "Xiaomi cube set mode")
var actionName = receivedEvent.getEvent()
switch(actionName) {
case "FLIP90": {
logInfo("rules", "case flip90 start")
if (CubeMode.state == 1) {
CubeMode.sendCommand(0)
// XiaomiMiSmartHomeGateway_SoundVolume.sendCommand(30)
// XiaomiMiSmartHomeGateway_SoundSelector.sendCommand(10004)
}
else{
CubeMode.sendCommand(1)
// XiaomiMiSmartHomeGateway_SoundVolume.sendCommand(30)
// XiaomiMiSmartHomeGateway_SoundSelector.sendCommand(10004)
}
}
case "FLIP180": {
if (CubeMode == 2) {CubeMode.sendCommand(0)
//logInfo("rules", "Cube new angel "+CubeMode.state)
// XiaomiMiSmartHomeGateway_SoundVolume.sendCommand(30)
// XiaomiMiSmartHomeGateway_SoundSelector.sendCommand(10004)
}
else {
CubeMode.sendCommand(2)
// logInfo("rules", "Cube new angel "+CubeMode.state)
// XiaomiMiSmartHomeGateway_SoundVolume.sendCommand(30)
// XiaomiMiSmartHomeGateway_SoundSelector.sendCommand(10004)
}
}
case "MOVE": {
// XiaomiMiSmartHomeGateway_SoundVolume.sendCommand(30)
// XiaomiMiSmartHomeGateway_SoundSelector.sendCommand(10004)
CubeMode.sendCommand(3) //select radio channel
// logInfo("rules", "Cube new angel "+CubeMode.state)
}
}
end
air shake and tap twice:
rule "Xiaomi Cube air shake and tap twice"
when
Channel 'mihome:sensor_cube:158d0001135c14:action' triggered or
Channel 'mihome:sensor_cube:158d0001108110:action' triggered or
Channel 'mihome:sensor_cube:158d00011813ed:action' triggered
then
var actionName = receivedEvent.getEvent()
switch(actionName) {
case "TAP_TWICE": {
logInfo("state", "TAP_TWICE rule started")
//gLights_effect_SW.sendCommand(OFF)
//All_Lights_color_temperature_dimmer.members.forEach[ s | s.sendCommand(80) Thread::sleep(100) ]
//String Hue , sat , Britness
gLights_color.sendCommand("0,0,60")
gLights_Color_temperature_dimmer.sendCommand(60)
CubeLightMode.sendCommand(0)
//CubeLightMode.postUpdate(0)
}
case "SHAKE_AIR": {
if(SwPartyMode.state != ON){SwPartyMode = ON}
else
{SwPartyMode = OFF}
/*
gLights_color.members.forEach[light|
//(new_H,new_S,new_B)
sendCommand(light, (((Math::random * 255).intValue)) + "," + (((100.intValue))) + "," + (((30.intValue))))
Thread::sleep(100)
]
*/
}
}
end
hope you can use it for inspiration maybe.