Line 4: |
Line 4: |
| API2 works via WebSocket connection, so you can interact with your Larnitech server from a browser using extensions (such as WebSocket Test Client).<br> | | API2 works via WebSocket connection, so you can interact with your Larnitech server from a browser using extensions (such as WebSocket Test Client).<br> |
| To get started, you should:<br><br> | | To get started, you should:<br><br> |
− | 1. Establish a web socket connection.<br> | + | 1. Establish a web socket connection.<br> Locally |
| <syntaxhighlight lang="xml"> | | <syntaxhighlight lang="xml"> |
| ws://IPADDR:PORT/api | | ws://IPADDR:PORT/api |
| </syntaxhighlight> | | </syntaxhighlight> |
| Where: IPADDR – ip address of your metaforsa or DE-MG;<br> | | Where: IPADDR – ip address of your metaforsa or DE-MG;<br> |
− | PORT – port for API2 (you can get it from LT_Setup => General => API => Websocket port (2041 by default);<br><br> | + | PORT – port for API2 (you can get it from LT_Setup => General => API => Websocket port (2041 by default); <br> |
| + | Or use next for remote: |
| + | <syntaxhighlight lang="xml"> |
| + | wss://SERIAL.in.larnitech.com:8443/api |
| + | </syntaxhighlight> |
| + | Where: SERIAL is serial number of your server, you can find it in LT_Setup => General <br><br> |
| 2. Authorize | | 2. Authorize |
| <syntaxhighlight lang="json"> | | <syntaxhighlight lang="json"> |
Line 22: |
Line 27: |
| Fields of JSON_REQUEST: | | Fields of JSON_REQUEST: |
| <ul> | | <ul> |
− | <li>"requestType" - Type of request: | + | <li>"request" - Type of request: |
| <ul> | | <ul> |
− | <li>“getDevicesList” – request for getting the list of all devices;</li> | + | <li>“get-devices” – request for getting the list of all devices;</li> |
− | <li>“getDeviceStatus” – request for getting device status;</li> | + | <li>“status-get” – request for getting device status;</li> |
− | <li>“setDeviceStatus” – request for setting device status;</li> | + | <li>“status-set” – request for setting device status;</li> |
− | <li>“setDeviceStatusRaw” – request for setting device status (status in hex format);</li>
| + | <li>“status-subscribe” – request for subscribe events (WebSocket only)</li> |
− | <li>“getAllDevicesStatus” – request for getting all devices status.</li>
| |
| | | |
| </ul> | | </ul> |
Line 41: |
Line 45: |
| <syntaxhighlight lang="json" line> | | <syntaxhighlight lang="json" line> |
| request: | | request: |
− | {"requestType":"getDevicesList","key":"ENTER_API_KEY"} | + | {"request":"get-devices", "status":"detailed"} |
| | | |
| response: | | response: |
| { | | { |
− | "requestType":"devicesList",
| + | "response":"get-devices", |
− | "devices": [
| + | "devices":[ |
− | {
| + | { |
− | "type": "lamp",
| + | "addr":"158:21", |
− | "name": "Ceiling",
| + | "type":"ir-receiver", |
− | "addr":"401:1"
| + | "name":"IR receiver", |
− | },
| + | "area":"Setup", |
− |
| + | "status":{ |
− | {
| + | "state":"undefined" |
− | "type": "conditioner",
| + | } |
− | "name": "AC",
| + | }, |
− | "addr":"158:200",
| + | { |
− | "t-min":"16",
| + | "addr":"158:40", |
− | "t-delta":"16"
| + | "type":"com-port", |
− | }
| + | "name":"RS232", |
− |
| + | "area":"Setup", |
− | ]
| + | "status":{ |
| + | "state":"undefined" |
| + | } |
| + | }, |
| + | { |
| + | "addr":"33:200", |
| + | "type":"climate-control", |
| + | "name":"climate", |
| + | "area":"Living room", |
| + | "status":{ |
| + | "state":"on", |
| + | "setpoint":23.0, |
| + | "setpoint-heat":21.0, |
| + | "setpoint-cool":25.0, |
| + | "current-temperature":0.0, |
| + | "pid-temperature":100, |
| + | "current-humidity":0.0, |
| + | "current-co2":0, |
| + | "automation":"Comfort", |
| + | "mode":"auto", |
| + | "time-interval":0 |
| + | }, |
| + | "automations":[ |
| + | "Comfort" |
| + | ], |
| + | "automation":"Comfort", |
| + | "modes":[ |
| + | "heat", |
| + | "cool" |
| + | ] |
| + | }, |
| + | ], |
| + | "found":3 |
| } | | } |
− |
| + | |
| request: | | request: |
− | {"requestType":"getDeviceStatus","addr":"310:1","key":"ENTER_API_KEY"} | + | {"request":"status-get","addr":"158:240", "status":"detailed"} |
| response: | | response: |
| { | | { |
− | "requestType" : "deviceStatus",
| + | "response":"status-get", |
− | "status" : {
| + | "devices":[ |
− | "addr" : "310:1",
| + | { |
− | "state" : "middle",
| + | "addr":"158:240", |
− | "type" : "jalousie"
| + | "type":"valve-heating", |
− | }
| + | "status":{ |
| + | "state":"off" |
| + | } |
| + | } |
| + | ], |
| + | "found":1 |
| } | | } |
| | | |
| request: | | request: |
− | {"requestType":"setDeviceStatus","addr":"310:1","key":"ENTER_API_KEY","status":{"state": "on"}} | + | {"request":"status-set","addr":"999:250", "status":{"state":"off"}} |
| | | |
| response: | | response: |
| { | | { |
− | "requestType":"setDeviceStatus",
| + | "response":"status-set", |
− | "addr":"410:1",
| + | "devices":[ |
− | "status":{
| + | { |
− | "state": "on"
| + | "addr":"999:250", |
− | }
| + | "success":true |
− |
| + | } |
| + | ] |
| } | | } |
| | | |
| request: | | request: |
− | {"requestType":"getAllDevicesStatus","key":"ENTER_API_KEY"} | + | {"request":"status-subscribe","addr":"999:250"} |
| | | |
| response: | | response: |
| { | | { |
− | "requestType":"allDevicesStatus",
| + | "response":"status-subscribe", |
− | "statuses": [
| + | "devices":[ |
− | {
| + | { |
− | "addr":"401:1",
| + | "addr":"999:250", |
− | "state": "off",
| + | "status":"0x08" |
− | },
| + | } |
− |
| + | ], |
− | {
| + | "found":1, |
− | "addr":"158:200",
| + | "subscribed":1 |
− | "state": "on",
| |
− | "temp":"25",
| |
− | "mode":"cool",
| |
− | "fan":"low",
| |
− | "vane-ver":"1",
| |
− | "vane-hor":"4"
| |
− | }
| |
− | ]
| |
| } | | } |
| | | |
| request: | | request: |
− | {"requestType":"setDeviceStatusRaw","addr":"310:1","key":"0","status":{"state":"ff00"}} | + | {"request":"status-set","addr":"999:250", "status":"0x01"} |
| | | |
| response: | | response: |
| { | | { |
− | "addr" : "310:1",
| + | "response":"status-set", |
− | "key" : "0",
| + | "devices":[ |
− | "requestType" : "setDeviceStatusRaw",
| + | "999:250" |
− | "status" : {
| + | ] |
− | "state" : "ff00"
| |
| } | | } |
| + | |
| + | request (set status for climate-control): |
| + | {"request":"status-set","addr":"33:200", "status":{"state":"on","setpoint-heat":21.0}} |
| + | |
| + | response: |
| + | { |
| + | "response":"status-set", |
| + | "devices":[ |
| + | { |
| + | "addr":"33:200", |
| + | "success":true |
| + | } |
| + | ] |
| + | } |
| + | |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
Line 136: |
Line 184: |
| | | |
| 1. Use request to get detailed info about element with "status":"detailed" | | 1. Use request to get detailed info about element with "status":"detailed" |
− | curl --header 'Content-Type: application/json' --data '{"request":"status-get", "API-KEY":"8010920395573775", "addr":"585:17", "status":"detailed"}' 'http://de-mg.local/API2/' | + | <syntaxhighlight lang="json" line> |
| + | curl --header 'Content-Type: application/json' --data '{"request":"status-get", "API-KEY":"ENTER_API_KEY", "addr":"585:17", "status":"detailed"}' 'http://de-mg.local/API2/' |
| + | </syntaxhighlight> |
| + | |
| + | |
| | | |
| + | 2. Use request to set brightness for dimmer element |
| + | <syntaxhighlight lang="json" line> |
| + | curl --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/' |
| + | </syntaxhighlight> |
| | | |
− | 2. Use request to set brightness for dimmer element
| |
− | curl --header 'Content-Type: application/json' --data '{"request":"status-set","API-KEY":"8010920395573775", "addr":"585:17", "status":{"level":10}}' 'http://de-mg.local/API2/'
| |
| | | |
| | | |
− | 3. Use request to set color-temp for dimmer element | + | 3. Use request to set color-temp for dimmer element |
− | curl --header 'Content-Type: application/json' --data '{"request":"status-set","API-KEY":".................","addr":"585:17", "status":{"color-temp":100}}' 'http://de-mg.local/API2/' | + | <syntaxhighlight lang="json" line> |
| + | curl --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/' |
| + | </syntaxhighlight> |
| + | |
| | | |
| </translate> | | </translate> |