有趣生活

当前位置:首页>科技>智能家居控制方法及智能家居系统老工程师教你如何搭建智能家居控制系统

智能家居控制方法及智能家居系统老工程师教你如何搭建智能家居控制系统

发布时间:2026-07-21阅读(0)

导读现在国内一提起智能家居、智能设备、智能物联网,真是火的不得了,感觉很高大上,相关的人才也是缺的厉害。你作为一名创客或者准创客,有没有觉得这些东东其实并不是遥....

现在国内一提起智能家居、智能设备、智能物联网,真是火的不得了,感觉很高大上,相关的人才也是缺的厉害。你作为一名创客或者准创客,有没有觉得这些东东其实并不是遥不可及的,下面教你如何搭建一个智能家居系统,我们完全可以自己DIY一些小系统出来。

智能家居布线系统

智能家居布线系统是一个小型的综合布线系统,从功用说它是一个能支持语音/数据、多媒体、家庭自动化、保安等多种应用的传输通道,是智能家居系统的基础。它可以作为一个完善的智能小区综合布线系统的一部份,也可以完全独立成为一套综合布线系统。

一、安装 Arduino ESP8266

Arduino ESP8266 GitHub 地址: https://github.com/esp8266/Arduino

安装方法:

启动 Arduino IDE,并进入 Preferences 窗口

在 Additional Board Manager URLs 中输入: http://Arduino.esp8266.com/stable/package_esp8266com_index.json

从 Tools > Board 菜单中打开 Boards Manager,并输入安装 esp8266 平台

二、测试仿真

下载安装包:https://github.com/kakopappa/arduino-esp8266-alexa-multiple-wemo-switch

Setup 步骤:

下载代码

在编辑器中打开 wemos.ino

修改 WiFi 设置

定义开关及其回调,在 officeLightsOn、officeLightsOff、kitchenLightsOn、kitchenLightsOff 中

烧录

相似项目:Arduino Esp8266 Alexa Wemo switch emulator

ESP8266 仿真 Philips Hue

ESP8266 Hue Emulator 项目地址:ESP8266HueEmulator

这个 Demo 需要这么几个库NeoPixelBus、aJson、Time、NtpClient,同时还需要修改一些相关的配置。

因此直接使用这个脚本安装,比较简单:

注意:如果是 Mac OS,需要将下面脚本中的 $HOME/Arduino/libraries/ 改为 $HOME/Documents/Arduino/libraries/

mkdir -p $HOME/Arduino/libraries/

cd $HOME/Arduino/libraries/

git clone --branch 2.1.4 https://github.com/Makuna/NeoPixelBus.git

git clone https://github.com/interactive-matter/aJson.git

git clone https://github.com/PaulStoffregen/Time.git

git clone https://github.com/gmag11/NtpClient.git

sed -i -e s|#define PRINT_BUFFER_LEN 256|#define PRINT_BUFFER_LEN 4096|g aJson/aJSON.h

cd -

git clone https://github.com/probonopd/ESP8266HueEmulator.git

sed -i -e s|#include "/secrets.h"|//#include "/secrets.h"|g ESP8266HueEmulator/ESP8266HueEmulator/ESP8266HueEmulator.ino

sed -i -e s|//const char|const char|g ESP8266HueEmulator/ESP8266HueEmulator/ESP8266HueEmulator.ino

再将代码烧录到 ESP8266 上,就可以在 Homekit 看到相应的配置。

智能插座

寻找设备

npm install -g miio

miio --discover

npm install --save miio

集成网关篇

Raspberry Pi Home Assistant

Images: https://home-assistant.io/docs/hassbian/installation/

Images Downloader: https://etcher.io/

发现文档好像有点问题,便手动地尝试安装:

pip3 install --upgrade homeassistant

运行

sudo -u homeassistant -H /srv/homeassistant/bin/hass

并不没工作,于是执行官方的安装脚本:

curl -O https://raw.githubusercontent.com/home-assistant/fabric-home-assistant/master/hass_rpi_installer.sh && sudo chown pi:pi hass_rpi_installer.sh && bash hass_rpi_installer.sh

又在我的 MBP 上安装尝试

pip3 install homeassistant

hass --open-ui

然后发现安装完就可以了。

Home Assistant Broadlink PM PRO

在 configuration.yaml 文件中添加下面的配置:

# Example configuration.yaml entry

switch:

- platform: broadlink

host: IP_ADDRESS

mac: MAC_ADDRESS

switches:

reciever:

command_on: switch_packet on

command_off: switch_packet off

获取 Broadlink 配置

从 https://github.com/NightRang3r/Broadlink-e-control-db-dump 获取数据导出脚本

打开 易控(英语:E-Control) 应用,点击菜单 -> 共享 -> 云分享 就会生成相应的配置文件

浏览手机上的 /broadlink/newremote/SharedData/ 目录,复制出 jsonSubIr、jsonButton、jsonIrCode 三个文件

安装好 python 环境, 并安装 pip install simplejson

执行第一步代码中的脚本,python getBroadlinkSharedData.py

安装python-broadlink,地址 https://github.com/mjg59/python-broadlink.git

不知道是不是我的空调问题,获取到的配置是空的。

Homebridge

相关的插件:

