Local API

Got it - just what I needed. Many thanks

Just to be sure, the access token is obtained using:

/oauth/token

with parameters:
grant_type=authorization_code
code=
client_id=
client_secret=
scope=app=
redirect_uri=

For the endpoints I know I have to use Bearer. Here is what my PHP code looks like for SmartThings. I assume this exact code will work for Hubitat with the hub $stweb variable set to a different value and change /api/smartapps/endpoints to /api/apps/endpoints
You said /apps/api/endpoints but I assume you meant the other order?

$host = $stweb . "/api/smartapps/endpoints";
$headertype = array("Authorization: Bearer " . $access_token);
$response = curl_call($host, $headertype);

when you call /oauth/token , you do not need to provide the scope, otherwise everything is correct in your list.

The code you are using for ST should work fine. and the url I mentioned earlier is correct: "/apps/api/endpoints"

would it be possible to have the event's data field in the /eventsocket stream?

There is no plan to make the event data available on that socket. In addition, that is an internal use endpoint so it is subject to change at any time.

ok, good to know. I'm currently forwarding from within an app and works nicely. Having those in a websocket would have allowed to have less load on the hub but will work anyway. I understand it is internal and I by no means request any guarantee on it :wink:

Are any of these endpoints documented. My hub was in a 500 error right now and was looking for this command and could not find it handy anywhere. I ended up pulling the plug.

Not at this time. These are internal methods and probably won't be documented vs improving the ui to be able to handle things better.

1 Like

Ok just making sure - thought there might be a simple a url to enter in the browser or such.
Thanks for the response...

Not sure what you are asking for? If your hub is at a hard stop and every page is loading a 500 error, grabbing a database backup would have that issue in it. The hub stores 5 days worth of backups.

Are you looking to restore a specific day / database? A reboot is meant to fix a database issue on startup.

If you just have an app throwing a 500 error, you can always go into settings, backup / restore and restore the last known good db.

Honestly I was interested in a remote command to tell the hub to reboot.

I was playing with some code and caused some kind of meltdown - I could access the location page but everything else was returning a 500 error.

My thought was maybe if there was a command available I could tell the hub to reboot rather than pulling the plug. There is a good chance this command would fail as well I guess. I just did not know without being able to try.

I though I had seen talk of some sort of endpoint being available to do this sort of thing. Not a big deal, just figured I would ask in order to be armed for next time.

Some sort of remote reboot method could be beneficial in some cases?

Edit: I saved the code in case anyone wants to try it. - Past logs showed a cool error I had never seen before.

image

Check out this thread. You can remotely reboot the hub in a variety of ways but the web service would need to be running.

1 Like

@stephack YES!!

This is the thread I was thinking about - I just could not seem to come search it out.

And this post in particular...

Thank you so much

You what's really funny. I walked into my house right after sharing this and none of my automations ran. I was able to ping the hub but could not bring up the web interface. Popped the reboot url in the browser and voila. Hub rebooted..talk about instant use case.

3 Likes

Probably not posting this in the right spot. I am new to Hubitat and looking to support a device that sends events via an HTTP post. Can anyone point me to an example of how to approach this?

If you mention what device it is maybe someone has exact experience with it

There is a Hubitat app called Maker API that accepts commands and there is also the ability for rule actions to send http requests outbound but you’re not clear at all on what you are trying to do or even what direction you’re truly to send the request, that would help others help you

This is for RoomMe. I have searched Hubitat and nobody has experience with it yet.

RoomMe has a simple facility to enable integrations. It send a JSON object via an HTTP post call. Thus I am looking for a way to write a hubitat device driver that can receive an HTTP post and deal with the payload.

RoomMe is configured simply with the endpoint to receive the HTTP posts.

Here's a GET. You can look at what it's doing and how JSON is parsed into a Map.

def pollSunRiseSet() {
    currDate = new Date().format("yyyy-MM-dd", TimeZone.getDefault())
    log.info("DarkSky.net Weather Driver - INFO: Polling Sunrise-Sunset.org")
    def requestParams = [ uri: "https://api.sunrise-sunset.org/json?lat=" + location.latitude + "&lng=" + location.longitude + "&formatted=0" ]
    if (currDate) {requestParams = [ uri: "https://api.sunrise-sunset.org/json?lat=" + location.latitude + "&lng=" + location.longitude + "&formatted=0&date=$currDate" ]}
    LOGINFO("Poll Sunrise-Sunset: $requestParams")
    asynchttpGet("sunRiseSetHandler", requestParams)
    return
}

def sunRiseSetHandler(resp, data) {
	if(resp.getStatus() == 200 || resp.getStatus() == 207) {
		sunRiseSet = resp.getJson().results
		updateDataValue("sunRiseSet", resp.data)
        LOGINFO("Sunrise-Sunset Data: $sunRiseSet")
.
.
.
    } else {
		log.warn "Sunrise-Sunset api did not return data"
	}
    return
}

Please correct me if I am wrong but this is making a call from Hubitat to a remote device/service. I need the reverse. I need my Hubitat device driver to receive an HTTP post from RoomMe.

I was looking at the Hubitat dev docs and was surprised to see websockets and associated events but not rest. A simple hubitat http event would do the trick.

That's the mechanism for you, I suspect. :slight_smile: