I am not good at writing code. I have many items and I write my rules over and over again to accomplish my goal for all items. I started reading about using groups but have no idea how to implement it with my simple code.
rule "RGB Buttons Mapping for Diner_Light_Left"
when
Item Diner_Light_Left_rgbColor received command
then
if (receivedCommand == ON) {
sendCommand(Diner_Light_Left_Brightness, 100)
}
else if (receivedCommand == OFF) {
sendCommand(Diner_Light_Left_Brightness, 1)
}
else if (receivedCommand == INCREASE) {
Diner_Light_Left_Brightness.sendCommand((Diner_Light_Left_Brightness.state as DecimalType) + 1)
}
else if (receivedCommand == DECREASE) {
Diner_Light_Left_Brightness.sendCommand((Diner_Light_Left_Brightness.state as DecimalType) - 1)
}
end
rule "RGB Buttons Mapping for Diner_Light_Center"
when
Item Diner_Light_Center_rgbColor received command
then
if (receivedCommand == ON) {
sendCommand(Diner_Light_Center_Brightness, 100)
}
else if (receivedCommand == OFF) {
sendCommand(Diner_Light_Center_Brightness, 1)
}
else if (receivedCommand == INCREASE) {
Diner_Light_Center_Brightness.sendCommand((Diner_Light_Center_Brightness.state as DecimalType) + 1)
}
else if (receivedCommand == DECREASE) {
Diner_Light_Center_Brightness.sendCommand((Diner_Light_Center_Brightness.state as DecimalType) - 1)
}
end
Also another rule I keep using for all items
rule "Diner_Light_Left Slider Switch"
when
Item Diner_Light_Left_Brightness changed
then
if (Diner_Light_Left_Brightness.state instanceof DecimalType) {
if ((Diner_Light_Left_Brightness.state as DecimalType) > 0 && Diner_Light_Left_Power.state != ON)
Diner_Light_Left_Power.sendCommand(ON)
else if ((Diner_Light_Left_Brightness.state as DecimalType) == 0 && Diner_Light_Left_Power.state != OFF)
Diner_Light_Left_Power.sendCommand(OFF)
}
end
rule "Diner_Light_Center Slider Switch"
when
Item Diner_Light_Center_Brightness changed
then
if (Diner_Light_Center_Brightness.state instanceof DecimalType) {
if ((Diner_Light_Center_Brightness.state as DecimalType) > 0 && Diner_Light_Center_Power.state != ON)
Diner_Light_Center_Power.sendCommand(ON)
else if ((Diner_Light_Center_Brightness.state as DecimalType) == 0 && Diner_Light_Center_Power.state != OFF)
Diner_Light_Center_Power.sendCommand(OFF)
}
end
There must be a way to not have a very very long file with code, but instead use groups,
I cannot seem to get my head around it.
maybe someone could shed some light on it