NUC to build a smart home platform

 

Preamble:


 

Learn smart home for several years, has been a piecemeal East to the West scrape together a few days ago whim, in some eastern bought a Inter NUC mini-computer, intended as intelligent home control center, coupled with previous experience, use business time to build a set of their own smart home platform, the recording process of building bit by bit.

 Renderings:


 

 

  

 

   

   

 

 

Chart


 Core smart home is built Home Assistant (HASS), if you want to control the device with siri has not done HomeBridge the bridge, HASS has Primal Homekit support the agreement.

 All devices have access through the HASS management, if it is the use of devices or sensors raspberry pie gateway bridge, MQTT recommended way to access HASS, development costs low.

Control Panels


 Why buy NUC it, because it is a good performance of the computer, including Lightning 3 interfaces (40Gps bandwidth) and 2.5-inch hard disk box space, the latter can expand as a NAS server that supports 4K @ 60Hz display output can be expanded to HTPC. 

 Host Configuration: Inter NUC8i5BEH, CPU: i5 8259U, hard disk: Samsung 970 EVO 250G, Memory: Kingston DDR4 2400MHz 16G.

 Host energy control was good, about standby 7W, if you do not care about energy consumption, you can also get desktop do control panel.

 You can buy a motherboard with integrated CPU J series, the price is a lot cheaper, running intelligent home is enough.  

      

 

    

 

 

   This is almost more than I score a desktop computer.

 

  System installation


  First download and install open-source virtualization platform Proxmox (PVE), the official website: https://www.proxmox.com/de/   , install in a virtual machine virtualization platform for running HASS, MQTT, Node-RED, etc. software.

  In fact, I was beginning to install win10, and then install CentOS virtual machine VM ware, where you need to deal with many problems derived, such as boot, network mapping, and according to my experience, VM virtual machine a long time stability not very good.

  PVE installation is relatively simple, follow the tutorial step by step on the line, installation time is approximately 5 minutes. It should be noted that, if the software is to use UltraISO to burn U disk, be sure to use Raw format.

  If the U-NUC not recognize the host system, the need to boot by f2, setting off the security boot.

  PVE After installation, uploading the local store CentOS mirrors, and create a virtual machine, virtual machine's hardware configuration adjusted according to actual situation, and then start the virtual machine, pop-up Web console system installation.

 

  

  

  After the installation interface system:

   

 

 

  Software Deployment


  It recommended containerized docker way to deploy software, so upgrades and maintenance will be relatively simple.

  Installation docker command:

# Configure docker source
 yum-config-Manager --add-repo HTTPS: // download.docker.com/linux/centos/docker-ce.repo 

# find and install the specified version docker 
yum List docker-ce --showduplicates | the Sort - R & lt 

yum  the install -Y-CE- Docker 18.03 . . 1 .ce- . 1 .el7.centos

  (Optional) installation docker scheduling tools and Web administration interface, I use Rancher, if the download is slow, you can set the default image docker warehouse Ali cloud.

docker run --name rancher -d -v /data/docker/rancher/data:/var/lib/mysql --restart=unless-stopped -p 8080:8080 rancher/server

  Rancher in turn add hosts, applications and services:

  

 

 

 

  If the virtual machine configuration is poor, you can not install Rancher, by directly mounting HomeAssistant docker command:

 docker run --restart=always --network host -d -v /etc/localtime:/etc/localtime:ro -v /data/docker/home-assistant/config:/config -p 8123:8123 --name hass homeassistant/home-assistant    
 So far, HASS platform to build complete, the face of smart home management, are mounted on the configuration file is modified on the line.

   Add Device


   After HASS platform to build, we need to add a device to the platform, different devices access there will be little difference, but basically HASS by modifying the configuration file, you can access the.

   HASS equipment access documents: https://home-assistant.cc/component/

  Here is my millet access configuration devices:

  1, Mi Gateway:

# Millet Gateway 
xiaomi_aqara : 
  Gateways: 
    - mac: 78:11: **: **: 81: E3 # gateway MAC address, in Mi APP where multiple clicks on to query 
      key: 62A96 ****** A4500   # gateway LAN communication protocol password, the Mi APP where you can check on multiple clicks

  2, Philips lamp:

# Philips Rui Chi Mi series of lamps installed 5.0.19 #token Andrews simulator with a computer, and then look in the Explorer 
Light : 
  - Platform: xiaomi_miio 
    name: Philips lamps 
    Host: 192.168.0.48 
    token: 740a96fbe ****** * c8817e0ccc44d54e

  3, millet patch panel:

