Webhooks

From Larnitech wiki page
Revision as of 12:37, 5 November 2026 by Mark (talk | contribs) (ru)
Jump to navigation Jump to search
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.