Hi Rich, I hope it’s ok to post after the problem is solved with a linked question.
As I mentioned before, changing different lights on/off was fun but not very practical. What I have found is a much better use of the flip90 would be to change the brightness of the current color.
As I rotate the cube left or right it goes through my color Array List which is H,S,B. The list only changes the value of H with S and B remaining at 100.
How would I go about getting the current H,S,B value and then through the flip90 action only changing the B value and keeping the existing H and S values.
The idea being I rotate left or right to select the chosen color then flip90 to cycle through the brightness array list which might just be 10,20…90,100 for the B value.
Does that make sense?
Cheers
You don’t need an array for the brightness. You can just do the math.
To get the current brightness:
MyColorItem.getStateAs(PercentType)
or
(MyColorItem.state as HSBType).brightness // I think that's right, rely on VSCode to tell you the correct way
To count up by 10% from current:
var next_brightness = (((MyColorItem.state as HSBType).brightness as Number) + 10)
if(next_brightness > 100) next_brightness = 100
To count down by 10% from current.
var next_brightness = (((MyColorItem.state as HSBType).brightness as Number) - 10)
if(next_brightness < 0) next_brightness = 0
Hi Rich, Im sure this would have worked but it turned out that the same channel accepted both (50,100,100) for HSB and (20) ie 20% for brightness.
So rotate left or right changes color and flip changes brightness of that color.
Ended up with this.
var currState = 0
var colors = newArrayList("170,100,100", "180,100,100", "190,100,100", "200,100,100", "210,100,100", "220,100,100", "230,100,100", "240,100,100", "250,100,100", "260,100,100", "270,100,100",
"280,100,100", "290,100,100", "300,100,100", "310,100,100", "320,100,100", "330,100,100", "340,100,100", "350,100,100", "355,100,100", "10,100,100", "20,100,100", "30,100,100", "40,100,100",
"50,100,100", "60,100,100", "70,100,100", "80,100,100", "90,100,100", "100,100,100", "110,100,100", "120,100,100", "130,100,100", "140,100,100", "150,100,100", "160,100,100" )
var luma = newArrayList(1, 3, 5, 8, 12, 17, 25, 40, 70, 100)
var warmth = newArrayList(1, 5, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100)
var lights = newArrayList( [ | SW3_01_1.sendCommand(ON) SW3_01_2.sendCommand(ON) SW3_01_3.sendCommand(ON)], [ | SW3_01_1.sendCommand(OFF) SW3_01_2.sendCommand(OFF) SW3_01_3.sendCommand(OFF)
SW3_02_1.sendCommand(ON) SW3_02_2.sendCommand(ON) SW3_02_3.sendCommand(ON)], [ | SW3_02_1.sendCommand(OFF) SW3_02_2.sendCommand(OFF) SW3_02_3.sendCommand(OFF)
White_Lamps.sendCommand(ON) ], [ | White_Lamps.sendCommand(OFF) Mood_Lamps.sendCommand(ON) ], [ | Mood_Lamps.sendCommand(OFF) ] )
rule "Aqara Cube Controller"
when
Channel 'mihome:sensor_cube:04cf8c9783a3:158d00029bc4f8:action' triggered
then
var actionName = receivedEvent.getEvent()
switch(actionName) {
case "MOVE": {
All_Living.sendCommand(OFF)
Mood_Lamps.sendCommand(ON)
LoungeTVControl.sendCommand(ON)
}
case "ROTATE_RIGHT": {
if (currState <= 0) currState = -1
currState = currState + 1
val value1 = colors.get(currState % colors.size)
TV_Light_Color.sendCommand(value1)
L3_Color.sendCommand(value1)
L4_Color.sendCommand(value1)
}
case "ROTATE_LEFT": {
if (currState <= 0) currState = colors.size
currState = currState - 1
val value1 = colors.get(currState % colors.size)
TV_Light_Color.sendCommand(value1)
L3_Color.sendCommand(value1)
L4_Color.sendCommand(value1)
}
case "FLIP90": {
currState = currState + 1
val value2 = luma.get(currState % luma.size)
TV_Light_Color.sendCommand(value2)
L3_Color.sendCommand(value2)
L4_Color.sendCommand(value2)
}
case "FLIP180": {
currState = currState + 1
val value3 = warmth.get(currState % warmth.size)
L3_Temperature.sendCommand(value3)
L4_Temperature.sendCommand(value3)
TV_Light_White.sendCommand(value3)
}
//Turns OFF the Mood Lamps
case "TAP_TWICE": {
TV_Light_Color.sendCommand(OFF)
L3_Color.sendCommand(OFF)
L4_Color.sendCommand(OFF)
}
//Cycle through various light Scene combinations
case "SHAKE_AIR": {
currState = currState + 1
val func = lights.get(currState % lights.size)
func.apply()
}
//case "FREE_FALL": {
// HouseCheck.sendCommand(ON)
//}
//case "ALERT": {
// HouseCheck.sendCommand(ON)
//}
}
end
Please feel free to re write using your method.
James