I’m wanting to effectively power down the ‘living room’ 30 minutes after the TV goes off… but I’m struggling.
The items are all working, but It’s the rule I’m struggling with.
I’ve tried the following concoctions;
rule "BlahBlahCar"
when
Item SamsungTV received command
then
if(receivedCommand==ON) {
if(tSamsungPower==null) {
// first ON command, create a timer to turn the light off
tSamsungPower = createTimer(now.plusSeconds(20)) [|
sendCommand(Hue_LivingRoom_MainLight, OFF)
]
} else {
// subsequent ON command, so reschedule the existing timer
tSamsungPower.reschedule(now.plusSeconds(20))
}
} else if(receivedCommand==OFF) {
// remove any previously scheduled timer
if(tSamsungPower!=null) {
tSamsungPower.cancel
tSamsungPower = null
}
}
end
^^ This one works when I the Samsung TV is detected as being ON, unfortunately, this is the exact opposite of what I want. I thought simply switching the receivedCommand==ON to with OFF and vice versa, would do the job. It doesnt
So I tried both off, with no luck.
rule "BlahBlahCar"
when
Item SamsungTV received command
then
if(receivedCommand==OFF) {
if(tSamsungPower==null) {
// first OFF command, create a timer to turn the light off
tSamsungPower = createTimer(now.plusSeconds(20)) [|
sendCommand(Hue_LivingRoom_MainLight, OFF)
]
} else {
// subsequent ON command, so reschedule the existing timer
tSamsungPower.reschedule(now.plusSeconds(20))
}
} else if(receivedCommand==OFF) {
// remove any previously scheduled timer
if(tSamsungPower!=null) {
tSamsungPower.cancel
tSamsungPower = null
}
}
end
and then I tried
rule "Turn Downstairs Lights off 5 minutes after Onkyo goes off"
when
Item onkyoPower received command
then
if(receivedCommand==ON) {
if(tOnkyoPower==null) {
tOnkyoPower = createTimer(now.plusSeconds(300)) [|
sendCommand(Hue_LivingRoom_MainLight, OFF)
sendCommand(Hue_LivingRoom_Lamp, OFF)
sendCommand(Hue_LivingRoom_TallLamp, OFF)
]
} else {
tOnkyoPower.reschedule(now.plusSeconds(300))
}
} else if(receivedCommand==OFF) {
if(tOnkyoPower==null) {
tOnkyoPower = createTimer(now.plusSeconds(300)) [|
sendCommand(Hue_LivingRoom_MainLight, OFF)
sendCommand(Hue_LivingRoom_Lamp, OFF)
sendCommand(Hue_LivingRoom_TallLamp, OFF)
]
} else {
tOnkyoPower.reschedule(now.plusSeconds(300))
}
}
end
Again with no luck. Which is why I’m now here, asking for help/advice.
The variables exist, the timer in the first example works absolutely fine with lights on a motion sensor, so I’m not entirely sure what I’m missing.
If anything, the timer is too complex. I simply need to turn off the lights/other items after X amount of minutes, I don’t need to perform any other checks.
Any thoughts?