How about a pace maker approach?
Have something reliable from outside of ST hit the endpoint and forcefully reset the schedules?
How about a pace maker approach?
Have something reliable from outside of ST hit the endpoint and forcefully reset the schedules?
If youâve got some sort of *nix box, you could use something like curl to GET an endpoint that tells you whether the scheduler has died and if certain text is found, GET the reschedule endpoint. Run it periodically via cron and youâre set.
Iâm sure thereâs a windows equivalent, I just donât speak that language. =)
This has been happening to me with my two SmartApps. I switched to runEvery5Minutes and runEvery1Hour hoping that would help, but both apps only seem to work for a few days before quietly giving up.
If Iâm just going to call an outside service to monitor whether or my scripts are working, it seems like it would be best just to move the whole app thereâŚ
If youâre going to do that why do you need a scheduler? Just have your app send a poll() whenever its REST endpoint is called. It will be essentially a cron proxy.
Iâd try to the âexternal monitor / jumpstartâ method out of optimism that SmartThings scheduling will miraculously start working once it is knows it is being watchedâŚ
At this point, though, I guess it may have to wait until Hub V2 takes some load off the cloud? Itâs difficult to understand why the scheduler canât queue up jobs, regardless of how long the queue gets.
We could get 2 hubs so they would give each other an occasional kick. And a third one to make sure the other two donât kill each other.
I think Iâd like to do something similar, except instead of remote checking the schedule, just have the remote endpoint totally replace the scheduled job altogether. The external app would hit a GET endpoint every X minutes to kick off whatever job I need done in the SmartApp. Only trouble is, Iâve not messed with the Smartthings inbound API. Any good code examples out there that are anything close to this?
A reliable scheduler would be infinitely cleaner and âthe right wayâ to do it. We donât have that, though, so weâre getting creative in order to overcome the one of the platformâs longest-standing issues.
Hereâs what Iâm doing. Remember youâll also need to enable OAuth.
mappings {
path("/stamp") {
action: [
GET: "html",
]
}
path("/reschedule") {
action: [
GET: "reschedule",
]
}
}
def html() {
def result
if (now() - state.timestamp < ((settings.interval_1.toInteger() + 5) * 60 * 1000)) {
result = "FIRING"
} else {
result = "FAIL"
}
render contentType: "text/html", data: "<!DOCTYPE html><html><head></head><body>${result}<br><hr><br>App: ${app.name}<br>Last timestamp: ${new Date(state.timestamp)}</body></html>"
}
def reschedule() {
log.trace("Rescheduled via web API call!")
render contentType: "text/html", data: "<!DOCTYPE html><html><head></head><body>Rescheduled ${app.name}</body></html>"
initialize()
}
Thanks. Itâs the OAuth piece Iâm trying to think through at the moment. I can get a token manually via Postmanâs tool, but I was trying to figure out a way to handle that generation through some local application or scripting that didnât require me to host something for the URI callback. Iâm really new at this, so still figuring it all out.
The docs team is currently working a new WebServices Basics Tutorial. To help you out right now, here are the manual steps you can take to get the token (once youâve got your SmartApp published and OAuth enabled). You can do this with requests through a web browser (weâll also add a sample Sinatra app to the tutorial show an app following these steps):
In your web browser, paste in the following URL, replacing the CLIENT_ID with your OAuth Client ID::
https://graph.api.smartthings.com/oauth/authorize?response_type=code&client_id=CLIENT_ID&scope=app&redirect_uri=https%3A%2F%2Fgraph.api.smartthings.com%2Foauth%2Fcallback
Once authenticated, you will be asked to authorize the external application to access your SmartThings. Select some devices to authorize, and click Authorize.
This will redirect you to a page that doesnât exist - but thatâs ok! The important part is the OAuth authorization code, which is the âcodeâ parameter on the URL. Grab this code, and note it somewhere. Weâll use it to get our API token.
Using the code you just received, and our client ID and secret, we can get our access token. Paste the following into your web browserâs address bar, replacing CLIENT_ID, CLIENT_SECRET, and CODE with the appropriate values::
https://graph.api.smartthings.com/oauth/token?grant_type=authorization_code&client_id=CLIENT_ID&client_secret=CLIENT_SECRET&code=CODE&redirect_uri=https%3A%2F%2Fgraph.api.smartthings.com%2Foauth%2Fcallback&scope=app
This should return JSON like the following, from which you can get the access_token
:
{
"access_token": "your_token",
"expires_in": 1576799999,
"token_type": "bearer"
}
You can get the endpoint URL for your SmartApp by making a request to the SmartThings endpoints service, specifying your access token.
In your web browser, paste the following into your address bar, replacing ACCESS_TOKEN with the access token you retrieved above.
https://graph.api.smartthings.com/api/smartapps/endpoints?access_token=ACCESS_TOKEN
That should return JSON that contains information about the OAuth client, as well as the endpoint for the SmartApp:
[
{
"oauthClient": {
"clientId": "myclient",
"authorizedGrantTypes": "authorization_code"
},
"url": "/api/smartapps/installations/8a2aa0cd3df1a718013df1ca2e3f000c"
}
]
Now that you have the access token and the endpoint URL, you can make web requests to your SmartApp endpoint using whatever tool you prefer.
Just make sure to preface http://graph.api.smartthings.com
to the beginning of the URL returned above, and any endpoints your SmartApp exposes (e.g., /switches
) to the end of the URL.
You can either specify your access token via the access_token
URL parameter as above, or (preferably) use the Authorization header ("Authorization: Bearer <API TOKEN>"
).
Ive been seeing the same thing too⌠but iâve noticed that it seams to happen more around certain times of the day. From 2:00pm - 2:01pm CST is the first time frame i noticed it. I kinda got me thinking that almost all the jobs are being set to run on the 0 second of the minute IE âschedule(â0 59 * * * ?â, ârunStuffâ)â so i started testing scheduling off the 0 second and minuet like this schedule(â57 4/8 * * * ?â, ârunStuffâ). This is an eight minuet cycle off the 4min 57 sec point instead of 0. So far itâs been working well but iâm still watching it.
Wow, thanks! That was super helpful. I must have just been doing something weird when passing the code back to to get the token, but I got it working.
I think youâre right. I started to look into the scheduled job history for both my apps. It looks like itâs a roller coaster ride if the second ends with 0 while the jobs wwith off 0 seconds gets executed quickly. Attached below : MyQ is scheduled to run once a minute and iComfort running once every 5 minutes on 00 seconds.
I think that thereâs plenty of events that can forcefully trigger to reset the schedules within ST. Changing of modes, sunrise/sunset. If you happen to have something constantly polling like energy meter, theoretically you can subscribe to the event and piggy back on the polling instead of relying on cron schedule.
Iâm still testing with these ideas. Only time will tell if they work.
My Locations > Installed SmartApps > (your smartapp)
Well so far it doesnât look to resolve the issue, but it does make the execution delay a lot more consistent. Well iâm off to code up a workaround.
So i updated a smartapp that polls every 8 mins to get weather and temp info to auto restart in the case of SSDS and it had been working well till last night when both scheduled tasks died. From the looks of the logs both task tasks put up a hell of a fight till they both died and i reinitialized the app.