I wrote my question already in the topic of this thread:
I want to switch on a light when the motion sensor detects motion but only after a certain time. (The light shall be turned on when I leave my bedroom in the morning, but not before 6 a.m. and not during the night, e.g. when I go to the toilet.)
So, my focus is the time polling. Do I use “Time cron” for this?
rule "limited light"
when
Item motionSensor changed to ON
then
if (now.getHourOfDay() >= 6 && now.getHourOfDay() < 23) {
lightItem.sendCommand(ON)
}
end
rule "limited light"
when
Item motionSensor changed to ON
then
if (now.getMinuteOfDay() >= 330 && now.getHourOfDay() < 23) {
lightItem.sendCommand(ON)
}
end
This rule will go wrong on the date the time changes.
The work around is:
rule "limited light"
when
Item motionSensor changed to ON
then
if (now.getMinuteOfDay() >= now.withTimeAtStartOfDay.plusDays(1).minusMinutes(1110).getMinuteOfDay() && now.getHourOfDay() < 23) {
lightItem.sendCommand(ON)
}
end
We compare to the minute from now.withTimeAtStartOfDay.plusDays(1) midnight tonight take away 1440 minutes in a days less 330 minutes (05:30) = 1100 minutes