Hej
czy to powinno działać?
Założenia są takie że jeśli wykryje ruch, a światło jest zgaszone ma je zaświecić na 60s.
Po odliczeniu czasu ma je wyłączyć chyba że w tym czasie wykryje kolejny ruch to ma anulować timer i uruchomić nowy.
Wynik jest taki że światło się świeci i gaśnie po 60s ale jak wykryje ruch to chyba nie zaczyna liczyć na nowo.
rule "Motion Sensor Light Control"
when
Item C_Kuchnia changed from OFF to ON
then
var Timer timer = null
if (OswKuch.state == OFF) {
sendCommand(OswKuch, ON)
logInfo("Motion Sensor Light Control","Start timer 60s")
timer = createTimer(now.plusSeconds(60)) [|
sendCommand(OswKuch, OFF)
]
} else {
if (timer !== null) {
timer.cancel()
timer = null
logInfo("Motion Sensor Light Control","Timer anulowany")
}
logInfo("Motion Sensor Light Control","Start nowego timera 60s")
timer = createTimer(now.plusSeconds(60)) [|
sendCommand(OswKuch, OFF)
]
}
end
W logach pojawia się "start timer 60s" oraz "start nowego timera 60s" ale nigdy "timer anulowany"
var Timer timer = null
rule "Motion Sensor Light Control"
when
Item C_Kuchnia changed from OFF to ON
then
if (OswKuch.state == OFF) {
sendCommand(OswKuch, ON)
logInfo("Motion Sensor Light Control","Start timer 60s")
if (timer===null) {
timer = createTimer(now.plusSeconds(60)) [|
sendCommand(OswKuch, OFF)
timer = null
]
}
} else {
logInfo("Motion Sensor Light Control","PIR triggered one more time, light already ON")
if (timer !== null) {
logInfo("Motion Sensor Light Control","Timer counts")
timer.reschedule(now.plusSeconds(60))
logInfo("Motion Sensor Light Control","Timer reschedued for the next 60sec to midnight ;)")
}
}
end
Sorry za mały off... ale zapytam czy próbowałeś programować reguły w Blockly? Ja jestem cienki z programowania a w Blockly jestem w stanie wyklikać reguły.
Ja osobiście "graficznie" niczego nie programowałem więc nie pomogę ale jeśli zadasz w odpowiednim dziale pytanie to zazwyczaj ktoś chętnie pomoże

