Introduction
In our daily use, some smart devices themselves support access to HomeKit, which means that users can access and control the device through the "home" of the Apple mobile phone. However, this operation has obvious limitations. Android phones cannot be used, and they cannot be linked with devices that do not support HomeKit. For example, use the iPhone to remotely turn on and off the lights in the house;
Take Home Assistant as an example. It is a Python-based smart home open source system that can support access to many brands of smart devices. However, it also has advantages and disadvantages to a certain extent: the first advantage is centralized management; the other The disadvantage is that it can only be accessed within the local area network and cannot be remotely controlled through the external network;
Many people here do not know that it is the first comprehensive open source protocol in China that adopts the software characteristics of various smart home manufacturers. It can run offline in the local area network and obtain more powerful functions by binding to the Zhiting cloud. rookie. When running in a local area network environment, users can discover and manage the Zhiting home cloud through the Zhiting APP, and install plug-ins to manage and control the device.
Secondly, through the Zhiting cloud account, connect the Zhiting home cloud device to the cloud, and then support the control of the device on the external network through cloud transfer.
At the same time, it provides the function of directly connecting the device to the cloud virtual home, which is convenient for users who do not have Zhiting home cloud equipment; Zhiting cloud also provides an interface for migrating virtual home data to a physical home.
For families connected to the cloud, Zhiting Cloud provides cloud-to-cloud access, and users can authorize Xiaodu, Tmall Genie, Google Nest and other smart speakers to directly control the device.
Second, install third-party plug-ins
Zhiting Home Cloud runs under the Linux host, and uses Docker to deploy and isolate its services. Some of the core service containers need to be pre-configured and run automatically when the system is started; while the plug-in services are managed by SA calling the docker API.
After the plugin is started, it will run a gRPC service and an optional HTTP service. SA monitors the running status of the plugin through the docker API, and obtains the plugin information through the gRPC interface. For example plugins implemented in the plugin implementation tutorial; refer to this document: golang | development documentation
development example
1. Image compilation and deployment
Temporarily only supports the installation of plug-ins in mirror mode. After debugging is normal, it is compiled into an image and provided to SA
- Dockerfile example reference
FROM golang:1.16-alpine as builder
RUN apk add build-base
COPY . /app
WORKDIR /app
RUN go env -w GOPROXY="goproxy.cn,direct"
RUN go build -ldflags="-w -s" -o demo-plugin
FROM alpine
WORKDIR /app
COPY --from=builder /app/demo-plugin /app/demo-plugin
# static file
COPY ./html ./html
ENTRYPOINT ["/app/demo-plugin"]
- Compile the image
docker build -f your_plugin_Dockerfile -t your_plugin_name
- Run the plugin
docker run -net=host your_plugin_name
//注意:-net=host 参数只有linux环境才有用。
In contrast, HomeBridge is a dynamic plug-in whose main function is to allow homekit to recognize the device connected to Home Assistant, which is equivalent to a bridge.
The installation of Homebridge requires npm. It is a bit troublesome to install npm under the Raspberry Pi, so I will not describe it in detail here. After installing npm, just enter the following statements in order to install homebridge and its related dependencies.
sudo npm install -g --unsafe-perm homebridge hap-nodejs node-gyp
cd /usr/local/lib/node_modules/homebridge/
sudo npm install --unsafe-perm bignum
cd /usr/local/lib/node_modules/hap-nodejs/node_modules/mdns
sudo node-gyp BUILDTYPE=Release rebuild
Next, you can install homebridge-mqtt.
npm install -g homebridge-mqtt
On the Raspberry Pi, the configuration of Homebridge is mainly to edit the "config.json" file under "/home/pi/.homebridge". Below is an example homebridge-mqtt configuration.
{
"bridge": {
"name": "Homebridge",
"username": "12:34:56:78:90:AB",
"port": 38960,
"pin": "123-45-678"
},
"platforms": [{
"platform": "mqtt",
"name": "mqtt",
"url": "mqtt://127.0.0.1",
"port": 61613,
"topic_type": "multiple",
"topic_prefix": "homebridge",
"username": "admin",
"password": "password",
"cert": "/path/to/certificate.pem",
"key": "path/to/key.pem",
"ca": "/path/to/ca_certificate.pem"
}]
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。