now i will add an virtual switch for manuall stop the rule.
in words, if flagItemsunset is on ore Light_Sensore_Outdoore is less then 10 and the dummyswitch is ON, than do …
Another thing is: As you check if it’s sunset or darker than some threshold, how should the lights react if the sun raises? shall the lights keep being on or should they be shutdown? The rule would be slightly different:
i have the light sensor only if it is a rainy day or thunderstorms.
it is ok if the light comes on just because a cloud passes by.
I just want to have an additional switch that disables the rule, maybe i need it sometimes
I had the same mistake in a similar rule. After some testing, I was able to solve it by following Vincent’s train of thought. Here’s my code, I hope it helps.
var Timer Motion_Flur_timer = null
val int timeoutSeconds = 60 // choose an appropriate value
rule "FlurLicht an"
when
Item HueSensor_2_Motion changed to ON
then
if (Motion_Flur_timer === null && (vEsWirdNacht.state == ON && gFlur.state == OFF )) {
logInfo("FlurBewegung","--> Bewegung nach Sonnenuntergang im Flur. Schalte Licht ein")
gFlur.sendCommand (1)
Motion_Flur_timer = createTimer(now.plusSeconds(timeoutSeconds ), [|
gFlur.sendCommand(OFF)
logInfo("FlurLicht","--> Schalte Licht im Flur wieder aus")
Motion_Flur_timer = null
])
}
else if (vEsWirdNacht.state == ON) {
Motion_Flur_timer.reschedule(now.plusSeconds(timeoutSeconds ))
logInfo("FlurLicht","--> Weitere Bewegung im Flur, Timer erneut auf 60 Sekunden gesetzt")
}
else {
logInfo("FlurLicht","--> Bewegung erkannt, aber noch Tag: Nichts zu tun")
}
end
Had the same error here. Was also related to rescheduling a timer that was set to ‘null’. My code here for a motion detector. Make sure to take a good look at the ‘else’ clause.
rule "Verlichting berging (MOTION ON)"
when
Channel "mqtt:topic:MyMQTTBroker:GPIO06:GPIO06_IN9" triggered ON
then
logInfo("Verlichting berging", "Motion detected in berging (MOTION)")
var Timeout = 60 // Timeout for motion sensor in seconds
// Only turn on the light using motion if:
// - The previous timer has expired
// - The previous timer is null
// - The light was not already turned on manually
// Do not confuse NULL with null (NULL = unitialized, null = does not exist)
// When comparing with null, use === or !==. For all the rest use == or !=
if(TimerVerlichtingBerging === null && VerlichtingBerging == 1)
{
logInfo("Verlichting berging", "Verlichting berging ON (MOTION)")
Led17_4.sendCommand(ON)
Led18_4.sendCommand(ON)
Led10_4.sendCommand(ON)
GPIO05_OUT02.sendCommand(ON)
VerlichtingBerging = 0
TimerVerlichtingBerging = createTimer(now.plusSeconds(Timeout),
[
logInfo("Verlichting berging", "Verlichting berging OFF (MOTION TIMER)")
Led17_4.sendCommand(OFF)
Led18_4.sendCommand(OFF)
Led10_4.sendCommand(OFF)
GPIO05_OUT02.sendCommand(OFF)
VerlichtingBerging = 1
TimerVerlichtingBerging = null
])
}
else if (TimerVerlichtingBerging !== null && VerlichtingBerging == 0)
{
logInfo("Verlichting berging", "Verlichting berging (Reschedule MOTION TIMER)")
TimerVerlichtingBerging.reschedule(now.plusSeconds(Timeout))
}
end