Hello everyone,
I’m looking for ideas and impulses to improve on a ruleset.
I want to have a group of light items with color and brightness. I then want to change all lights in this group to HSBType::RED when an alert item triggers and back to the state they had before when the alert is turned off.
I have implemented that for two lights “by hand” but would like to have that over a whole group of lights.
Additionally I have an issue with the rule below:
Imagine the alert light was set to a color but is turned off. Now when I send brightness is set to 100 it lights up in the last set color. After the alert triggered once the light will be red if brightness is set to 100. Note that if the light was on it reverts to its previous color and brightness correctly.
So in summary two questions:
- How do I change the light via a rule but “remember” the exact previous state (variable HSType seems to be not enough)
- How can I achieve this for a whole group of lights?
Thanks in advance!
The rule in question:
var Timer lightTimer = null
var Boolean gateTimerRunning = false
var Boolean warning = false
var HSBType hsb = null
var Number dimmer = 0
rule "GateOpen"
when
Item stairGateOpen received update or
Item cellarDoor received update or
Item vBabySleepMode received command OFF
then
if (!gateTimerRunning && vBabySleepMode.state == OFF) {
gateTimerRunning = true
createTimer(now.plusSeconds(5), [ |
if (stairGateOpen.state == CLOSED && cellarDoor.state == CLOSED && warning) {
wzIndirectLightColor.sendCommand(hsb)
hsb = null
stairGateLight.sendCommand(OFF)
warning=false
}
else if (!warning && (stairGateOpen.state == OPEN || cellarDoor.state == OPEN)) {
warning = true
hsb = wzIndirectLightColor.state
stairGateLightBrightness.sendCommand(80)
wzIndirectLightColor.sendCommand(HSBType::RED)
}
gateTimerRunning = false
])
}
end
The two light items for completeness sake:
Dimmer wzIndirectLightDimmer "Wohnzimmer Indirektes Licht" <light> (gLivingroomLights, gWZIndirectLight ) ["Dimmer", "Lighting"] { channel="hue:0210:huebridge:tWZIndirekt:color"}
Color wzIndirectLightColor "Wohnzimmer Indirektes Licht Farbe" <light> (gWZLightColors, gWZIndirectLight) ["Color", "Lighting"] { channel="hue:0210:huebridge:tWZIndirekt:color", alexa="Lighting"}
Switch stairGateLight "Gatter Warnlicht" <light> (gAlarmLights) ["Switch"] { channel="mqtt:topic:localBroker:tGateWarnlight:state" }
Dimmer stairGateLightBrightness "Gatter Warnlicht Brightness" <light> (gAlarmLights) ["Switch"] { channel="mqtt:topic:localBroker:tGateWarnlight:brightness" }