Hi there,
i had some spare time and finally wired two Shellys into my home.
One is working in my office as an edge switch together with the normal wall switch.
This was very important for the WAF!
So i´m able to control the lights of the office with the Shelly and with the wall switch.
Now i´m using my MS Teams Status Updater to turn on the Shelly in the morning and then control the lights.
As the hue lights are OFFLINE
and can´t be controlled right after turning them ON
with the Shelly, i need to wait until the Things come ONLINE
.
This time can be something between 2 and 20 seconds for what i saw in the logs.
Now i had the idea to do a Looping timer as of Richs example.
I´m not sure what i´m missing but the timer gets rescheduled even after the Thing came ONLINE
.
val String ruleId = "TestRule"
var Timer timer = null
rule "Test"
when
Item itmTestSwitch changed
then
timer = null
logInfo(ruleId, "Test rule started!")
var thingStatus = getThingStatusInfo('<Thing-UID>').getStatus().toString()
logInfo(ruleId, "Thing is " + test)
if(thingStatus == "ONLINE")
{
logInfo(ruleId, "Status Online!")
}
timer = createTimer(now, [ |
if(thingStatus == "ONLINE")
{
timer = null
logInfo(ruleId, "Test rule executed!")
}
else
{
logInfo(ruleId, "Restart the Timer!")
timer.reschedule(now.plusSeconds(5))
}
])
end
What i see in the logs:
2021-08-13 18:03:47.587 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing '<thing-UID>' changed from ONLINE to OFFLINE: Die Hue Bridge meldet, dass die Lampe nicht erreichbar ist.
2021-08-13 18:04:02.003 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'itmTestSwitch' received command OFF
2021-08-13 18:04:02.008 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'itmTestSwitch' changed from ON to OFF
2021-08-13 18:04:02.012 [INFO ] [g.openhab.core.model.script.TestRule] - Test rule started!
2021-08-13 18:04:02.016 [INFO ] [g.openhab.core.model.script.TestRule] - Thing is OFFLINE
2021-08-13 18:04:02.120 [INFO ] [g.openhab.core.model.script.TestRule] - Restarted the timer!
2021-08-13 18:04:07.126 [INFO ] [g.openhab.core.model.script.TestRule] - Restarted the timer!
2021-08-13 18:04:12.130 [INFO ] [g.openhab.core.model.script.TestRule] - Restarted the timer!
2021-08-13 18:04:17.133 [INFO ] [g.openhab.core.model.script.TestRule] - Restarted the timer!
2021-08-13 18:04:22.137 [INFO ] [g.openhab.core.model.script.TestRule] - Restarted the timer!
2021-08-13 18:04:27.141 [INFO ] [g.openhab.core.model.script.TestRule] - Restarted the timer!
2021-08-13 18:04:27.814 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing '<thing-UID>' changed from OFFLINE: Die Hue Bridge meldet, dass die Lampe nicht erreichbar ist. to ONLINE
2021-08-13 18:04:32.144 [INFO ] [g.openhab.core.model.script.TestRule] - Restarted the timer!
2021-08-13 18:04:37.148 [INFO ] [g.openhab.core.model.script.TestRule] - Restarted the timer!
This goes on and on until i use the Testswitch again and it runs into problems…
2021-08-13 18:04:42.154 [WARN ] [ore.internal.scheduler.SchedulerImpl] - Scheduled job failed and stopped
java.lang.NullPointerException: cannot invoke method public abstract boolean org.openhab.core.model.script.actions.Timer.reschedule(java.time.ZonedDateTime) on null
-
What did i do wrong?
Theif(thingStatus == "ONLINE")
fires and so should the sameif
inside the timer. -
Is there any way to stop this never ending loop from the outside?
Thanks in advance!
- Platform information:
- Hardware: Raspberry Pi 4 Model B Rev 1.1
- OS: Raspbian GNU/Linux 10 (buster)
- Java Runtime Environment:
- openjdk version “11.0.12” 2021-07-20 LTS
- OpenJDK Runtime Environment Zulu11.50+19-CA (build 11.0.12+7-LTS)
- OpenJDK Client VM Zulu11.50+19-CA (build 11.0.12+7-LTS, mixed mode)
- openHAB version: 3.1.0 (Build)