Difference between revisions of "Webhooks/ru"

From Larnitech wiki page
Jump to navigation Jump to search
(ru)
(ru)
Line 4: Line 4:
 
* '''Actions''' (действия): внешний сервис отправляет HTTP-запрос серверу Larnitech, и сервер меняет состояние элемента.
 
* '''Actions''' (действия): внешний сервис отправляет HTTP-запрос серверу Larnitech, и сервер меняет состояние элемента.
  
−
== Events ==
+
== События ==
−
An event has the following fields:
+
Поля события:
 
{|class="wikitable"
 
{|class="wikitable"
−
!Field!!Description
+
!Поле!!Описание
 
|-
 
|-
−
|Name||Name of the event. It is used in the script that sends the event.
+
|Name||Название события. По нему событие вызывается из сценария.
 
|-
 
|-
−
|URL||Address that the server calls.
+
|URL||Адрес, на который обращается сервер.
 
|-
 
|-
−
|Method||<code>GET</code> (default) or <code>POST</code>.
+
|Method||<code>GET</code> (по умолчанию) или <code>POST</code>.
 
|-
 
|-
−
|Feedback||Optional. Item address and a regular expression: the value found in the answer is written to that item.
+
|Feedback||Необязательно. Адрес элемента и регулярное выражение: найденное в ответе значение записывается в этот элемент.
 
|}
 
|}
−
The event is sent from a script. In LT Setup open '''Scripts → Scripts from logic → Add Blockly script''', add the device event on the '''Triggers''' tab, put the '''Make webhook''' block from the '''Automation''' tab into it and choose the event name.
+
Событие отправляется из сценария. В LT Setup откройте '''Scripts → Scripts from logic → Add Blockly script''', на вкладке '''Triggers''' добавьте событие устройства, поместите в него блок '''Make webhook''' с вкладки '''Automation''' и выберите название события.
  
 
== Actions ==
 
== Actions ==

Revision as of 12:37, 5 November 2026

Other languages:
English • ‎русский

Webhooks связывают систему Larnitech с любым интернет-сервисом, который умеет отправлять или принимать HTTP-запросы (например, IFTTT). Они настраиваются в LT Setup на вкладке Webhooks, у которой две части:

  • Events (события): сервер Larnitech отправляет HTTP-запрос на внешний адрес, когда в системе что-то происходит.
  • Actions (действия): внешний сервис отправляет HTTP-запрос серверу Larnitech, и сервер меняет состояние элемента.

События

Поля события:

Поле Описание
Name Название события. По нему событие вызывается из сценария.
URL Адрес, на который обращается сервер.
Method GET (по умолчанию) или POST.
Feedback Необязательно. Адрес элемента и регулярное выражение: найденное в ответе значение записывается в этот элемент.

Событие отправляется из сценария. В LT Setup откройте Scripts → Scripts from logic → Add Blockly script, на вкладке Triggers добавьте событие устройства, поместите в него блок Make webhook с вкладки Automation и выберите название события.

Actions

An action has a name, an item and the state to set (on, off, reverse, level, mode, target temperature and so on, depending on the item type).

To run an action, call the URL:

  • in the local network: http://CONTROLLER_IP/webhook/?key=API_KEY&name=ACTION_NAME
  • over the internet: https://service.larnitech.com/webhook/?key=API_KEY&sn=SERIAL&name=ACTION_NAME

where:

  • API_KEY: API key of the server (the TCP-API key, see API2);
  • SERIAL: serial number of the server;
  • ACTION_NAME: name of the action from the Name field.

The server answers with JSON. An error answer has "result":"ERROR" and a message, for example Error Key (wrong key) or Action not found.

Example

The settings are stored in /home/settings/webhooks.json. Example with one event with feedback and two actions:

 1{
 2  "events": [
 3    {
 4      "name": "997:1_button_pressed",
 5      "url": "https://maker.ifttt.com/trigger/997:1_button_pressed/with/key/YOUR_IFTTT_KEY",
 6      "method": "POST"
 7    },
 8    {
 9      "name": "447:145_sensor_state",
10      "url": "https://example.com/weather.json",
11      "feedback": { "addr": "447:145", "regexp": "/\"temp\":\"(-?[0-9]+)\",/" }
12    }
13  ],
14  "actions": [
15    {
16      "name": "401:1_lamp_on",
17      "status": [ { "request": "status-set", "addr": "401:1", "status": { "state": "on" } } ]
18    },
19    {
20      "name": "401:1_lamp_reverse",
21      "status": [ { "request": "status-set", "addr": "401:1", "status": { "state": "reverse" } } ]
22    }
23  ]
24}

See also: IFTTT (IF This, Then That), API2.