How to create a ticker or timer to refresh() every so often

I am new to groovy, but not to development in general.

I am trying to create a ticker using runIn(seconds, 'methodName'), like this:

def ticker() {
refresh()
runIn(4, "ticker")
}

In order to have a refresh every 4 seconds, sometimes it seems to work, sometimes it takes longer between ticks, and then it just stops, and then comes back a couple minutes later.

Do you have any best practices you can recommend on how to do this in HUBITAT & groovy in a reliable implementation.

Thanks!!!

runIn(4, updateLux) // give sunrise/set time to complete.

no quotes.

I got the following advice when I asked a few days ago:

I was specifically asking about the reboot scenario, 4 seconds is a pretty rapid loop. That it would lead to lost schedules, wouldn't shock me.

Thanks!

Still not working by removing the quotes.

Does anybody has a working example of a "cron string schedule"?

Yes.

schedule("0 "+randomMinute+" "+randomHour+" ? * FRI *", checkForUpdate)

this runs at a random time, this is a direct quote from one that works. But if you wanted to schedule the job to run every 4 mins,

schedule("0 */4 * ? * * *", refresh)

I am pretty sure that would be what you would want.

Or you can simply do runEvery5Minutes(refresh) or runEvery10Minutes(refresh) also. There are several different options up to 3 hours I think. But you can't use any number you want.

1 Like

Thanks!

Your example is correct and very helpful and allowed me also to track a little course in cron schedule and an online cron schedule generator.

The problem is that no matter what combination I use, the HUBITAT seems to do whatever it wants, triggering completely at random and not respecting anything on the schedule.

Now this points to a problem or limitation on the hub itself.

Should I open a ticket with support?

At this point I have tried all kind of combinations using:

  • runIn
  • runInMillis
  • runEvery1Minute
  • schedule

But to no avail, all of them are not reliable.

Suggestions?

Thanks!

I have no idea what you are doing wrong. I have several custom drivers that work off runIn and cron jobs and they all work perfectly. You know that the scheduled task at the bottom of the device page don't update until you refresh the page, right? Also, when you update a driver, you have to have some method to invoke it to be scheduled. Maybe if you posted the whole driver, I could see what you are doing wrong.

Does not match my experience.

I have wx-ApiXU-Driver polling sunrise-sunset.org once every 24 hours, Polling ApiXU.com every (user selectable interval) and poll a Lux calculation, also every (user selectable interval). Each is run off 'schedule()' or runIn.

	unschedule()
	schedule("23 10 0 ? * * *", pollSunRiseSet)
	schedule("0 0 8 ? * FRI *", updateCheck)
	schedule("0 0/${luxEvery} * * * ?", updateLux)

Logs show:

dev:19 2019-08-08 06:40:00.116 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 06:35:00.112 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 06:30:00.108 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 06:25:00.124 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 06:24:55.596 pm info wx-ApiXU poll for: 14610
dev:19 2019-08-08 06:20:00.109 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 06:15:00.092 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 06:10:00.143 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 06:05:00.114 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 06:00:00.124 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 05:55:00.110 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 05:54:55.702 pm info wx-ApiXU poll for: 14610
dev:19 2019-08-08 05:50:00.119 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 05:45:00.092 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 05:40:00.076 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 05:35:00.130 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 05:30:00.140 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 05:25:00.118 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 05:24:55.627 pm info wx-ApiXU poll for: 14610
dev:19 2019-08-08 05:20:00.071 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 05:15:00.132 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 05:10:00.110 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 05:05:00.093 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 05:00:00.111 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 04:55:00.063 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 04:54:57.308 pm info wx-ApiXU poll for: 14610
dev:19 2019-08-08 04:50:00.129 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 04:45:00.121 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 04:40:00.127 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 04:35:00.141 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 04:30:00.081 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 04:25:00.118 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 04:24:55.828 pm info wx-ApiXU poll for: 14610
dev:19 2019-08-08 04:20:00.142 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 04:15:00.110 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 04:10:00.132 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 04:05:00.131 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 04:00:00.113 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 03:55:00.124 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 03:54:55.589 pm info wx-ApiXU poll for: 14610
dev:19 2019-08-08 03:50:00.099 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 03:45:00.131 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 03:40:00.109 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 03:35:00.132 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 03:30:00.143 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 03:25:00.141 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 03:24:55.706 pm info wx-ApiXU poll for: 14610
dev:19 2019-08-08 03:20:00.112 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 03:15:00.110 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 03:10:00.129 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 03:05:00.106 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 03:00:00.098 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 02:55:00.139 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 02:54:55.650 pm info wx-ApiXU poll for: 14610
dev:19 2019-08-08 02:50:00.084 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 02:45:00.105 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 02:40:00.118 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 02:35:00.127 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 02:30:00.116 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 02:25:00.089 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 02:24:55.554 pm info wx-ApiXU poll for: 14610
dev:19 2019-08-08 02:20:00.129 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 02:15:00.100 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 02:10:00.136 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 02:05:00.077 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 02:00:00.126 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 01:55:00.112 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 01:54:55.596 pm info wx-ApiXU poll for: 14610
dev:19 2019-08-08 01:50:00.091 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 01:45:00.054 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 01:40:00.116 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 01:35:00.127 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 01:30:00.121 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 01:25:00.121 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 01:24:55.641 pm info wx-ApiXU poll for: 14610
dev:19 2019-08-08 01:20:00.126 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 01:15:00.140 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 01:10:00.118 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 01:05:00.413 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 01:00:00.123 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 12:55:00.096 pm info wx-ApiXU lux calc for: 14610
dev:19 2019-08-08 12:54:55.606 pm info wx-ApiXU poll for: 14610

Which seems the opposite of random.

The released version of wx-ApiXU-Driver uses runIn, which I'm re-coding as above..

def updateLux()     {
	runIn(state.luxNext, updateLux)

The chained runIn works, but if anything prevents the action, it does not recover. As in: runIn(300, updateLux) = 5 min from now. But if a reboot occurs 2 mins from now, and takes longer than 3 mins, the runIn misses the time and does not call the handler and therefore the next is not scheduled. There's nothing wrong with this behavior, as long as one is aware.

1 Like

You can literally set your watch by it. Oh wait....:wink: hehe

Refreshing anything every 4 seconds is going to generate e quite a bit of traffic. I remember reading that one of the main tenets that HE team held was to not be constantly refreshing like the "other platform" does. if devices aren't showing the correct state, but do once refreshed, address it at the connectivity layer, ie mesh or LAN.

You should NOT refresh every 4 seconds. That is going to bring your hub to a crawl. It should only be necessary every few minutes.

I believe the "refreshing tenets" was due to the SmartThings hub refreshing everything every 10 seconds. That approach was thought to be a huge waste.

I can't speak to how much it would take to bury the HE hub. I have two rules that will refresh the relevant device every 10 seconds. They don't run together so I can say that my experience has shown that refreshing a single device doesn't do anything to the hub's performance.

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