Hello,
I have a rule where I dim Toilet lights when the time is between 22:00PM and 06:00AM.
I’ve had this code working well, but after migrating my system to OH3.1 the method of getting current date/time values have changed. I’ve read several articles but still not able to figure out why is it not working properly. Also I have errors in my openhab log when running the timer/get time part of the script.
As I’ve checked possible Java time values Minutes() and Hour() should be able to grabbed.
I’ve added a log entry to check if the value of hr*60+minutes are changing. It was changing on first run then I think it got stuck or stg because it shows the same value for CurrentTime.
var CurrentTime = now.hour * 60 + now.minute
val nighttimeBrightness = '2'
val daytimeBrightness = '100'
rule "WC Lámpa dimmelés"
when
Item WcSzemAlarmMotion changed from OFF to ON
then
logInfo("WC", "WC mozgás")
logInfo("WC", "Aktuális idő " + CurrentTime.toString)
if ((CurrentTime > 1320) || (CurrentTime < 360))
{
logInfo("WC", "Dimm bathroom light because it is nighttime")
WCDimmerSwitchDimmer.sendCommand(nighttimeBrightness)
createTimer(now.plusSeconds(180), [ | sendCommand(WCDimmerSwitchDimmer,0)])
} else
{
logInfo("WC", "Set bathroom light brightness to 100 because it is daytime")
WCDimmerSwitchDimmer.sendCommand(daytimeBrightness)
createTimer(now.plusSeconds(180), [ | sendCommand(WCDimmerSwitchDimmer,0)])
}
end
The Error log shows:
2021-07-13 08:34:41.306 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method ‘ThingHandler.handleCommand()’ on ‘org.openhab.binding.zwave.handler.ZWaveThingHandler@19fe1ad’: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@107a8d1[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@f34266[Wrapped task = org.openhab.binding.zwave.handler.ZWaveThingHandler$1@f01ea9]] rejected from org.openhab.core.internal.common.WrappedScheduledExecutorService@1f5c927[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 2838615]
java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@107a8d1[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@f34266[Wrapped task = org.openhab.binding.zwave.handler.ZWaveThingHandler$1@f01ea9]] rejected from org.openhab.core.internal.common.WrappedScheduledExecutorService@1f5c927[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 2838615]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2055) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:825) ~[?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:340) ~[?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor.scheduleAtFixedRate(ScheduledThreadPoolExecutor.java:632) ~[?:?]
at org.openhab.binding.zwave.handler.ZWaveThingHandler.startPolling(ZWaveThingHandler.java:459) ~[?:?]
at org.openhab.binding.zwave.handler.ZWaveThingHandler.handleCommand(ZWaveThingHandler.java:1220) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:154) [bundleFile:?]
at org.openhab.core.internal.common.InvocationHandlerSync.invoke(InvocationHandlerSync.java:59) [bundleFile:?]
at com.sun.proxy.$Proxy3016.handleCommand(Unknown Source) [?:?]
at org.openhab.core.thing.internal.profiles.ProfileCallbackImpl.handleCommand(ProfileCallbackImpl.java:80) [bundleFile:?]
at org.openhab.core.thing.internal.profiles.SystemDefaultProfile.onCommandFromItem(SystemDefaultProfile.java:48) [bundleFile:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
at org.openhab.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:154) [bundleFile:?]
at org.openhab.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:829) [?:?]
Previously in OH 2.5 I’ve had this part checking what is the current time and if that was between 22:00->to minutes and 06:00->to minutes then the ligts were dimmed.
if ((now.getMinuteOfDay > 1320) || (now.getMinuteOfDay < 360)
Now since in OH 3.1 getminuteofday does not work anymore I had to populate a variable every time the rule runs and check the same. Clearly it does not work well…
What am I missing or doing wrong?