极物科技 | Control4 对接 - 温控器驱动(IRAcc/CAN/中弘)
前言
在智能控制领域,"协议壁垒"与"系统稳定性"始终是绕不开的难题。极物科技(Zeewo)以 "重构空间交互体验" 为使命,通过自研的 极物 OS,实现了 KNX、DALI、CAN、RS485 等多种总线协议在单一主机上的深度融合。
我们认为,一个真正优秀的智能系统,不仅要实现灯光、遮阳、温控、音乐、安防等全生态设备的无界融合 ,更要确保本地运行、断网可用 ,并具备WEB 远程调试 和 OTA 固件升级的能力。基于此底层架构,我们推出了诸如带双路 DALI 的 KNX 主机、HomeKit 网桥等核心硬件,并将极物 OS 成功接入了 Apple HomeKit、小度、纯血鸿蒙及 HomeAssistant 等主流生态系统。
一句话概述:本文详细解析极物网关温控器驱动的 Control4 DriverWorks 实现,涵盖 IRAcc/CAN/中弘多协议适配、温度设定、模式切换、Proxy 代理机制及状态同步。
本文聚焦于 极物温控器驱动的完整实现,从 IRAcc/CAN/中弘多协议适配、温度设定、模式切换、Proxy 代理机制到状态同步,逐一深入剖析,并提供完整代码供 C4 集成商参考。
开源代码:本系列文档对应的 Control4 对接驱动代码已完全开源,访问 Gitee 仓库获取完整源码:https://gitee.com/fujianxinxi/aolebahe.git
1. 驱动概述
1.1 驱动定位
温控器驱动是 Control4 系统中直接面向终端用户的温控设备驱动,负责:
- 接收 C4 Composer 或场景的温控指令
- 支持 IRAcc/CAN/中弘多协议适配
- 实现温度设定、模式切换、风速控制
- 接收网关下发的温控器状态更新
1.2 驱动文件结构
Aolebach-Thermostat/
├── driver.xml # 驱动元数据与配置定义
├── driver.lua # 驱动主逻辑(入口、命令路由、Proxy 分发)
├── thermostat.lua # 温控协议封装(IRAcc/CAN/中弘)
├── proxy.lua # Proxy 代理逻辑
├── action.lua # 动作处理
├── const.lua # 常量定义(Proxy ID、设备结构体)
├── documentation.rtf # 驱动文档说明
└── Aolebach-Thermostat.c4zproj # C4 Composer 工程文件
1.3 通讯参数
| 参数 | 规格 |
|---|---|
| 通讯方式 | IR / CAN / RS485 |
| 网关 Proxy ID | 1(THERMOSTAT_GATE_WAY_PROXY_ID) |
| 温控器 Proxy ID | 5001(THERMOSTAT_PROXY_ID) |
| 设备地址 | IR/CAN/RS485 地址 |
| 协议类型 | IRAcc / CAN / 中弘 |
| 温度范围 | 16°C ~ 30°C |
| 模式 | 制冷 / 制热 / 自动 / 送风 / 除湿 |
2. 驱动配置(driver.xml)
xml
<devicedata>
<manufacturer>Aolebach</manufacturer>
<name>奥乐巴赫 温控器</name>
<model>Thermostat Module</model>
<version>2025011309</version>
<control>lua_gen</control>
<driver>DriverWorks</driver>
<proxies>
<proxy>Aolebach-Thermostat-Module</proxy>
</proxies>
<capabilities>
<thermostat>True</thermostat>
<set_temperature>True</set_temperature>
<set_mode>True</set_mode>
<set_fan>True</set_fan>
</capabilities>
<config>
<properties>
<property>
<name>设备地址</name>
<type>RANGED_INTEGER</type>
<readonly>false</readonly>
<default>0</default>
</property>
<property>
<name>协议类型</name>
<type>LIST</type>
<items>
<item>IRAcc</item>
<item>CAN</item>
<item>中弘</item>
</items>
<default>IRAcc</default>
</property>
<property>
<name>Debug Mode</name>
<type>LIST</type>
<items>
<item>Off</item>
<item>Print</item>
<item>Log</item>
<item>Print and Log</item>
</items>
<default>Off</default>
</property>
</properties>
</config>
</devicedata>
3. 常量定义(const.lua)
lua
-- 代理
THERMOSTAT_GATE_WAY_PROXY_ID = 1
THERMOSTAT_PROXY_ID = 5001
-- 温控模式
MODE_COOL = "cool"
MODE_HEAT = "heat"
MODE_AUTO = "auto"
MODE_FAN = "fan"
MODE_DRY = "dry"
MODE_OFF = "off"
-- 风速
FAN_AUTO = "auto"
FAN_LOW = "low"
FAN_MID = "mid"
FAN_HIGH = "high"
-- 协议类型
PROTOCOL_IRACC = "IRAcc"
PROTOCOL_CAN = "CAN"
PROTOCOL_ZHONGHONG = "中弘"
4. 驱动核心实现
4.1 设备结构体
lua
require "utils"
require "ao_timer"
require "thermostat"
require "proxy"
require "const"
require "action"
local g_thermostat_proxy_bound_status = false
-- 温控器设备结构体
local g_thermostat_device = {
address = 0,
protocol = "IRAcc",
temperature = 25,
mode = "off",
fan = "auto",
current_temp = 25
}
4.2 属性变更回调
lua
function OnPropertyChanged(strProperty)
local value = Properties[strProperty]
if (value == nil) then
value = ''
end
if (strProperty == '设备地址') then
g_thermostat_device.address = tonumber(value)
elseif (strProperty == '协议类型') then
g_thermostat_device.protocol = value
end
Print_table("g_thermostat_device", g_thermostat_device)
end
4.3 延迟初始化
lua
function OnDriverLateInit(dit)
for property, _ in pairs(Properties) do
OnPropertyChanged(property)
end
gTestTimer = AddTimer(gTestTimer, 3)
LUMI_CMD.GET_CONNECTED_STATE(THERMOSTAT_GATE_WAY_PROXY_ID, nil, nil)
end
4.4 Proxy 绑定变更
lua
function OnBindingChanged(idBinding, class, bIsBound)
dbg("OnBindingChanged(), idBinding = " .. tostring(idBinding) .. ", class = " .. class .. ", bIsBound = " ..
tostring(bIsBound))
if (idBinding == THERMOSTAT_GATE_WAY_PROXY_ID) then
g_thermostat_proxy_bound_status = bIsBound
end
end
4.5 命令路由
lua
function ExecuteCommand(strCommand, tParams)
Print_table("strCommand", strCommand)
Print_table("tParams", tParams)
if (strCommand == "LUA_ACTION") then
lua_normal_action(tParams, g_thermostat_device)
else
lua_special_action(strCommand, tParams, g_thermostat_device)
end
end
4.6 Proxy 分发
lua
function ReceivedFromProxy(idBinding, strCommand, tParams)
if (idBinding == THERMOSTAT_GATE_WAY_PROXY_ID) then
-- 网关下发的状态更新
proxy_info_update_by_gateway(g_thermostat_device, strCommand, tParams)
elseif (idBinding == THERMOSTAT_PROXY_ID) then
-- 温控器控制
proxy_thermostat_control(g_thermostat_device, strCommand, tParams)
end
end
5. 温控协议封装(thermostat.lua)
5.1 IRAcc 协议
lua
function iracc_thermostat_control(device, temperature, mode, fan)
local frame_data = {
driver_data = {
address = device.address,
protocol = device.protocol,
temperature = temperature,
mode = mode,
fan = fan
},
frame_type = "request",
frame_driver = "iracc",
frame_result = "ok"
}
C4:SendToProxy(THERMOSTAT_GATE_WAY_PROXY_ID, JSON:encode(frame_data), {})
end
5.2 CAN 协议
lua
function can_thermostat_control(device, temperature, mode, fan)
local frame_data = {
driver_data = {
address = device.address,
protocol = device.protocol,
temperature = temperature,
mode = mode,
fan = fan
},
frame_type = "request",
frame_driver = "can",
frame_result = "ok"
}
C4:SendToProxy(THERMOSTAT_GATE_WAY_PROXY_ID, JSON:encode(frame_data), {})
end
5.3 中弘协议
lua
function zhonghong_thermostat_control(device, temperature, mode, fan)
local frame_data = {
driver_data = {
address = device.address,
protocol = device.protocol,
temperature = temperature,
mode = mode,
fan = fan
},
frame_type = "request",
frame_driver = "zhonghong",
frame_result = "ok"
}
C4:SendToProxy(THERMOSTAT_GATE_WAY_PROXY_ID, JSON:encode(frame_data), {})
end
5.4 统一控制入口
lua
function thermostat_control(device, temperature, mode, fan)
if device.protocol == PROTOCOL_IRACC then
iracc_thermostat_control(device, temperature, mode, fan)
elseif device.protocol == PROTOCOL_CAN then
can_thermostat_control(device, temperature, mode, fan)
elseif device.protocol == PROTOCOL_ZHONGHONG then
zhonghong_thermostat_control(device, temperature, mode, fan)
end
end
6. 温控器控制
6.1 温度设定
lua
function proxy_thermostat_control(device, strCommand, tParams)
if (strCommand == "Set Temperature") then
local temperature = tParams.TEMPERATURE
thermostat_control(device, temperature, device.mode, device.fan)
device.temperature = temperature
elseif (strCommand == "Set Mode") then
local mode = tParams.MODE
thermostat_control(device, device.temperature, mode, device.fan)
device.mode = mode
elseif (strCommand == "Set Fan") then
local fan = tParams.FAN
thermostat_control(device, device.temperature, device.mode, fan)
device.fan = fan
elseif (strCommand == "Off") then
thermostat_control(device, device.temperature, MODE_OFF, device.fan)
device.mode = MODE_OFF
end
end
6.2 状态更新(网关下行)
lua
function proxy_info_update_by_gateway(device, strCommand, tParams)
if (strCommand == nil) then
print("proxy_info_update error")
return
end
local frame = JSON:decode(strCommand)
-- 过滤无关信号
if frame.driver_data.address ~= device.address then
return
end
device.temperature = frame.driver_data.temperature
device.mode = frame.driver_data.mode
device.fan = frame.driver_data.fan
device.current_temp = frame.driver_data.current_temp
-- 同步到 C4 Composer
C4:SendToProxy(THERMOSTAT_PROXY_ID, "Set Temperature", {TEMPERATURE = device.temperature})
C4:SendToProxy(THERMOSTAT_PROXY_ID, "Set Mode", {MODE = device.mode})
C4:SendToProxy(THERMOSTAT_PROXY_ID, "Set Fan", {FAN = device.fan})
end
7. 配置与测试指南
7.1 驱动版本要求
- C4 版本:3.3.0 及以上版本
- 驱动文件 :
Aolebach-Thermostat.c4z - 驱动版本号 :driver.xml 中
<version>字段对应软件编译时间点
7.2 添加驱动
在 C4 Composer 中添加温控器驱动,选择对应的协议类型(IRAcc/CAN/中弘)。
7.3 配置说明
- 设备地址:需与网关中配置的设备地址一致
- 协议类型:选择正确的协议类型(IRAcc/CAN/中弘)
7.4 测试方法
在 C4 Composer 中双击温控器驱动,弹出控制界面,可以测试:
- 温度设定(16°C ~ 30°C)
- 模式切换(制冷/制热/自动/送风/除湿)
- 风速控制(自动/低/中/高)
- 开关机
8. 注意事项
⚠️ 协议差异
IRAcc/CAN/中弘协议有差异,驱动内部自动适配
配置时需选择正确的协议类型
⚠️ 温度范围温控器温度范围为 16°C ~ 30°C
超出范围的值将被自动限制
⚠️ 模式切换支持制冷/制热/自动/送风/除湿五种模式
模式切换后需等待设备响应
9. 相关文档
- 《极物科技 | Control4 对接 - 系统架构与驱动开发概述》
- 《极物科技 | Control4 对接 - CAN 网关驱动》
- 《极物科技 | Control4 对接 - 窗帘驱动》
关于极物科技(ZEEWO)
极物科技(Zeewo)致力于为用户提供智能控制系统及硬件产品。我们以总线系统为技术底座,以**"稳定、可靠、快速响应"**为产品底线,是国内少有的拥有 KNX、DALI 全套软硬件自主研发能力的厂商之一。
我们的核心能力:
- 系统架构:自研极物 OS,支持多协议无界融合(KNX/DALI/CAN/RS485/IP)。
- 核心硬件:带双路 DALI 的 KNX 主机、超薄全金属定制面板、各类智选传感器及网关。
- 生态互联:深度融入 Apple HomeKit、Matter、小度、HomeAssistant 及纯血鸿蒙生态。
- 调试交付:独家支持 ETS 导出 XML 直接导入进行 APP 免编程调试,支持远程 WEB 运维。
我们的市场覆盖:
服务网点已覆盖全国核心城市(含长三角、珠三角、成渝等),并以高品质的方案深耕家居生活、酒店民宿、企业办公、疗愈康养、餐馆会所 等多个细分领域。


(如果您在开发或落地中遇到技术问题,欢迎通过官网或后台私信与我交流探讨)