Subscribing to systemStart - Execute with delay

I've been trying to get a method to run with a delay after a reboot. I know the subscription works as the scheduler shows the job. The job is shown without a next run time.

This is my subscription:

def subscribe(){
LOGDEBUG("subscribe()")
subscribe(location, "systemStart", handleReboot)
}

def handleReboot(evt) {
LOGDEBUG("handleReboot()")
myRunIn(600, getAccessToken)
}

which should then run the getAccessToken() method after ten minutes

private def myRunIn(delay_s, func) {
if (delay_s > 0) {
def tms = now() + (delay_s * 1000)
def date = new Date(tms)
runOnce(date, func)
}
}

I know the myRunIn() works as it's used throughout my code.

This the how the scheduled job looks

and the event subscription:

I've been tinkering with this for ages. I'm sure in the past there was a scheduled time. The scheduled job just never runs.

I need the delay as the Hub will have power and network connectivity before the rest of my network is stable.

Any suggestions greatly appreciated.

We were just tinkering with the timing of sending out the systemStart event. What release are you on?

Thanks I'm on 2.3.4.127

Update to latest, and see if it works as expected or not. There are changes in 2.3.4.130.

That worked. The job had a scheduled time and ran as expected

Thanks very much

1 Like

I had a problem with this again this morning after my network and systems shutdown overnight.

Could it be that the hub is trying to get ntp for local processing and is unable because the network isn't ready? I'm assuming it's an issue with the myRunIn() method not being able to get the datetime to calculate the delay.

Again, the job is scheduled without next run time being set.

Why don't you just use runIn() instead of your method? It does the same thing. I don't know if that in and of itself would solve your problem. It is true that the hub is wanting to get the time from ntp at startup. I don't know how that affects scheduling, but can look into it.

Hello,

Set the subscribed method to use runIn(). Unfortunately the same result.

How often does the system try for ntp? I'm wondering whether a loop based on the date variable might be the way to do it.

I could put a delay in the loop so it runs every few mins until it's has a date. Then I don't need to schedule the job, the app will handle the api session normally based on auth result, or is there any other events I could subscribe to, that confirm connectivity. Connection to Hubitat, for example?

What is the hub id? I can take a look at the engineering logs, they will have entries when time is updated through NTP.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.