API2

From Larnitech wiki page
Jump to navigation Jump to search
This page contains changes which are not marked for translation.

API2 works via WebSocket connection, so you can interact with your Larnitech server from a browser using extensions (such as WebSocket Test Client).
To get started, you should:

1. Establish a web socket connection.

ws://IPADDR:PORT/api

Where: IPADDR – ip address of your metaforsa or DE-MG;
PORT – port for API2 (you can get it from LT_Setup => General => API => Websocket port (2041 by default);

2. Authorize

{
    "request": "authorize",
    "key": "XXXXXXXXXXXXXXX"
}

Where XXXXXXXXXXXXXXX - key from LT_Setup => Security => Show API key

3.After this you can send json requests:

Fields of JSON_REQUEST:

  • "requestType" - Type of request:
    • “getDevicesList” – request for getting the list of all devices;
    • “getDeviceStatus” – request for getting device status;
    • “setDeviceStatus” – request for setting device status;
    • “setDeviceStatusRaw” – request for setting device status (status in hex format);
    • “getAllDevicesStatus” – request for getting all devices status.
  • “key” – key for API plugin (you can get it from LT Setup=>Plugins=>API=>Configure button).
  • “addr” – address of device.
  • “status” – status of device.

Examples of requests and responses:

 1request:
 2{"requestType":"getDevicesList","key":"ENTER_API_KEY"}
 3 
 4response:
 5{
 6    "requestType":"devicesList",
 7    "devices": [
 8        {
 9            "type": "lamp",
10            "name": "Ceiling",
11            "addr":"401:1"
12        },
13                       
14        {
15            "type": "conditioner",
16            "name": "AC",
17            "addr":"158:200",
18            "t-min":"16",
19            "t-delta":"16"
20        }
21 
22        ]
23}
24 
25request:
26{"requestType":"getDeviceStatus","addr":"310:1","key":"ENTER_API_KEY"}
27response:
28{
29   "requestType" : "deviceStatus",
30   "status" : {
31      "addr" : "310:1",
32      "state" : "middle",
33      "type" : "jalousie"
34   }
35}
36 
37request:
38{"requestType":"setDeviceStatus","addr":"310:1","key":"ENTER_API_KEY","status":{"state": "on"}}
39 
40response:
41{
42  "requestType":"setDeviceStatus",
43  "addr":"410:1",
44  "status":{
45    "state": "on"
46  }
47   
48}
49 
50request:
51{"requestType":"getAllDevicesStatus","key":"ENTER_API_KEY"}
52 
53response:
54{
55    "requestType":"allDevicesStatus",
56    "statuses": [
57      {
58        "addr":"401:1",
59        "state": "off",
60      },
61       
62      {
63        "addr":"158:200",
64        "state": "on",
65        "temp":"25",
66        "mode":"cool",
67        "fan":"low",
68        "vane-ver":"1",
69        "vane-hor":"4"
70      }  
71        ]
72}
73 
74request:
75{"requestType":"setDeviceStatusRaw","addr":"310:1","key":"0","status":{"state":"ff00"}}
76 
77response:
78{
79   "addr" : "310:1",
80   "key" : "0",
81   "requestType" : "setDeviceStatusRaw",
82   "status" : {
83      "state" : "ff00"
84}

CURL

1<item addr="585:16" auto-period="1" cfgid="4" name="color-temp dimmer" type="dimer-lamp"/>
2<item addr="585:17" name="main dimmer" type="dimer-lamp" auto-period="600" color-temp="585:16"/>

1. Use request to get detailed info about element with "status":"detailed"

1curl --header 'Content-Type: application/json' --data '{"request":"status-get", "API-KEY":"ENTER_API_KEY", "addr":"585:17", "status":"detailed"}' 'http://de-mg.local/API2/'


2. Use request to set brightness for dimmer element

1curl --header 'Content-Type: application/json' --data '{"request":"status-set","API-KEY":"ENTER_API_KEY", "addr":"585:17", "status":{"level":10}}' 'http://de-mg.local/API2/'


3. Use request to set color-temp for dimmer element

1curl --header 'Content-Type: application/json' --data '{"request":"status-set","API-KEY":"ENTER_API_KEY","addr":"585:17", "status":{"color-temp":100}}' 'http://de-mg.local/API2/'