Yeelight:homebridge-yeelight

小米设备:homebridge-aqara

Broadlink RM 红外:homebridge-broadlink-rm

Broadlink SP 开关: homebridge-broadlink-sp

Home Assistant: homebridge-homeassistant

安装 Homebridge

编辑软件源:

sudo vim /etc/apt/sources.list

修改为阿里云,速度会更快一些:

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

安装 Node.js ARM 版 :

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -

sudo apt-get install -y nodejs

安装 avahi:

sudo apt-get install libavahi-compat-libdnssd-dev

安装 homebridge:

npm install -g homebridge

安装相应的插件:

sudo npm install -g homebridge-yeelight

sudo npm install -g homebridge-homeassistant

sudo npm install -g homebridge-broadlink-sp

sudo npm install -g homebridge-broadlink-rm

sudo npm install -g homebridge-platform-wemo

sudo npm install -g homebridge-miio

对应的配置在 home-assistant 目录下的 configuration.yaml 文件。

开机启动

在 /etc/default 目录下创建 homebridge 文件,内容如下:

#Defaults / Configuration options for homebridge

#The following settings tells homebridge where to find the config.json file and where to persist the data (i.e. pairing and others)

HOMEBRIDGE_OPTS=-U /var/lib/homebridge

# If you uncomment the following line, homebridge will log more

# You can display this via systemds journalctl: journalctl -f -u homebridge

# DEBUG=*

在 /etc/systemd/system 目录下创建 homebridge.service 文件,内容如下:

[Unit]

Description=Node.js HomeKit Server

After=syslog.target network-online.target

[Service]

Type=simple

User=homebridge

EnvironmentFile=/etc/default/homebridge

# Adapt this to your specific setup (could be /usr/bin/homebridge)

# See comments below for more information

ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS

Restart=on-failure

RestartSec=10

KillMode=process

[Install]

WantedBy=multi-user.target

启动服务:

systemctl daemon-reload

systemctl enable homebridge

systemctl start homebridge

HomeBridge 集成 Home Assistant

安装插件:

npm install -g homebridge-homeassistant

添加配置:

"platforms": [

{

"platform": "HomeAssistant",

"name": "HomeAssistant",

"host": "http://127.0.0.1:8123",

"password": "yourapipassword",

"supported_types": ["binary_sensor", "climate", "cover", "device_tracker", "fan", "group", "input_boolean", "light", "lock", "media_player", "scene", "sensor", "switch"],

"logging": true

}

]

Amazon Echo 设置

我用的是 Amazon Echo Dot 2 就是那个 Mini 版的

安装 Yeelight Skill

安装 Mijia

两者需要登录小米的账号,才能授权获得控制。

结合 HomeAssistant 和 Amazon Echo

文档:https://home-assistant.io/components/alexa/

如果只是为了打开、关闭设备,可以直接使用 emulated_hue 组件,它可以提供一个虚拟的 Philips Hue 桥。

只开关设备

使用 Home Assistant 的 Emulated Hue 组件就可以了,添加如下的配置:

emulated_hue:

host_ip: 192.168.199.242

其中的 192.168.199.242 即是 Home Assistant 的服务器地址

更详细的配置,如:https://github.com/Teagan42/HomeAssistantConfig

定制命令

为了使用更多的功能,则需要使用将 Home Assistant 暴露到公网上——使用诸如花生壳等。(PS:由于当前家里使用的是光纤,需要光纤猫,实施上比较困难;因此,外部访问需要使用一级跌幅,暂时没有进行这方面的尝试)。

随后在 Amazon developer console

创建相应的 Alexa Skill,并添加 Endpoing:https://YOUR_HOST/api/alexa?api_password=YOUR_API_PASSWORD

必须使用 HTTPS

定制 Home Assistant

Home Assistant RESTful API 地址:Home Assistant API

Raspberry Pi Cornata

官方文档:Use Cortana Function on IoT Core

下载 Windows 10 IoT Core Dashboard

下载地址:https://developer.microsoft.com/en-us/windows/iot/docs/iotdashboard

安装最新镜像

打开 Windows 10 IoT Core Dashboard,为 RPi 烧录镜像,如下图所示:

官方建议要更新到最新。使用 Web 界面打开设备的 Windows Update,http://:8080/#Windows Update,如http://192.168.199.223:8080/#Windows Update。

然后到 Devices 中看是否出现相应的 Microphone 设置。

开机启动 Cortana

在首页的 Device Settigns 最下面有一个 Start Cortana on Boot 的选项。

使用 Windows IoT Remote Server 访问:在 http://192.168.199.223:8080/#Remote 在勾上 Enable Windows IoT Remote Server

设置 speechlanguage 成中文:

打开 Processes -> Run command,执行:

IoTSettings -set region CN

IoTSettings -set speechlanguage zh-Hans-CN

提高管理水平

智能控制系统是以自动控制为主、人工控制为辅的系统。在一般的情况下,不需要有人的参与,照明系统通过网络遥控自动实现开关和调光功能。既大大减少了电量的浪费,也排除了由于人为因素而出现的不定时开关,减少为控制灯光而到处跑的情况出现。

Copyright © 2024 有趣生活 All Rights Reserve吉ICP备19000289号-5 TXT地图HTML地图XML地图