# Millet patch panel     
Switch :     
  - Platform: xiaomi_miio 
    name: Study socket 
    Host: 192.168.0.47 
    token: 802d2e16 ****** 739163f32275317c1c

  It should be noted that the Mi wifi device, you can skip the direct control of the gateway, but you need to know token device, the easiest solution is to install a PC Andrews simulator, and then install Mi APP (5.0.19 or lower) ,

  After connecting the device, you can find token directly in the /data/data/com.xiaomi.smarthome/databases/miio2.db file.

  After adding a device, HASS platform interface:

  

  

 

 

  Other equipment access


 

  HASS platform can now add a lot of smart devices, but if it is to develop its own devices and sensors, such as raspberry pie, you need api, manage and control their own equipment to achieve the HASS.

  The easiest way is to interact with the HASS through MQTT agreement.

  I supplemented the latter example.

 

  Siri control


 

  Add siri control is very simple, Homekit protocol used Apple's smart home, you need Apple's official authentication device to control, and later after Homekit protocol reverse engineering, beginning with Homebridge analog HomeKit certified parts, so that we can through Apple devices control the system.

  HASS now tacitly support HomeKit, so here we can skip Homebridge.

  HASS configuration is very simple, just the node name on the line, after the restart configuration, HASS will notify HomeKit Code:

 Homekit: 

  Then, open the iphone mobile phones, add accessories, you can enter the code HomeKit siri control your smart devices up.

  

 

  

 

 

  Extranet Access


 

  Now, siri only for devices in the same local area network control, if need extranet access, you can purchase Apple's AppleTV or HomePod, here we adopt another way:

  Principle is to find a public server (Ali cloud can be used lightweight server), the request to the network reverse proxy HASS, here need to use technology in the network map, I use the frpc, so you can pass outside home network to control the device.

  Server installation of agent software (frps):

docker run --restart=always --network host -d -v /data/docker/frp/frps.ini:/conf/frps.ini --name frps cloverzrg/frps-docker

  Virtual machine installed network mapping software (frpc):

docker run --restart=always --network host -d -v /etc/frp/frpc.ini:/etc/frp/frpc.ini --name frpc snowdreamtech/frpc

  Profiles:

[ Common ] 
The server_addr = server the IP 
SERVER_PORT = 6000 
token = request token 

[ Home-Assistant ] 
type = TCP 
local_ip = network the IP 
local_port = 8123 # local port 
REMOTE_PORT = 8123 Remote Port #

   

  In this way, we access the public network IP: 8123 port, will be delegated to the 8123 port of the virtual machine within the network.

  Home smart devices if exposed to the public network, you need to pay attention to security issues, in order to be safe, we use the HTTPS certificate request is encrypted.

  Now we can apply for free in Ali cloud a certificate, and then configure on nginx, by way of https domain name, the reverse proxy server to port 8123, then the agent to the virtual machine within the network. (Note that the server port 8123 needs to be done to security restrictions)

  nginx configuration:

    server
    {          
        listen 80;
        server_name home.xxx.com;
        return 301 https://$server_name$request_uri; #http请求直接跳转到https 
    }
    server {
        listen       443;
        server_name  home.xxx.com;
        ssl             on;        
        ssl_certificate   cert/home.xxx.com.pem;
        ssl_certificate_key  cert/home.xxx.com.key; 
        
        location / {
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-Port $server_port;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://localhost:8123;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_read_timeout 900s;
        }
        access_log /root/wwwroot/log/home.xxx.com.log;
    }

  

  final effect:

  

 

  If you have the time and energy, you can also develop your own applets, HASS docking platform within the network.

 

  Smart Sound


  I was home with a small degree sound, dueros need to Baidu open platform to add skills, according to a small degree to define the parameters of smart devices, modifying device parameters at home, similar to the Lynx elves and love the students.

  Adding skills:

  

  

  Configuration Oauth2 authorization:

   

 

  HASS configuration:

# Small degree of skill open platform      
dueros : 
  expire_hours: 87600   . # This time the license expires parameter is not mandatory    

  

   Then duerOS platform can be simulated test, the test is passed, with a small degree, he said: "Discovery", you can make a small degree of control smart devices.

 

  Automation, scenes, voice broadcast


  To be added.

  


  

 At this point, we are chipping away of smart home platform to get on the line, let us happy group of programmers together boast share the thrill of smart technology to bring it!

 

 

Guess you like

Origin www.cnblogs.com/yixueli/p/12548972.html