Difference between revisions of "Webhooks"

From Larnitech wiki page
Jump to navigation Jump to search
(New page: Webhooks)
 
(Marked this version for translation)
 
Line 1: Line 1:
 
<languages/>
 
<languages/>
 
<translate>
 
<translate>
 +
<!--T:1-->
 
'''Webhooks''' connect the Larnitech system with any internet service that can send or receive HTTP requests (for example [[IFTTT (IF This, Then That)|IFTTT]]). They are set up in LT Setup on the '''Webhooks''' tab, which has two parts:
 
'''Webhooks''' connect the Larnitech system with any internet service that can send or receive HTTP requests (for example [[IFTTT (IF This, Then That)|IFTTT]]). They are set up in LT Setup on the '''Webhooks''' tab, which has two parts:
 
* '''Events''': the Larnitech server sends an HTTP request to an external URL when something happens in the system.
 
* '''Events''': the Larnitech server sends an HTTP request to an external URL when something happens in the system.
 
* '''Actions''': an external service sends an HTTP request to the Larnitech server, and the server changes the state of an item.
 
* '''Actions''': an external service sends an HTTP request to the Larnitech server, and the server changes the state of an item.
  
−
== Events ==
+
== Events == <!--T:2-->
 
An event has the following fields:
 
An event has the following fields:
 
{|class="wikitable"
 
{|class="wikitable"
Line 20: Line 21:
 
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.
 
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.
  
−
== Actions ==
+
== Actions == <!--T:3-->
 
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).
 
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).
  
 +
<!--T:4-->
 
To run an action, call the URL:
 
To run an action, call the URL:
 
* in the local network: <code><nowiki>http://CONTROLLER_IP/webhook/?key=API_KEY&name=ACTION_NAME</nowiki></code>
 
* in the local network: <code><nowiki>http://CONTROLLER_IP/webhook/?key=API_KEY&name=ACTION_NAME</nowiki></code>
Line 31: Line 33:
 
* <code>ACTION_NAME</code>: name of the action from the '''Name''' field.
 
* <code>ACTION_NAME</code>: name of the action from the '''Name''' field.
  
 +
<!--T:5-->
 
The server answers with JSON. An error answer has <code>"result":"ERROR"</code> and a message, for example <code>Error Key</code> (wrong key) or <code>Action not found</code>.
 
The server answers with JSON. An error answer has <code>"result":"ERROR"</code> and a message, for example <code>Error Key</code> (wrong key) or <code>Action not found</code>.
  
−
== Example ==
+
== Example == <!--T:6-->
 
The settings are stored in <code>/home/settings/webhooks.json</code>. Example with one event with feedback and two actions:
 
The settings are stored in <code>/home/settings/webhooks.json</code>. Example with one event with feedback and two actions:
 
<syntaxhighlight lang="json" line>
 
<syntaxhighlight lang="json" line>
Line 62: Line 65:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 +
<!--T:7-->
 
See also: [[IFTTT (IF This, Then That)]], [[API2]].
 
See also: [[IFTTT (IF This, Then That)]], [[API2]].
 
</translate>
 
</translate>

Latest revision as of 12:37, 5 November 2026

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

Webhooks connect the Larnitech system with any internet service that can send or receive HTTP requests (for example IFTTT). They are set up in LT Setup on the Webhooks tab, which has two parts:

  • Events: the Larnitech server sends an HTTP request to an external URL when something happens in the system.
  • Actions: an external service sends an HTTP request to the Larnitech server, and the server changes the state of an item.

Events

An event has the following fields:

Field Description
Name Name of the event. It is used in the script that sends the event.
URL Address that the server calls.
Method GET (default) or POST.
Feedback Optional. Item address and a regular expression: the value found in the answer is written to that item.

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.

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.