IoT|硬體 |樹莓派|實作|Homebridge 結合 MQTT Homebridge-server、Homebridge-config-ui-x、Homebridge-mqtt
安裝 Homebridge-server
sudo npm -g --unsafe-perm install homebridge-server
安裝後設定 Config,設定好後重新 Homebridge
nano /home/pi/.homebridge/config.json
{
"bridge": {
"name": "控制訊號整合閘道器",
"username": "E8:4E:06:35:47:C6",
"port": 51826,
"pin": "123-45-678"
},
"platforms": [
{
"platform": "Server",
"port" : 8080,
"name" : "Homebridge Server",
"log" : "/var/log/daemon.log",
"restart" : "sudo systemctl restart homebridge.service"
}
]
}
安裝 Homebridge-config-ui-x、Homebridge-mqtt(安裝前,先確認是否安裝 mosquitto server)
sudo npm install -g homebridge-mqtt
sudo npm install -g --unsafe-perm homebridge-config-ui-x
因已安裝 Homebridge-server 套件,固可採兩種方式設定 Config
方式一:檔案編輯
nano /home/pi/.homebridge/config.json
{
"bridge": {
"name": "控制訊號整合閘道器",
"username": "E8:4E:06:35:47:C6",
"port": 51826,
"pin": "123-45-678"
},
"platforms": [
{
"platform": "Server",
"port" : 8080,
"name" : "Homebridge Server",
"log" : "/var/log/daemon.log",
"restart" : "sudo systemctl restart homebridge.service"
},
{
"platform": "mqtt",
"name": "mqtt",
"url": "mqtt://127.0.0.1",
"port": 1883,
"topic_type": "multiple",
"topic_prefix": "homebridge"
},
{
"platform": "config",
"name": "Config",
"port": 8081,
"sudo": true,
"log" : "/var/log/daemon.log"
}
]
}
方式二:網頁編輯
重啟系統
Homebridge-server:192.168.100.235:8080
Homebridge-config-ui-x:192.168.100.235:8081 (帳號密碼可修改,預設為:admin/admin)
Homebridge-mqtt 相關接口(詳細說明可參考 https://github.com/cflurin/homebridge-mqtt)
支持 Service
service
|
說明
|
service
|
說明
|
AirPurifier
|
空氣淨化器
|
SecuritySystem
|
安全系統,安全解防
|
AirQualitySensor
|
空氣質量傳感器
|
SmokeSensor
|
煙霧傳感器
|
ContactSensor
|
接觸傳感器,可以判斷房間是否關閉
|
Switch
|
開關
|
Fan
|
風扇
|
TemperatureSensor
|
溫度
|
HumiditySensor
|
濕度
|
Thermostat
|
恆溫器
|
LightSensor
|
光照傳感器
|
Window
|
窗戶
|
Lightbulb
|
燈泡
|
WindowCovering
|
窗簾
|
OccupancySensor
|
人體傳感器
|
範例
配件名稱
|
Service
|
說明
|
指令
| 新增配件 | 刪除配件 |
冷氣
|
Fan
|
風扇
|
開啟冷氣
關閉冷氣
|
mosquitto_pub -h 127.0.0.1 -t homebridge/to/add -m '{"name": "冷氣", "service_name": "冷氣", "service": "Fan"}'
|
mosquitto_pub -h 127.0.0.1 -t homebridge/to/remove -m '{"name": "冷氣"}'
|
溫度 |
TemperatureSensor
|
溫度
| 溫度 |
mosquitto_pub -h 127.0.0.1 -t homebridge/to/add -m '{"name":"溫度","service":"TemperatureSensor"}'
|
mosquitto_pub -h 127.0.0.1 -t homebridge/to/remove -m '{"name": "溫度"}'
|
Siri 語音控制,訂閱來自 homebridge 狀態消息
mosquitto_sub -h 127.0.0.1 -t homebridge/from/set
[參考]
留言
張貼留言