Эта страница является
переводом страницы
Legrand Netatmo. Перевод выполнен на 100%.
Legrand Netatmo Home Control
Legrand Netatmo Home Control is a module to work with Legrand Netatmo equipment (smart spckets, heaters, dimmers, etc.).
documentation was last updated on 26.10.2022
On Septermber 1, 2022 support of Legrand Netatmo Home Control was stopped. The skill is called back due to API change of Legrand manufacturer.
Legrand Netatmo Home Control is a module to work with Legrand Netatmo equipment (smart sockets, heaters, dimmers, etc.) This module can be build in a project in iRidium studio and equipment can be controller from the i3pro app on a control panel (iOS, Android, Windows, Mac).
A license is required.
Connection
The module works via HTTP protocol. It is in the online status only when data are sent, it is offline in the remaining time. The following is required to connect to equipment:
1 Download the Home+Control app from Play Market or App Store;
2 Add required devices in the Home+Control app;
3 Set the module and add required commands and feedback channels to your project.
Integration of Module to Project
We made a special panel project that helps to learn all devices added in the app and required commands and feedback channels for these devices. To add a module to your project, it is enough to merge project tabs and confirm merging.
The module contains (main components):
- Java Script:
- "Driver" - the basic logic of the module is written in this script (no changes are required);
- Script 1" - a script with examples of functions fro additional logic of a project (all descriptions to the driver are written in the script comments).
- Devices:
- Office (house name) - an example of a driver with commands and feedback channels to control equipment. It can be deleted after importing devices from a .json file. Additional commands and feedback channels can be added to the imported file from the table.
- Auth - a driver responsible for authorization on the manufacturer's cloud.
Getting Legrand Activation Key
To get Legrand activation key, do the following:
1 Register at Legrand official web-site;
2 Go to the MY APPLICATIONS tab and click Create new;
3 Fill in all required fields in the form to register a new app.
It is obligatory to choose Mobile application in the Type of the application, the First Reply Url field is filled in automatically with the following link: https://eliotclouduamprd.b2clogin.com/oauth2/nativeclient
It is recommended to select everything in the Scopes section for the correct work of the app.
4 After the app is registered and approved, a letter will come to your e-mail with client id and client secret. These keys must be copied to the script of the project (see description in the Work in iRidium studio) section.
5 Now subscribe to Api Legrand. To do it, go to the Api > SUBSCRIPTIONS > Stater Kit tab.
6 Click Subscribe.
7 Enter the subscription name and click Confirm.
8 You are subscribed. You can see and change the keys and unsubscribe in the My Subscriptions page.
Work in iRidium studio
The module is set in several steps:
1 Open the example of a project given above in iRidium Studio and enter client id and client secret in the Driver script.
1 Start a panel project given above (project template) in the Emulator;
2 An authorization page is displayed in the app window, where it is required to enter an e-mail address and a password of the existing Legrand account (this account is also used to authorize in the Home+Control app);
3 Confirm that you give the i3 pro app access to your Legrand data;
4 After access is given, a project page is opened. Click "Get JSON" button to get a list of commands and feedback channels of added equipment. The list is formed in iRidium Log in the JSON format.
Example:
"Commands":[{"Name":"Office Lamp|Set value", "Direction":1}, {"Name":"Office Lamp|Get value", "Direction":1}]
"Feedbacks":[{"Name":"Office Lamp|Reachable", "Direction":2}, {"Name":"Office Lamp|Value", "Direction":2}, {"Name":"Office Lamp|Status", "Direction":2}, {"Name":"Office Lamp|Consumption type", "Direction":2}, {"Name":"Office Lamp|Consumption value", "Direction":2}]
- Name - the name of a command/ a feedback channel. A command / a feedback channel is formed this way:
room name + blank space (" ") + device name + vertical line ("|") + type of command / feedback channel.
- Direction - type (1 - command, 2 - feedback channel).
5 Copy received data into a text file and save it in the *.json format.
6 Click Scanner / Import > Universal import from JS (*.js, *.json) in the Device tab in iRidium Studio and choose a driver saved earlier (see point 5). A driver will be added to a project with commands and feedback channels for all devices.
Commands & Feedbacks
As the driver works via HTTP protocol, to get the status of equipment it is required to send a Get request to a corresponding feedback channel.
Legrand limits the number of requests to 1000 for every account. To decrease the number of requests, use the Get plant or Get ambientcommand, as they request all feedback channels of a device at a time, thus the number of requests is saved.
All added commands and feedback channels are subdevided into types:
CommandType
| Command |
Value* |
Description
|
| Run scene |
not used |
Start a concrete scene (used only with scenes). Example: Scene1|Run scene The name of a scene must be the same as in the Home+Control app.
|
| Get plant |
not used |
Get values from all feedback channels. Example: Get plant
|
| Get ambient |
not used |
Get values from feedback channels only in one room. Example: Kitchen|Get ambient
|
| Set value |
Value |
Set a value for a chosen device. Example: Office Lamp|Set value
|
| Get value |
not used |
Get a value for a chosen device. Example: Office Lamp|Get value
|
| Get json |
not used |
Get info about all commands and feedback channels of equipment in the json format (the info is displayed in project log journal). Example: Get json
|
| Authorize |
not used |
Authorize in the app with Legrand account. Example: Authorize
|
| Get token |
not used |
A service command that sends a request to get a token from a panel project (for a server project). Example: Get token
|
| Refresh token |
not used |
A service command that updates the current token forcefully. Example: Refresh token
|
Value is a value that must be entered when a command is drag'n'dropped on an item. If an item does not use a set value, any value can be entered.
FeedbackType
| Feedback |
Value* |
Description
|
| Value |
Value |
Current value. Example: Office Lamp|Value
|
| Status |
0 / 1 |
Current value. Example: Office Lamp|Status
|
| Reachable |
0 / 1 |
Current connection status of a device. Example: Office Lamp|Reachable
|
| Mode |
Text |
Current mode (only for automatic device). Example: Office Device1|Mode
|
| Battery |
0-100 |
Current battery level (for a remote). Example: Wireless switch |Battery
|
| Consumption type |
Text |
Type of power consumption (Watt, Watt per hour). Example: Electrical cabinet Lamp|Consumption type
|
| Consumption value |
Value |
Current value of power consumtion. Example: Electrical cabinet Lamp|Consumption value
|
| Out of commands |
0 / 1 |
A message about exceeding the limit of requests per day (0 - not exceeded, 1 - exceeded). Example: Out of commands
|
| Out of commands message |
Text |
A message about exceeding the limit of requests per day Example: Out of commands
|
| Need authorize |
Text |
A message with an authorization request. Example: Need authorize
|
Value is a value that a feedback channel will display on a graphic item.
Setting Commands and Feedback Channels
To control equipment it is required to set commands (Commands) and feedback channels (Feedbacks). To send a command, drag'n'drop it on a graphic item and enter a value to send. To display feedback, drag'n'drop a feedback channel on a graphic item and choose how to output or display a value.
Read more about work with graphic items in the
"Types of graphic items" article.
Creating Script
Script 1 contains templates of functions that can be used to transform values of feedback channels (text value of a feedback channel can be transformed to a numerical one and vice versa) and to create additional logic in a project (for example, to send a push-notification when the number of requests is exceeded).
How to do it:
1 Replace the name of the "Office" driver into the name of your house that was added with the help of device import in the first line;
var l_oTest = new Legrand.Netatmo(IR.GetDevice("Office"), IR.GetDevice("Auth"), true);
2 Use the template of given functions to create logic:
l_oTest.onCommandsLimit = function() {
//do something
}
l_oTest.onModeReceive = function(in_sName, in_sText) {
return in_sText
}
l_oTest.onBatteryReceive = function(in_sName, in_sText) {
return in_sText
}
- .onCommandsLimit - actions to limit the number of attempts to get values;
- .onModeReceive - used to transform received values (for equipment of the "Heater" type);
- .onBatteryReceive(in_sText) - serves to transform received values (for equipment of the "Battery" type).
Example 1 (sending push notifications to a panel when the limit of requests is exceeded):
l_oTest.onCommandsLimit = function() {
IR.SendPush('You have reached limit for commands', '', 1);
}
Пример 2 (transforming a text value into a numeric one):
- in_sName - device name (till the vertical line);
- in_sText - received value.
l_oTest.onBatteryReceive = function(in_sName, in_sText) {
var l_Value = in_sText;
if(in_sName == 'Room 1 Light 1') {
l_Value = 0;
switch(in_sText) {
case "full":
l_Value = 0;
break;
case "high":
l_Value = 1;
break;
case "medium":
l_Value = 2;
break;
case "low":
l_Value = 3;
break;
case "very_low":
l_Value = 4;
break;
case "unknown":
l_Value = 5;
break;
}
}
return l_Value;
}