Smart Home - voice control in three steps. Raspberry + HomeKit

Dear friends!



We decided to share with you a budget ready-made solution, we hope you appreciate our efforts. The solution is proven, working. In the attachment, you can download all program files and settings. We give everything for free.



A smart home for the customer is basically a “toy” that you can brag to your friends, but these games are not worth the small efforts of the integrators!



It will be about some problems and solutions related specifically to lighting in the house, as an integral unit of the “smart home”.



Problem 1: If the system is centralized, then in the event of a central controller failure, the program cannot control the light-on relay.



Solution : Use distributed control modules with internal logic, in our experience one of the most proven devices in this is the programmable relay PR200 manufactured by OWEN. We recommend using version 220v, as household switches are designed specifically for this voltage and there will be fewer problems with the logical "unit" at the digital input.



image



This device has 8 channels (relays) that can be programmed using internal logic (as a distributed system), additional 2pcs expansion modules are additionally connected. 8 channels each, but there is a risk of being left without more controlled lights when the PR200 itself fails (8 channels versus 24), if you are planning to save, think!



image



Despite the fact that the program looks simple, we went to it for several years through no fault of our own, the Aries company relatively recently (after the appearance of PR200) ​​added the ability to manage a network variable both from the outside and from the inside.



More about the program:



I8 is a digital input with 8 switches in a house or room



RTRIG - front detector, necessary for the formation of a single (per program cycle) impulse



TO INT - Converting Bool to INT could be dispensed with, but the Slave network variable in Owen Logic does not support bool.



XOR - exclusive or, if on one input 1, then output 1, if both inputs apply 1 output will be reset, the main program element that decides to turn on or off the light by pressing the switch.



Relay8 is an input and output network variable, as I said above, recently we can use these two variables with one Modbus register (address), this allows us to save the necessary state to it both outside and inside without using different triggers. These network variables have non-volatile memory, so when the voltage jumps, the lighting will return to its last state.



TO BOOL - convert INT to BOOL value, because the output relay has the status False / True.



Step 1 : the program for 8 channels can be downloaded from the link at the end of the article and uploaded to a programmable relay, do not forget to change the target platform for your version of PR200 / 110, otherwise the device will fail to flash!



Problem 2: standard household switches have the state turned on or off, which fundamentally contradicts the logic of lighting control in a smart house, we need buttons without fixing (with springs).



Solution 1: Use ready-made buttons without fixing, which are available for most switch manufacturers such as Shneider, Biticino, ABB, etc. (recommended solution, even though the buttons are in the same position and the lamps are on and off, it looks aesthetically beautiful)



Solution 2: Catch in PR200 / 110 a change in the input state when using a typical household switch with a latch and then send an impulse to the program that was downloaded above, if the light was on, it will go out and vice versa (not recommended, because after a while all the buttons will be mixed up and down)



Problem 3: the top level in most manufacturers of smart home systems does not reach aesthetic and functional perfection.



Solution: we use Apple's HomeKit, which: is functional, convenient and has voice control.



Step 2: dock PR200 / 110 with HomeKit



To do this, the following tools are required:



Recommended Solution for Demos:



Raspberry Pi 2/3/4 and to it usb rs485 converter (for example, with Alliexpress)



image



The solution recommended for installations based on the Raspberry CM3 + module in industrial design with 2 two built-in RS485 ports:



image



Connect your Raspberry-based device to the power and home network, preferably with a patch cord, and not via wifi.



Connect the RS485 port of your device and the PR200 / 110.



Next, determine the IP address that your router issued and connect via SSh, for example, through the PUTTY program (by default, the username is pi password raspberry)



Install the node-red software for docking the HomeKit protocol at the upper level and Modbus Rtu at the lower level, see the installation instructions here .



Do not forget to make your node-red service for startup.



Install HomeKit and modbus package for node-red



cd ~/.node-red npm install node-red-contrib-homekit npm install node-red-contrib-modbus sudo reboot
      
      





We are waiting for the reboot and go to the browser “YOUR IP”: 1880 (for example, 192.168.1.110:1880)



We copy the next stream (the code at the end of the article) and paste the node-red rules engine into the web interface



Go to Menu -> import -> insert stream code



image



image



image



You must apply the stream by clicking on the Deploy button



In case of failure, we advise you to correctly specify the RS485 port in the Modbus settings of the “Modbas Request” and “Write Reset FC6” plugins (example / dev / ttyUSB0).



For reliability, reboot your SSH device à sudo reboot



Step 3 Setting up the application on your Apple device is quite simple.



image



Give a name to our house at will, in our example PR200



image



Add and agree to use an uncertified accessory



image



We enter the access code, in our case 111 11 111, it can be replaced in the Node-red settings in each of the HomeKit accessories



image



We add all our lamps to the rooms, this can be done later.



We wish you a pleasant use of such an inexpensive, but very convenient system.



Attention:



We do not agitate the commercial use of the HomeKit protocol, the developer takes all actions contrary to the APPLE licensing agreement on the use of the HomeKit protocol!



The program for ARIES PR200 and the script for NodeRed can be downloaded for free here .



All Articles