I’ve got different ways of triggering the same sets of lights:
- Motion sensors
- Voice command (Amazon Echo)
- OpenHAB UI, etc.
I’ve also got a system in place for “locking” lights if they’ve been triggered by the user (i.e., through voice command or other means), because I don’t want the motion sensors’ OFF
updates to turn the lights off if the user is still in the room but not moving around very much. The system works like this:
- If the user initiates the lights turning on, I update a virtual switch (a “light lock”) to
ON
, then turn on the lights - If the user initiates the lights turning off, I update the same virtual switch to
OFF
, then turn off the lights - Before a motion detector sends an
OFF
command to a group of lights, I first check the light lock’s state. If the lock isON
, then I don’t send theOFF
command; otherwise I do.
So I’m wondering if there’s a more concise way of accomplishing this. I currently maintain a “light lock” for each group of lights, and then check against this lock on every motion-sensor initiated OFF
update.
I also maintain different groups of Items for each group of lights: there’s an ALEXA_LTS_GF_OFFC
group (Alexa Lights Ground Floor Office), and an LTS_GF_OFFC
group. When Alexa initiates a light action, she’s tied to the ALEXA groups, and I check against updates on them in the Rules; the motion sensors check against updates on the LTS_GF_OFFC
group.
The system works as it should, but I can’t shake the feeling that there’s a much better way of accomplishing the same thing. I’m a couple weeks old at OpenHAB, so I’m still very much learning.
Any ideas?
Here are examples of the relevant Items & Rules:
ITEMS
// The same group of lights, controlled by two different entities
Dimmer LTS_GF_OFFC "Office Lights" <dimmer> (GF_Office, Lights) { channel="hue:0100:01178820e953:7:brightness,hue:0100:01178820e953:14:brightness" }
Dimmer ALEXA_LTS_GF_OFFC "Office Lights" <dimmer> (GF_Office, Lights) ["Lighting"] { channel="hue:0100:01178820e953:7:brightness,hue:0100:01178820e953:14:brightness" }
// The "light lock" associated with this group
LOCK_LTS_GF_OFFC "Office Light Lock" <lock> (GF_Office, SoftwareLocks)
RULES
// Here, Alexa sends a command to the group of lights associated with her current room
rule "ALEXA_LTS_GF_OFFC"
when
Item ALEXA_LTS_GF_OFFC received command
then
if (receivedCommand == OFF) {
sendCommand(LOCK_LTS_GF_OFFC, OFF)
else {
sendCommand(LOCK_LTS_GF_OFFC, ON)
}
end
// Here, the motion sensor in the same room receives an update
rule "MS_GF_OFFC"
when
Item MS_GF_OFFC changed
then
if (MS_GF_HALL.state == ON) {
sendCommand(LTS_GF_HALL, ON)
} else {
if (LOCK_LTS_GF_OFFC.state !== ON) {
sendCommand(LTS_GF_OFFC, OFF)
}
}
end