I have a problem, I want to do some stuff between 2 time periods.
when
Item XXXX received update ON
then
if (now.isAfter(now.withTimeAtStartOfDay.plusHours(19).plusMinutes(30)) && now.isBefore(now.withTimeAtStartOfDay.plusHours(20).plusMinutes(55)) {
sendCommand(YYYY, ON)
}
end
this isn’t working but this is:
when
Item XXXX received update ON
then
if (now.isAfter(now.withTimeAtStartOfDay.plusHours(19).plusMinutes(30)) {
sendCommand(YYYY, ON)
}
end
I would try it with and extra ( ) around the complete if statement, like:
when
Item XXXX received update ON
then
if ((now.isAfter(now.withTimeAtStartOfDay.plusHours(19).plusMinutes(30)) && now.isBefore(now.withTimeAtStartOfDay.plusHours(20).plusMinutes(55))) {
sendCommand(YYYY, ON)
}
end
You’re missing the closing ) on the if statements on both rules.
if (now.isAfter(now.withTimeAtStartOfDay.plusHours(19).plusMinutes(30))) {
if (now.isAfter(now.withTimeAtStartOfDay.plusHours(19).plusMinutes(30)) && now.isBefore(now.withTimeAtStartOfDay.plusHours(20).plusMinutes(55))) {
Try adding the .millis inside isAfter and isBefore
if (now.isAfter(now.withTimeAtStartOfDay.plusHours(19).plusMinutes(30).millis)) {
if (now.isAfter(now.withTimeAtStartOfDay.plusHours(19).plusMinutes(30).millis) && now.isBefore(now.withTimeAtStartOfDay.plusHours(20).plusMinutes(55).millis)) {
I can confirm that isBefore does not work as expected - at least today… because today daylight saving was switched off…
I had to add one hour when testing the behavior.
It was about 11:25 pm when I tested .isBefore(), and it did not work with
if (now.isBefore(now.withTimeAtStartOfDay.plusHours(23).plusMinutes(30)))
but adding another hour worked!
if (now.isBefore(now.withTimeAtStartOfDay.plusHours(24).plusMinutes(30)))
So maybe this is a temporary error. I will try the same tomorrow…
In fact, the behavior is correct, because the actual day has 25 hours!!!