-
Notifications
You must be signed in to change notification settings - Fork 13
RESTful API
The API has been designed for just one client: the Homebridge script. While this API could be used by other plugins, it is not designed for that and devs are ground-up rewriting the entire web server and API system in Indigo so using this for anything other than HomeKit Bridge doesn't really make sense. What follows here are the methods for the HomeKit Bridge RESTFul API.
This RESTFul implementation is not based on published standards and is completely utilitarian in nature. In general the commands are comprised of the following query parameters.
- cmd: What you want the API to do
- serverId: the Indigo device ID for the server (passed in the config.json file for Homebridge)
- objId: The Indigo ID for the item being controlled (Device, Action Group, Variable, etc)
- jkey: The serialized unique key given to each device added to a server
There may be additional query parameters for specific commands. All RESTFul queries are GET queries. You'll find the port for the server located in the config.json file as apiPort and you should use 127.0.0.1 as the IP address as the plugin will NOT support remote servers at this point.
Every RESTful query requires a serverId field because the plugin permits the user to assign an object to multiple servers and with that ability means they can also have different definitions for each instance of the object. On one server it may be a lightbulb while on another it could be a switch. While this situation is likely rare it is important to always query the object for the server it is attached to so that the proper definition is retrieved. This is why all URL fields always include the serverId with it.
In each object detail there will be a URL parameter that gives you the entire prefix of where you need to go. All you need to do from that URL is give it a cmd to execute and whatever parameters are also required for that command.
For instance, if your Indigo server were at 10.1.200.3 and you went to the following URL for a device that you know is mapped to HomeBridge:
http://10.1.200.3:8558/HomeKit?cmd=getInfo&objId=1010303036&serverId=1794022133
You would get the following:
[
{
"versByte": "",
"name": "Basement Bar",
"hkservice": "Switch",
"url": "/HomeKit?objId=1010303036&serverId=1794022133&jkey=7f6ab27d7fd8b5a45e48ad0fa63c5e4642b298e95e11d89ff8d0156b54aadbb1",
"hkcharacteristics": [
{
"readonly": false,
"name": "On",
"value": false,
"notify": false
}
],
"object": "Device",
"alias": "Bar",
"deviceId": 1010303036,
"action": [
"On"
],
"type": "SwitchLinc Dimmer",
"id": "7f6ab27d7fd8b5a45e48ad0fa63c5e4642b298e95e11d89ff8d0156b54aadbb1"
}
]
You can see from the returned JSON data the following information:
- name: The full Indigo name for the device
- hkservice: The HomeKit device service that this device will be mapped to
- url: The callback URL for all communication between HomeKit and Indigo via the RESTful API
- hkcharacteristics: Each service characteristic and the value of it for HomeKit
- object: The object type for Indigo (i.e., Device, Action Group, Variable, etc)
- alias: The name that HomeKit will use to reference this device and that will be seen in the UI
- action: Available characteristic actions that can be taken on the object
- deviceId: The Indigo object ID associated with the item
- id: The unique serialized key given to the object
- type: The model that HomeKit will display
- versBye: The firmware that HomeKit will display
Retrieves a list of all devices for HomeKit that Indigo is publishing, including all of the parameters you would get if you queried an object individually. This allows for a single call to bring in all the data needed to populate all of HomeKit without any further queries.
The command is:
http://[INDIGO_IP]:[API_PORT]/HomeKit?cmd=deviceList&serverId=[INDIGO_ID_FOR_HK_SERVER]
- INDIGO_IP: IP address for the Indigo server, derived from the config.json
- API_PORT: Port assigned to the web server running the RESTful API, derived from plugin preferences
- INDIGO_ID_FOR_HK_SERVER: The object ID assigned by Indigo for the plugin's HomeKit Bridge Server that this device is included in. This is important because it is possible for one device to be included in multiple servers.
EXAMPLE
http://10.1.200.3:8558/HomeKit?cmd=deviceList&serverId=1794022133
Retrieves all the information about any given object being used as a HomeKit device.
The command is:
http://[INDIGO_IP]:[API_PORT]/HomeKit?cmd= getInfo&objId=[INDIGO_ID_FOR_OBJECT]&serverId=[INDIGO_ID_FOR_HK_SERVER]&jkey=[UNIQUE_SERIALIZED_KEY]
- INDIGO_IP: IP address for the Indigo server, derived from the config.json
- API_PORT: Port assigned to the web server running the RESTful API, derived from plugin preferences
- INDIGO_ID_FOR_OBJECT: The Indigo ID for the object being queried
- INDIGO_ID_FOR_HK_SERVER: The object ID assigned by Indigo for the plugin's HomeKit Bridge Server that this device is included in. This is important because it is possible for one device to be included in multiple servers.
- UNIQUE_SERIALIZED_KEY: The unique serialized key given to the object
EXAMPLE
http://10.1.200.3:8558/HomeKit?cmd=getInfo&objId=1010303036&serverId=1794022133&jkey=7f6ab27d7fd8b5a45e48ad0fa63c5e4642b298e95e11d89ff8d0156b54aadbb1
Updates Indigo to reflect any change made to a HomeKit device.
The command is:
http://[INDIGO_IP]:[API_PORT]/HomeKit?cmd= setCharacteristic&objId=[INDIGO_ID_FOR_OBJECT]&serverId=[INDIGO_ID_FOR_HK_SERVER]&jkey=[UNIQUE_SERIALIZED_KEY]&[CHARACTERISTIC]=[VALUE]...&[CHARACTERISTIC]=[VALUE]
- INDIGO_IP: IP address for the Indigo server, derived from the config.json
- API_PORT: Port assigned to the web server running the RESTful API, derived from plugin preferences
- INDIGO_ID_FOR_OBJECT: The Indigo ID for the object being queried
- INDIGO_ID_FOR_HK_SERVER: The object ID assigned by Indigo for the plugin's HomeKit Bridge Server that this device is included in. This is important because it is possible for one device to be included in multiple servers.
- CHARACTERISTIC=VALUE PAIRS: For each characteristic you are modifying, add an additional query parameter. It's OK that these are passed as strings because the plugin will translate that to the proper Indigo value for that characteristic
- UNIQUE_SERIALIZED_KEY: The unique serialized key given to the object
EXAMPLE
http://10.1.200.3:8558/HomeKit?cmd=setCharacteristic&objId=1010303036&serverId=1794022133&jkey=7f6ab27d7fd8b5a45e48ad0fa63c5e4642b298e95e11d89ff8d0156b54aadbb1&On=false&Brightness=0
HomeKit Bridge for Indigo Copyright (c) 2018 Colorado4Wheeler
HomeKit Indigo Version 2 Homebridge Script Copyright (c) 2018 Webdeck
Indigo Copyright (c) Perceptive Automation
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.