I have long been fascinated by the topic of technology in general and home automation in particular. A couple of years ago, this passion developed into a professional activity that I still do today. My company specializes in installing and configuring the Convenient Home systems (well, it doesn’t allow me to call my conscience a smart home what can be done for adequate money).
Work with the object can be divided into 3 stages:
As practice shows, in the first stage, absolutely all clients believe that controlling the light from the phone is the main function of the system, which they will use constantly especially in the toilet . But after some time after use, it turns out that a minority uses this option. Since, basically, the users of the system are the owners of the iPhone, to control the house, you must unlock the phone, open the application, select the desired room and then turn on the light. It turns out that it is much easier for a person to reach the nearest switch.
I understood that this process can be somehow simplified, but I did not seriously deal with this. But recently, two interesting updates came to the market, which pushed us with @RagimovRV to try to add some ingenuity to my and Convenient Homes clients.
Almost under each article on Habrahabr and Geektimes, in which the noolight equipment is mentioned, there is a comment with the question: "When will the feedback appear?". More than a year ago, at an exhibition in St. Petersburg, Igor Chavlytko, director of Nootech’s company, said that they were going to start working on blocks with feedback and encryption, which might be working on a different frequency. All summer we talked about the expected blocks and discussed possible functions.
Finally, in mid-October, the first test devices came to us to detect errors, test new features and obtain information about missing features. The test kit consists of two power units and one usb / uart transceiver. The blocks are marked with the SLF-200 marking, from which it follows that we have a non-dimmable block (sl) with a capacity of 200 watts (what the number means) and the new letter F now indicates the use of the new protocol, described below. The transceiver can be connected to a computer via USB port or disassembled and connected via UART to Arduino, Raspberry Pi and similar devices.
Externally, the adapter and the unit do not differ from their predecessors, but it is worth noting that there are places for soldering wires on the power unit board of the test sample, to which a switch or button can be connected (the operating mode is configured by a special service command from the adapter, the default is a switching switch) .
To control the module, you need to send a packet of 17 bytes through the UART. In case of successful reception of the control packet, the module will transmit a response, which will contain information on the status of the adapter and additional information from the blocks.
Data transfer to adapter:
ST | MODE | CTR | Res | CH | Cmd | FMT | DATA | ID | CRC | SP |
---|---|---|---|---|---|---|---|---|---|---|
one | one | one | one | one | one | one | four | four | one | one |
171 | 172 |
Adapter response (read data from adapter):
ST | MODE | CTR | TOGL | CH | Cmd | FMT | DATA | ID | CRC | SP |
---|---|---|---|---|---|---|---|---|---|---|
one | one | one | one | one | one | one | four | four | one | one |
173 | 174 |
Perhaps it is worth decipher the following abbreviations:
ST - Starting Byte
MODE - Adapter operation mode (receiver / transmitter, nooLite / nooLite F, service mode)
CTR - Adapter Management
RES - Reserved, not used.
TOGL - The number of remaining responses from the adapter
CH - Channel Address, cells to bind
CMD - Team
FMT - Format (The amount of data transmitted with the command)
DATA - 4 bytes of data
ID - Block identifier (Device address in the nooLite-F system)
CRC - Checksum
SP - Stop Byte
Commands that have been added to the new version of the blocks:
Code | Team | Description |
---|---|---|
128 | Status Request CMD_Read_State | Request to get block status. The FMT contains information about the field with the data that is requested. Answer - CMD_SEND_STATE |
129 | Device Configuration CMD_Write_State | Configure the device. The FMT contains the address of the field to be configured. D0 ... D3 correspond in the specified field. Answer - CMD_SEND_STATE |
130 | Transmit CMD_Send_State | FMT value = type of data requested or error code; 0 - General Information |
I will not provide a table of state setting data register values, but I will indicate which parameters are available for setting.
Stored in long-term memory:
Not stored in long-term memory:
At the moment, together with @AlekseevAV , we have implemented support for almost all adapter capabilities (except for receiving information from consoles and sensors), in a small python adapter that transforms the UART API into a HTTP API compatible with the nooLite Gateway API. The code, documentation and installation instructions are available in the Bitbucket repository , which will be actively updated after the publication of the article.
Now, using HTTP GET request to port 8080 of the computer on which the adapter is running, you can perform any actions available on the noolight system.
Examples of using:
http://192.168.2.18:8080/api.htm?ch=1&cmd=2&mode=0 # nooLite 1.0, 1 http://192.168.2.18:8080/api.htm?ch=8&cmd=0&mode=0 # nooLite 1.0, 8 http://192.168.2.18:8080/api.htm?ch=1&cmd=2&mode=2 # nooLite 2.0 (F), 1 http://192.168.2.18:8080/api.htm?ch=0&cmd=8&mode=2 # nooLite 2.0 (F), 0
For more information on the adapter API, please visit the official wiki .
A nice bonus: the MTRF-32 adapter, as the name implies, supports 32 channels, it is compatible with old and new blocks, but the addressing of old and new blocks is different. Thus, you can bind 32 old and 32 new blocks at the same time. Or 32 new units in normal mode and 32 in backward compatibility mode.
The second pleasant event is the appearance of the icon for the Home application on all Apple mobile devices updated to the latest (10) version of the operating system. The HomeKit platform was introduced on June 2 at the WWDC'2014 conference, but that it was not an understanding, but now it would simply be wrong to not know what is behind this icon.
After reading the official documentation on the Apple website, it became clear that this application would help to unite devices of different companies in one place with the minimum amount of effort and settings, if each of these companies made timely efforts to this. Indeed, the site shown looked very interesting, and I climbed to look at the list of compatible devices. He was very small and it made us think that there should be a way to deceive Apple and connect their devices as official ones.
Indeed, there is such a method, and it is called Homebridge . This is a software product written in node.js that allows you to provide the apple technology with information about devices for which there is a plugin and interaction parameters specified. Everything is clear, let's do. You can try to find the plugin that supports your hardware here.
Idea : Imagine that there is an apartment equipped with nooLite devices for the most popular tasks:
Some blocks are SU (dimmable lighting zones), the rest are SLF.
Objective: To begin to manage this equipment through the application "Home" and voice - through Siri. Use Raspberry PI 3 as a controller with a USB / UART nooLite transceiver.
First of all, you need to install HomeBridge on the Raspberry Pi (complete and understandable instructions are in the wiki of the official repository, that is, here ).
After that, we need to write plug-ins describing the actions needed to control the accessory in one way or another (on / off / change other parameters) and to obtain information about the state of the device (for different devices - different characteristics of the state).
We decided that the best interaction between the plug-in for Homebridge and noolight devices would be to perform HTTP requests to the localhost or ip of the Ethernet gateway according to the API of the gateway or the almost identical API of the software adapter in Python, which I described in the first part of the article.
To control the devices listed in the "idea" section, we wrote three plug-ins, each of which I will discuss in order:
The Somfy motorized roller blind , connected via the noolight SR unit, is controlled using the scenario buttons, the up / down / stop commands are available. The blind plug-in that was in npm allows you to send a command to move the shutter up or down, but does not support stopping in the middle of the path. We redesigned this plugin so that the "open N% blinds" command worked correctly. At the same time, after the command for fully opening or closing the blinds is calibrated, and if previously its state was not changed via HomeBridge, the next command to open the curtains to the specified level will be executed correctly. Link to npm package. With a properly configured HomeBridge, installation is performed with a single command.
sudo npm install -g homebridge-noolite-http-blinds
For the accessory to work, you need to describe it in the config.json file located in the ~ / .homebridge / config.json folder. An example of the description of the curtains, which is tied to my adapter. Three channels are used for control, each of which is responsible for translating the curtains into a specific state:
In addition, you need to set the parameter "motion time" - the time of movement of the curtain in milliseconds, which is necessary to go from fully open to fully closed state or vice versa.
{ "accessory": "NooLite-HTTP-Blinds", "name": "", "up_url": "http://192.168.2.18:8080/api.htm?ch=12&cmd=7&mode=0", "down_url": "http://192.168.2.18:8080/api.htm?ch=10&cmd=7&mode=0", "stop_url": "http://192.168.2.18:8080/api.htm?ch=11&cmd=7&mode=0", "http_method": "GET", "motion_time": "31000" }
The outlet that turns off the audio system with a capacity of 100 watts, so that it does not make noise at night. The socket can only be in two states: on or off, and in addition to this state, we cannot display any additional information in HomeKit. After completing the plugin for curtains, this plugin was very easy for us, and now you can install it too. Link to npm package.
sudo npm install -g homebridge-noolite-http-outlet
An example of the description of the outlet tied to the 3rd channel of the transmitter when using a new SLF unit.
{ "accessory": "NooLite-HTTP-Outlet", "name": "", "on_url": "http://192.168.2.18:8080/api.htm?ch=3&cmd=2", "off_url": "http://192.168.2.18:8080/api.htm?ch=3&cmd=2", "status_url": "http://192.168.2.18:8080/api.htm?ch=3&cmd=128", "http_method": "GET" }
Light control is the largest, most complex and interesting plugin. It supports on / off / setting the brightness for conventional lamps and color settings for LED strips connected via an SD unit. Link to npm package.
sudo npm install -g homebridge-noolite-http-rgb
An example of the description of the lamp, tied to the 3rd channel of the transmitter, when using the old SD unit.
{ "accessory": "NooLite-HTTP-RGB", "name": "RGB LED strip", "switch": { "powerOn": "http://192.168.2.18:8080/api.htm?ch=3&cmd=2&mode=0", "powerOff": "http://192.168.2.18:8080/api.htm?ch=3&cmd=0&mode=0" }, "brightness": { "url": "http://192.168.2.18:8080/api.htm?ch=3&cmd=6&br=%s&mode=0" }, "color": { "url": "http://192.168.2.18:8080/api.htm?ch=3&cmd=6&fmt=3&d0=%s1&d1=%s2&d2=%s3&mode=0" } }
Important note: to control dimmable lamps you need to set the parameter "brightness", and to control tapes - "color", both parameters are not immediately specified, because when setting the parameter "color", "brightness" is ignored. At the moment, getting the state of the block is not implemented, this feature will be added in future versions.
Cherry on the cake - camera support
If you look at the list of possible Siri commands for the "Home" application, you will notice a very interesting command "show the camera in the living room", which suggests that HomeKit does not just support cameras for displaying on one of the room screens, but also allows you to quickly open it from the locked screen of the phone. We figured out how to add a camera using HomeBridge.
There is something called "camera-ffmpeg" in the list of plugins. Judging by the instructions, the developer of this plug-in used it only on a poppy, and performance on other platforms, in our case raspberry, is not guaranteed. We decided to try and install this plugin, as well as the "ffmpeg" it needs. For the initial test, we found an RTSP stream with cartoons on the Internet and added it to the configuration file. We launched HomeBridge, added a virtual camera through the application, and it started working, the cartoon was successfully played on one of the screens of the Home application, the only nuance was a shutdown approximately every 30 seconds.
But the goal was not to watch cartoons, but images from real cameras, and we moved on to more vital tests. The task was to connect the camera manufacturer RVI. In the web interface, the request format was given to get the rtsp stream, which we copied to the config file and expected to see the image from the camera. But it was not so easy. When trying to open the camera, we saw only a rotating ring on the screen, notifying of an attempt to load an image, but the picture did not appear.
In order for everything to work, we had to rebuild ffmpeg. This process took a whole day, but as a reward for patience, the necessary function became available. It also turned out to take a video stream from the Giraffe and Hikvision cameras. The format of the RTSP request for a video stream from a camera or a DVR channel from most manufacturers can be found on this site
In order for you to earn a similar configuration, you can not repeat the actions performed from the very beginning. We have posted the ready-to-build FFMPEG package, as well as the fixed ffmpeg.js on the Yandex disk . Below I offer a brief installation guide:
You also need to install the camera-ffmpeg plugin, for this we run the following command:
sudo npm install -g homebridge-camera-ffmpeg
It turned out that the camera turns off after about 30 seconds of viewing due to the fact that ffmpeg tries to output data to the console, and the plugin does not process this output. To prevent the camera from turning off, we modify the plugin so that the ffmpeg output falls into "/ dev / null". This fix is ​​added to the file that we downloaded in the first step, so simply replace the file "ffmpeg.js" in the plugin folder and install the package that allows the plugins to write to "dev / null".
And we set the parameters for the camera in the config.json file
{ "platform": "Camera-ffmpeg", "cameras": [ { "name": "Camera Name", "videoConfig": { "source": "-re -i rtsp://myfancy_rtsp_stream", "maxStreams": 2, "maxWidth": 1280, "maxHeight": 720, "maxFPS": 30 } } ] }
Where "rtsp: // myfancy_rtsp_stream" is the path to the rtsp stream of your camera.
Now you can move the camera to the correct room, and it will show the image, updated every second. When you click on this image, a live broadcast will open, and Siri will understand what to do if you tell her "show the camera in <room name>".
To connect HomeBridge to the phone, you need to go to the "Home" application, click the "Add accessory" button, a bridge with the name specified in the settings will appear in the list of offered accessories. Click on it and consistently add all the proposed accessories, while you can immediately arrange them in the rooms to which they belong. An example of the "config.json" file for connecting lights, blinds and sockets can be downloaded from the link .
Thanks for attention! I hope the article was interesting and useful for you.
Source: https://habr.com/ru/post/372811/
All Articles