Zero-based to create the whole house intelligent control system Chapter 1: The establishment of intelligent home control center and linkage of Xiaomi Bolian

There are a lot of original sites on smart homes. When the landlord built his own smart home control center, he also read almost all of the site's related originals. It also helped me in the construction of the smart home. Thank you first. When it is useful to everyone's original content, it will be inserted in the relevant paragraph for your reference. This article is a long one, it is recommended that you are interested in the first collection, and then do it when you do it. Otherwise it is very boring to read. The first thing to say is to build a smart home. Because he bought the Bomini SP mini smart switch long ago to remotely control the home purifier. Then also bought Hongyan's intelligent switch, the results found that the pit father is the need for zero fire line to work, this transformation is really a big project, had to give up, but fortunately behind the millet ecological chain aqara is also launched a green fire single version of the wall switch With millet gateways, it is very convenient to perform linkage control with other millet products. But the problem has come. In general, most smart homes nowadays mostly use the mobile phone APP to control and manage the devices. Devices of different brands are not compatible with each other. They must be controlled by their own APPs. Said linkage. This is very bad, to know that I want to open an app control device, I already feel very annoying, not to mention having to install multiple apps. Therefore, we have been tempted to say how to open up the two independent smart home series of Xiaomi and Bolian, which is also the core content of this original article. Of course, in addition to this, the series will also include: Connecting Philips livingcolors Gen2 to the smart home, Gen2 is a relatively living colorings product. Unlike the G1, which uses a simple 2.4G remote control, it uses the zigbee network, but it is not directly supported by the Hue network. So in the next article we will talk about the connection between livingcolors Gen2 and Hue Bridge. Then it is DIY's AirSense air detector access domoticz steps, the landlord mentioned in other articles such a gadget, and also promised that everyone will release all the source code, but now there is no time to do even connect to domoticz code Writing, the camera may first release the non-network version of the tutorial (writing original is really alive, ah, such an article does not complete 5,6 hours simply can not). Since domoticz can already obtain air data in the home, the next thing to do is linkage, including the linkage of air purifiers and fresh air equipment. Of course, the simplest linkage is controlled through the switch of the smart socket, but this technology has no technical content, so the main reference is the linkage and infrared remote control of the optional gear for DIY air/fresh air. Well, the pit first digs so big, let us fill in slowly. The content first mentioned today mainly involves the following equipment: The first is a raspberry pie development board, which is the control center of the entire smart home, and all the programs will run on this development board. Of course, it does not necessarily require you to buy a raspberry pie, because all the software involved in the text can be run on windows, Mac OS, and even Linux and even Synology. Just the landlord is more like a thing to do to a device, so that the restoration of a certain function will not affect the use of other features. The landlord's development board is rasberry pi 3B. Original authentic raspberry pie 3 generation B type raspberrypi onboard Bluetooth and WIFI e14 version 299 yuan Jingdong direct link This is a link from Jingdong's third party. The Ma family will be cheaper. By the way, don't forget to give your raspberry pie with a TF card. 16G is enough. Then the millet smart home package: Although this is a millet smart home set, it actually refers to the aqara product. In addition to those shown in the figure, there is a temperature and humidity sensor. Wall sockets, switches, etc. As for other products of Mijia, whether it is air purifiers or smart patch panels are not supported. To put it plainly, in fact, domoticz only supports the gateway, so the devices connected to the gateway can all be supported. Other products currently only have yeelink's lights open and the protocol can be added separately. The following are all the accessories that can be connected to domoticz at present (Note: Gateway needs to be more than 2 generations, ie gateway with internet radio) The Bolian equipment owners only SPMINI socket, but the R2 gateway, A1 detector can also be supported, but to tell the truth, if you do not have Bolian equipment, it is recommended not to buy, all aspects are far worse than the Mi In particular, security, as will be discussed below, as long as you know the address of the Broadcom device, you can easily send instructions to operate it without any user authentication measures. Raspberry pie system installation This is the most basic job. Although there are many versions of the Raspberry Pi system on the Internet, it is very convenient to find various solutions for future problems. Therefore, we recommend using the official Raspbian system here: Download address: Stamp It is recommended that you use Thunder download. After downloading, you will get a 201X-XX-XX-raspbian-jessie.img file. We are ready for use. Then download the SDFormatter to format the TF card. After the download is complete, the TF card is formatted again. This step is unnecessary. Download address: Stamp Then we also need a tool Etcher to burn the img file into the tf card. Download address: Stamp Follow the steps: 1. Select the raspbian-jessie.img you just downloaded. 2. Select TF card driver. 3.FLASH, waiting to be completed just fine. After Etcher burns the system image to the TF card, we can insert the TF into the Raspberry Pi and then start the Raspberry Pi. Here is a reminder that the Raspberry Pi 3b uses a 5V 2A power adapter and the power cord To be as short as possible, the shorter the better. In the first step, we also need an HDMI monitor or TV. The mouse and keyboard are connected to the Raspberry Pi and then turned on. Will soon be able to enter the graphical desktop, the landlord here is used to display the VNC remote, so the display ratio is a bit of a problem, we do not mind. The first step to be done here is to connect to the wireless network. Click the WIFI icon in the upper right corner, select the SSID, and enter the wireless password. However, there is an extra step here, which is to set the IP address to manual static. After all, we use it as a server. The dynamic address may change after each disconnection: The specific approach is to right click on the WIFI icon in the upper right corner to select the first Wireless&..... Then select wlan0 on the right side of the interface, check off the box of Automatically...., fill in the IP address and gateway of your home LAN, and the DNS server. Then click apply and close. Then open the browser and see if you can go online normally: OK, no problem, the next step is to open SSH, after all, the old mouse and keyboard display with the Raspberry Pi is not very convenient. Click the Raspberry Pi icon and choose Preferences > Raspberry Pi Configuration. Then select the interfaces tab, SSH Enabled, click OK. Then you can close the Raspberry Pi, unplug the mouse and keyboard display, and move it to any place where the WIFI signal is good (note that it must be guaranteed that the WIFI signal is good). Then we download putty, because the official website is walled, in order not to cause everyone trouble, so please download it yourself Baidu. Remember to choose a large download station to avoid unnecessary losses. Open putty after the download is complete, the interface is as follows: In the host name, just fill in the IP of the Raspberry Pi you just set, and select the Connection type for SSH. Then OPEN. Of course, for the convenience of the next connection, you can fill in a name in Saved Sessions, click save, then you can double-click to open. Enter the user name pi, the default password is rasberry (the cursor will not change when you enter the password, enter the carriage return on the line) After seeing the success of pi@raspberrypi:~$, the first step we must take is to change the default password. The command is as follows: Sudo passwd pi Ctrl+C copies the commands inside the gray box and pastes it to the right of the putty window. It will allow you to enter the new password twice. If the two passwords are identical, the password will be modified successfully. Then we have to set the time and time zone of the Raspberry Pi. The first thing to do is to turn on NTP to synchronize the raspberry pie time with the network time: Sudo timedatectl set-ntp true Then set the time zone: Sudo dpkg-reconfigure tzdata The following screen appears: In China, we choose Asia, then return, and choose Chongqing. At this point the terminal will return to command line mode. At the same time, at the top of the command line, we can see that Local time is now:......, we check if it is the same as our own time. If it is the same, the time of the Raspberry Pi will be set. In order to allow us to install more smoothly, then we Set the mirror source. The command is as follows: Sudo nano /etc/apt/sources.list Add at the beginning: Deb http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib Deb-src http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib Then add # in front of the original mirror source, as shown below: Then press Ctrl+X to exit (remember to choose Y to save). Then run the command sudo apt-get update to update the image source. Sudo apt-get update At this point, our Raspberry Pi system has been completely and set up. Below we will say domoticz installation and setup. Domoticz installation and setup With regard to smart home systems, there are many open source software, such as Home Assitant, and our valued friends have also written originals: Raspberry Pi to create home center tutorial (full version) additional modifications (2017-05-01 23:38:35): To tell the truth, I don't know how many people actually follow the tutorials, but I still try to improve and update this tutorial. . First of all, the Hassbian system comes with a Home-assistant, so please use the value of the Hassbian system to skip 3.1 and go straight to 3.1.1. Second, if step 3.1.1 fails, you can install it manually. Wu Wu Niang and Di Fat | Likes 135 Comments 93 Favorites 1k View Details Even if you all use millet equipment, there is a simpler: [Updated] millet gateway access Homekit complete tutorial, voice control of home equipment! - Xiaomi community official forum bbs.xiaomi.cn direct link But for the landlord did not choose these two but use domoticz, first said that through the homebridge-aqara millet gateway device to join the homekit, this approach is undoubtedly the simplest, but it only supports aqara devices, and does not support the gateway Lamp and millet wireless switch (in fact, homekit does not support multi-segment mode of millet wireless switch). And can not be used across platforms, which is limited to the ios10 or more equipment can be used, the limitations are too great, so the landlord gave up. While Home Assitant+Homebridge can be used across platforms, it can also control gateway lights, but still does not support millet wireless switch (to be confirmed), but more importantly, he needs to add yaml files to add and configure devices. It is still inconvenient to use. And domoticz mainly read this original: Open source IoT platform domoticz and wild wifi module esp8266 article one: garage door remote control Keyou want to engage in smart home, after I strongly advocated, let me use his garage door tester to achieve the effect of the following video. With one beat, please see Guan Haihan. Slight delays in handling are sufficient to deal with garage doors that have low real-time requirements. Of course, being able to remote control is just the first step in smart. According to the various sensor data fed back to the central controller for automatic adjustment is the goal of the smart home. Existing Internet of Things Solution with Central Controller blindlight | Like 73 Comments 92 Favourites 533 View Details Although the original author did not write very detailed, but overall can understand the power of domoticz, and support for Arduino and ESP8266. The most critical is that, after domoticz is configured, adding devices will almost never need to change any files in command line mode. It can all be done in the web interface. Of course, the disadvantages are... UI is ugly.... Haha, the landlord spent a lot of effort to pull back points ..., gossip does not pull, the following said domoticz installation: Domoticz is very easy to install, just one line of command: Sudo curl -L install.domoticz.com | sudo bash Then he waited for his automatic brainless installation. After the installation, because the installation is a release version, it does not include support for Xiaomi's gateway. Therefore, we have to upgrade it to a beta version. Specific commands as follows: Cd domoticz ./updatebeta Note that this is a two-line command, which in turn copies. At this point domoticz has been installed and has started itself, this time we open the browser, enter http:// Raspberry Pi IP address: 8080, for example, the landlord is http://192.168.10.24:8080. Can open domoticz. We will temporarily ignore it and continue to install other required components. Install Nodejs: Curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - Sudo apt-get install -y nodejs Sudo apt-get install -y build-essential Install avahi Sudo apt-get install libavahi-compat-libdnssd-dev Install other Apt-get install mosquitto Sudo apt-get install python-dev Sudo easy_install -U distribute Sudo apt-get install python-pip Pip install paho-mqtt Then we set mosquitto to random start Sudo systemctl start mosquitto Sudo systemctl enable mosquitto Well, let's add millet gateway to domoticz afterwards. Millet Gateway Addition Before adding the millet gateway, we first need to do some settings on the router, because domoticz and the following sub-devices communicate through the LAN, so you need the IP address of each device, such as the IP address of the Raspberry Pi we can in the tree The Raspberry Pi is manually set to static, but whether it is a millet gateway or a Bolink outlet, its DHCP address is not fixed, so we must set the IP address of these devices in the router as static: Different router settings are different, but most of them are within DHCP-related settings. Of course, it is not ruled out that some routers do not have related settings (such as telecommunication cats): Then we need an Android phone to get the communication key of the millet gateway: This section is because I didn’t have an Android phone when I wrote this article, so we jumped to the following article to check: 1. Get the gateway basic information: [Updated] millet gateway access Homekit complete tutorial, voice control of home equipment! - Xiaomi community official forum bbs.xiaomi.cn direct link What needs to be reminded here is that after opening the LAN communication protocol, certain points must be determined. There is a page of gateway information, please take a screenshot or take a picture of the entire site, which is very helpful for the following settings: Here we go to domoticz add millet gateway, enter the address of domoticz in the browser, I still take http://192.168.10.24:8080 for example, click, Settings> Hardware Then set a name for yourself, choose Xiaomi Gateway (If you do not have to jump forward, upgrade domoticz to beta), the heartbeat time can be set arbitrarily, the landlord set is 10 minutes, if you receive less than 10 minutes, Xiaomi Gateway Any information, it will restart the millet gateway connection. Then the remote address fills in the IP address of the millet gateway, the port is 9898, the password is the password of the millet gateway communication protocol just obtained, and finally click to increase. When done, click Settings > Devices. At this point you should see the fullscreen device in front of you (if not, click on all devices): Because the landlord has already set up, so the name has been changed to Chinese, and everyone may see the default name of the device. At this time, you just need the picture that the landlord asked you to take a snapshot and save the name of the corresponding device through the last four digits of the domoticz ID. At the beginning, all arrows are green (unused), and when clicked, they will turn blue. The point to note here is that we can only see the devices in the navigation bar menu and control them if they are marked as used. After adding the finished effect, it is also worth noting here that the millet temperature and humidity sensor will have three device numbers. They are temperature, humidity, temperature, and humidity. We have to use temperature and humidity separately, because the composite data is not supported by homekit, and it is not possible to set linkage of composite sensors in domoticz. The addition of millet gateways comes down to this, the following says Bolian's (other settings are all self-research, pure fool-style operations). Bolian SPMINI add In many previous originals, everyone used the RM Bridge to connect the Bolink device to other smart home platforms. However, using the RM Bridge requires an Android device to do the transfer. This is very inconvenient. However, there is an original mention of a method that does not require relaying of Android devices: # The original innovator # Qunhui installed broadlink-http-rest instead of RMBridge to read the site's two great god posts and learned how to use Siri to control ordinary home appliances and achieve simple home intelligence. Two Great God's post links liberate your hands - so that ordinary appliances can also be summoned by Siri to liberate your hands - so that ordinary home appliances can also be summoned by iOS 10 from iOS10, iPhone can be used to increase them ... Ryoko Oda | Like 28 Comments 22 Collection 297 View Details There is also http-rest to control the infrared learning of RM2, but there is no RM2 on the landlord's hand, so this time we just mentioned the installation of python-broadlink. In fact, using python-broadlink wget can be very convenient for the installation of python-broadlink, but the landlord is downloaded down, so it is based on the successful method to say: First go to https://github.com/mjg59/python-broadlink Click the green Clone or Download, select download zip, download the python-broadlink source code, and upload it to the Raspberry Pi. In many previous articles, the establishment of SMB services to write files to the Raspberry Pi was completely unnecessary. We only need to download a filezilla to upload the file via SSH, download the address: http://sourceforge.net/projects/filezilla/files/FileZilla_Client/3.25.2/FileZilla_3.25.2_win32.zip/download Then create a new SFTP site in the site manager: The username and password are both Raspberry Pi passwords. Then connect. Then the right side is the server directory. I just placed the extracted file directly under the /home/pi/domoticz/scripts/python directory. The following is also an example of this: After the upload is complete we close filezilla, then continue to open putty, log in Raspberry Pi, execute the following command: Cd /home/pi/domoticz/scripts/python At this point we entered the directory where we just uploaded python-broadlink. Execute the ls command: Confirm the script with setup.py. Then we execute: Python setup.py (forgot whether to add sudo in front of it, if the implementation is wrong, then we add a try) Then wait until the script is automatically executed without any errors. Then we need to write a script to control the SPMINI. The script source is (https://?f=25&t=14&p=25&hilit=broadlink#p25): Here we first create a new script called spmini: Nano spmini.py Edit the IP address and MAC address of the following script and copy it into: #!/usr/bin/python Import broadlink Import sys Device_ip="IP address of the socket" Device_port=80 Device_mac="The socket's MAC address is all uppercase" Device_type="broadlink.sp2" Action = str(sys.argv[1]) Device = broadlink.sp2(host=(device_ip,device_port), mac=bytearray.fromhex(device_mac)) Device.auth() #device.host If action == "on": Device.set_power(True) Elif action == "off": Device.set_power(False) Elif action == "status": Print "on" if device.check_power() else "off" It should be like the following figure, we check if there is no problem, then choose ctrl+X to save. Then we add executable permissions for this script: Chmod 777 spmin.py Then we try to execute the script to see if the script has any problems: Python spmini.py on Python spmini.py off At the same time observe whether the corresponding Bolian outlet has performed the corresponding switch operation: If the script executes as shown above without any errors, then we can add switches to domoticz. If you have multiple outlets, just create multiple .py files and change the IP and MAC addresses to the corresponding outlet addresses. We open domoticz, now set> hardware to add a virtual hardware, the name just take, I take the Bolian switch, type is Dummy, heartbeat time is invalid, click to increase: Then we go to the switch page and choose to manually add lights/switches The device name is what you want and then set it to use. Then we edit the switch we just added: Open the trigger and fill in: Script:///home/pi/domoticz/scripts/python/spmini.py on Close the trigger and fill in: Script:///home/pi/domoticz/scripts/python/spmini.py off Then save, the page will jump back to the main page of the switch. At this time, we click on the icon of the switch to perform a switch test. If successful, the calculation is completed. If it fails, go to Settings > Log to view the specific error message. Then submit a comment to see if the landlord can solve it. In this way, we have added Xiaomi and Bolian’s equipment to domoticz. Of course, if I still need to open the browser every time I operate the device and enter domoticz's website to operate, then isn't it different from what I used to open all kinds of apps? What I want is not to free my hands, but to move my mouth. So here we talk about how to use SIRI to manipulate domoticz devices. Installation of HOMEBRIDGE Before installing homebridge we do some preparatory work, open domoticz, select the room area settings: Then click the new room area, take a name, click ADD, and then select the newly created area, in the following device will be used in the homekit to add the equipment to the newly created room area. For example, the landlord's homekit uses an area idx of 2, which contains the following devices: Then we putty to raspberry pie, install the relevant environment Sudo apt-get install python Sudo apt-get install libavahi-compat-libdnssd-dev Sudo apt-get install g++ Then install homebridge Sudo npm install -g --unsafe-perm homebridge Then install homebridge-edomotic Sudo npm install -g homebridge-edomoticz Then we enter the homebridge directory and set the config.json file: Cd ~/.homebridge/ Nano config.json Modify roomid to ctrl+x after the room area number just created in domoticz. { "bridge": { "name": "Homebridge", "username": "CC:21:3E:E4:DE:33", "port": 51826, "pin": "031-45-154" }, "description": "Configuration file for (e)xtended Domoticz platform.", "platforms": [ { "platform": "eDomoticz", "name": "eDomoticz", "server": "127.0.0.1", "port": "8080", "ssl": 0, "roomid": , "mqtt": 1 } ], "accessories": [] } As shown below: Then enter the homebridge command line to see if it can run. If there isn't any error message, then for a long time open your iphone, home, add a home, enter the PIN CODE on the screen and see if all the devices in domoticz are on the phone. If you have, then congratulations, we will do as long as the homebridge is set to boot. Here first ctrl + C exit homebridge, then everyone please refer to the following steps: When Homekit met Xiaomi's smart home and wanted to build a smart bedroom from high school, now 5 years have passed since the launch of Homekit, it has been concerned because it has always been a fruit powder, but faithful recharge can not afford to hurt, homekit accessories It is too expensive. Millet just out of the router. In the plug-in there is a homekit plug-in, but the price is too high, and is not practical, can not add their own accessories later, can only use millet accessories. A few days ago from the Wei Feng Forum to see Yang_John| Likes 131 Comments 186 Favourites 1k View Details Ctrl+F "Set homebridge to start with system" starts looking down. Well, after the last command is completed, the Raspberry Pi will restart, wait for 2 minutes, turn on the home on the phone, and if all sensors are working properly, you can use siri happily. This article is here for the time being, because the Raspberry Pi and Linux are completely white, so the steps in the article may be a bit embarrassing. If you find any, please point out in the comments. Thank you.