Homey Community Forum

[Unsupported] Homey v2 REST API


#1

I am not sure whether this topic is allowed. But I thought I share my findings for the v2 API. I have personal use cases for directly calling the API through iOS shortcuts.

In v2, the on and off REST API path has changed to /capability/onoff from /state.

So now to switch on:
PUT { "value": true } TO http://<HOMEY_IP>/api/manager/devices/device/<DEVICE_ID>/capability/onoff

and to switch off:
PUT { "value": false } TO http://<HOMEY_IP>/api/manager/devices/device/<DEVICE_ID>/capability/onoff

Other than that, the rest of the APIs path rename the same
GET http://<HOMEY_IP>/api/manager/devices/device
GET http://<HOMEY_IP>/api/manager/devices/device/<DEVICE_ID>
GET http://<HOMEY_IP>/api/manager/devices/device/<DEVICE_ID>
GET http://<HOMEY_IP>/api/manager/insights/log/homey:device:<DEVICE_ID>/measure_temperature/entry

To get the token needed to do call the API, see my reply below [Unsupported] Homey v2 REST API


#2

Nice thanks


#3

From previous forums (no idea if they still work):

# Get all zones
GET http://<HOMEY_IP>/api/manager/zones/

# Get all devices 
GET http://<HOMEY_IP>/api/manager/devices/

# Get all devices within a zone:
GET http://<HOMEY_IP>/api/manager/devices/?zone=01234567-89ab-cdef-0123-456789abcdef

# Get Device
GET http://<HOMEY_IP>//api/manager/device/01234567-89ab-cdef-0123-456789abcdef

From Candy

function updateFlowEnabled (flowId, enabled) {
  return api('put', `/manager/flow/flow/${flowId}/enabled`, {enabled})
  return api('put', '/manager/flow/flow/' + flowId, {enabled})
}

A few examples:

Get data
GET http://<HomeyIP>/api/manager/geolocation/ (read location)
GET http://<HomeyIP>/api/manager/devices/device/ (read all devices)
GET http://<HomeyIP>/api/manager/devices/device/<device_id>/ (read device by id)
GET http://<HomeyIP>/api/manager/flow/flow/ (read all flows)
GET http://<HomeyIP>/api/manager/flow/flow/<flow_id>/ (read all flow by id)

Set data
PUT http://<HomeyIP>/api/manager/devices/device/<device_id>/state/
(update capability of a device via json body, e.g. {'target_temperature': 20} triggers an thermostat to temperature of 20°, {'onoff': 1} switches a plug / switch 'on', etc). 

Im guesing : http://<HomeyIP>/api/manager/devices/device/<device_id>/capability/target_temperature

Speech :

http://YOUR-HOMEY-IP/api/manager/speech-output/

#4

the main question is… how are you authenticating?


#5

These keys can be used for local dev:
https://developer.athom.com/api/projects

API docs are documented for most parts: https://developer.athom.com/docs/api/HomeyAPI.ManagerDevices.html


#6

To get the token to do auth authenticated, go to https://developer.athom.com/ and login.

After logging in, open up developer console and go to the network tab.

Look for the URL that ends with /sessions/session/me. Click on it and on the right should appear another panel showing the header response.

Under request headers, look for the key authorization and what you need is the token starting after Bearer

In v2, the token changed. Used to be just <HASH>, now it is <UUID>:<UUID>:<HASH> which makes it much longer.

With that, you can do a call like

curl -H "Authorization: Bearer <TOKEN>" http://<HOMEY_IP>/api/manager/devices/device

And you should get back a list of your devices


#7

I have a problem

curl -H "Authorization: Bearer " http://<HOMEY_IP>/api/manager/devices/

with token and ip added I get:

{“code”:404,“error”:“not_found”,“error_description”:“Not found: GET /api/manager/devices/”}

I’m cannot solve the problem


#8

Did you try any of the other URL’s that @Jamie mentioned in this comment?


#9

Try with: /api/manager/devices/device/


#10

/api/manager/devices/device/

gave me a slightly different response

{“code”:401,“error”:“invalid_session”,“error_description”:“An unkown error has occured [invalid_session]”}


#11

That worked for me, just did a quick test in c# though.

public async Task GetDevicesAsync()
{
using (var client = GetClient())
{
var response = await client.GetStringAsync($“http://{homeyIp}/api/manager/devices/device/”).ConfigureAwait(true);
var result = JArray.Parse(response);
}
}

    private static HttpClient GetClient()
    {
        var client = new HttpClient();
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearerToken);
        return client;
    }

#12

Thanks for quick response. However, I still get the same problem. Tried on two different computers


#13

Are you using the correct bearer token? xxx:xxx:xxx


#14

So infact the information in this topic could be used to create a web ui? :smiling_imp:


#15

Share your code?


#16

The code is just a one liner

curl -H “Authorization: Bearer 80c58bxxxxxxxxxxxxxxxxxxxxxxxxxeb93ae449” http://192.168.1
.20/api/manager/devices/device/


#17

Your Bearer token seems to be the old v1.5 rather than v2


#18

Thanks, lesterchan
My Homey version is 2.0.0 according to the Homey app. The bearer token is one continuous number.


#19

Does it have any colon? There should be two colons separating three values. If you see one continuous string of chars without any colon or dash, it is the old v1.5 token.


#20

It hasn’t any colon and it is probably a v1.5 bearer. So then the question is, how can i generate a v2.0 one?