Install
openclaw skills install @oywq00008-cell/acnexus🎮 AI Agent 智能空调控制核心库 — 零 GUI 依赖,import 即用。支持 17 大品牌空调(格力/美的/海尔/大金等),直连 Broadlink RM 红外遥控器,同时接入所有支持 MIoT 协议的米家红外遥控器。百度+和风双天气源,中央气象台+NHC 双风暴源,多日期组定时模板,Markdown 日志,故障诊断。适配树莓派/NAS/OpenWRT/桌面全平台。(原名 BroadlinkAC,现已更名为 AC-Nexus,正式成为空调中枢)
openclaw skills install @oywq00008-cell/acnexusCross-platform AC control library for Broadlink RM series IR blasters and Xiaomi MIoT-compatible IR remote controllers. Zero GUI dependency — designed for AI agents to clone, install, and control air conditioners programmatically. Now includes IR learning — teach the system codes from any original remote, no brand limits.
📢 Rebrand Notice: Formerly BroadlinkAC, now AC-Nexus (空调中枢). All Xiaomi IR remote controllers compatible with MIoT protocol are supported — just scan with Mi Home app to add, then control via local network. No brand limitations.
This skill writes durable state to the user's machine.
init()creates~/.ac_controller/config.json(API keys, device config, schedule templates) and starts a background scheduler daemon thread. The scheduler survives agent task completion — scheduled on/off times, auto-adjust, and storm auto-shutdown will continue to run autonomously. Always confirm with the user before:
- Modifying or creating schedule templates
- Enabling auto-adjust or typhoon auto-shutdown
- Changing device configuration (brand, temperature rules, location)
To fully disable automation: set
schedule_enabled=Falseandauto_adjust=Falsefor the device, then call_cfg.save_config(_cfg.config).
git clone https://github.com/oywq00008-cell/AC-Nexus.git
cd AC-Nexus
pip install -r requirements-core.txt
from acnexus_core import init, send_ac, fetch_weather
# One-time setup — all config persisted
init(
baidu_key="your_baidu_key",
location={"lat": 22.54, "lon": 114.05, "name": "Shenzhen"},
brand="Gree"
)
# Control AC — auto-routes between Broadlink IR and Xiaomi MIoT
send_ac("on", "cool", 26, "auto") # Turn on, cool 26°C, auto fan
send_ac("off", "cool", 26, "auto") # Turn off
# Weather — dual source (Baidu default, falls back to QWeather)
weather = fetch_weather()
# Storm threat
from acnexus_core import typhoon_threat_distance
dist, name = typhoon_threat_distance()
if dist < 100:
send_ac("off", "cool", 26, "auto") # Storm protection: auto-shutdown
AC-Nexus supports multiple device providers simultaneously. Devices are organized by brand type in the config:
"devices": {
"broadlink": {
"e870723f41ee": {"host": "192.168.8.214", "model": "RM4 mini", ...}
},
"xiaomi_cloud": {
"2003509235": {"host": "192.168.8.119", "token": "97af...", "model": "qjiang.acpartner.ac02", ...}
}
}
Each provider's devices are fully isolated — separate schedules, temperature rules, and auto-adjust settings. send_ac() automatically detects the device type and routes commands:
set_properties)| Function | Description |
|---|---|
init(baidu_key=None, api_key=None, qw_host=None, location=None, brand=None) | Initialize config + start background scheduler. Writes to ~/.ac_controller/config.json. Idempotent. |
⚠️ Device naming is critical for Agent usability. Each device's
namefield in config should be a human-readable room/location name (e.g. "二楼卧室", "客厅"). The Agent matches user intent ("关掉二楼房间的空调") by searching device names. Open the desktop app → click the ✏️ rename button next to the device dropdown to set meaningful names. |acnexus_core.config.save_config(cfg)| Save config to disk (atomic write) | |acnexus_core.config.find_device(mac)| Find device by MAC across all providers →(provider, device_dict)|
| Function | Description |
|---|---|
send_ac(power, mode, temp, fan, source="手动", mac=None) | Send command. Auto-routes: broadlink → IR hex, xiaomi_cloud → MIoT set_properties. power: "on"/"off". mode: "cool"/"heat"/"dry"/"fan"/"auto". temp: 16-30. fan: "auto"/"1"/"2"/"3". Pass mac= to target a specific device. |
decide_ac(outdoor_temp, mac=None) | Run temperature rules → returns (target_temp, mode) |
get_device() | Get current Broadlink device (for IR learning) |
get_current_device() | Get current device config dict from devices[provider][mac] |
send_accovers the minimum universal set across all brands. MIoT devices use standard siid=3 (AC service) / siid=4 (fan service) — no per-model mapping needed.
Step 1 — Get session via QR login:
from acnexus_core.cloud_auth import login_qr
# In a terminal: prints ASCII QR code automatically
# In Jupyter/GUI: pass a callback to render the QR image
session = login_qr()
# Returns dict with auth tokens for listing devices
Step 2 — Add device to config:
import acnexus_core.config as _cfg
from acnexus_core.xiaomi_cloud import list_devices
# List devices on this mi account
devices = list_devices(session)
# Pick an IR remote controller and add it
for d in devices:
if d["model"] in ("lumi.acpartner.mcn02", "qjiang.acpartner.ac02"):
_cfg.add_or_update_device(d["did"], {
"did": d["did"],
"host": d["ip"],
"mac": d["mac"],
"model": d["model"],
"name": d["name"],
"token": d["token"], # Critical for local network control!
"brand": "格力", # Default brand, user changes in Mi Home app
})
break
_cfg.save_config(_cfg.config)
Step 3 — Control via local network (no cloud after this):
send_ac("on", "cool", 25, "auto") # Automatically uses MIoT local network
Unlike Broadlink (one-way IR), MIoT devices support reading current state:
from miio import Device
d = Device("192.168.8.119", "97af6abc63a7f95da50dc8710005a42d")
r = d.send('get_properties', [
{'siid': 3, 'piid': 1}, # Power (True/False)
{'siid': 3, 'piid': 2}, # Mode (0=cool 1=heat 2=auto 3=fan 4=dry)
{'siid': 3, 'piid': 4}, # Temperature (16-30)
{'siid': 4, 'piid': 2}, # Fan speed (0=auto 1=low 2=med 3=high)
])
print(f"Power={r[0]} Mode={r[1]} Temp={r[2]} Fan={r[3]}")
All MIoT-compatible IR remote controllers share the same service IDs:
⚠️ Note: Use
siid=4, piid=2for fan, notsiid=3, piid=3— the latter is read-only and does not trigger IR transmission.
| Function | Description |
|---|---|
learn_one(host) | Enter learning mode, wait for IR signal → raw hex or None (45s timeout) |
get_raw_code(name, power, mode, temp, fan) | Look up learned code for custom device |
load_custom_codes() | Load all custom codes from ~/.ac_controller/custom_codes.json |
save_custom_codes(data) | Persist learned codes |
list_custom() | List custom device names |
IR learning only works with Broadlink devices. Xiaomi MIoT devices use the pre-built IR code library on the device itself.
| Function | Description |
|---|---|
fetch_weather() | Current weather — auto-routes via Baidu/QWeather |
fetch_weather_alerts() | Local weather warnings |
| Function | Description |
|---|---|
fetch_typhoons() | Active storms from NMC or NHC |
fetch_typhoon_detail(typhoon_id) | Detailed track + forecast |
typhoon_threat_distance() | Agent-critical: nearest storm distance (km) + name. <100km = should shutdown. Never throws — returns (99999, "") on error |
typhoon.judge_and_shutdown(log_func) | One-call: fetch typhoon data → if <100km, shut down ALL devices across ALL brands + pause scheduler. Returns alerts list |
| Function | Description |
|---|---|
write_log(category, msg) | Append daily log (thread-safe) |
read_log(date_str) | Read log by date |
get_log_dates() | List dates with logs |
hvac_ir: Gree, Midea, Hisense, Daikin, Mitsubishi, Hitachi, Fujitsu, Ballu, Carrier MCA, Hyundai, Fuego
Custom protocols: Haier, AUX, Panasonic
Xiaomi MIoT: All MIoT-compatible IR remote controllers — add via QR scan, control via local network. Supports multiple devices per account.
Multi-brand mappings: Xiaomi, Hualing → Midea protocol; Carrier NQV → Carrier MCA
| Provider | Free Tier | Features |
|---|---|---|
| Baidu (default) | 5,000 calls/day | Real-time + forecast + alerts |
| QWeather | 50,000 calls/month | Real-time + forecast + alerts |
import acnexus_core has zero side effects — no I/O, no threadsinit() is idempotent — safe to call multiple times~/.ac_controller/config.json (atomic write)typhoon_threat_distance() never throws — returns (99999, "") on any errorthreading.Lockdevices[provider][mac] — fully isolated per brandsend_ac auto-routes: Broadlink → IR hex / Xiaomi → MIoT local networkfrom acnexus_core import init, send_ac
import acnexus_core.config as _cfg
init()
# List all devices across all providers
for provider, devs in _cfg.config["devices"].items():
for did, dev in devs.items():
print(f"[{provider}] {dev['name']} = {did[:8]}")
# Control a specific device by MAC/DID
send_ac("on", "cool", 25, "auto", mac="e870723f41ee")
from acnexus_core.cloud_auth import login_qr
from acnexus_core.xiaomi_cloud import list_devices
import acnexus_core.config as _cfg
# Step 1: Login (terminal prints ASCII QR, user scans with Mi Home)
session = login_qr()
# Step 2: List devices and add IR remote controllers
devices = list_devices(session)
ir_models = {"lumi.acpartner.mcn02", "qjiang.acpartner.ac02", "chuangmi.remote.v6"}
for d in devices:
if d["model"] in ir_models:
_cfg.add_or_update_device(d["did"], {
"did": d["did"], "host": d["ip"], "mac": d["mac"],
"model": d["model"], "name": d["name"], "token": d["token"],
"brand": "格力",
})
_cfg.save_config(_cfg.config)
print(f"Added {len(devices)} device(s)")
import acnexus_core.config as _cfg
from miio import Device
# Get device info from config
dev = _cfg.config["devices"]["xiaomi_cloud"]["2003509235"]
d = Device(dev["host"], dev["token"])
r = d.send('get_properties', [
{'siid': 3, 'piid': 1}, {'siid': 3, 'piid': 2},
{'siid': 3, 'piid': 4}, {'siid': 4, 'piid': 2},
])
POWER = {True: "开", False: "关"}
MODE = {0: "制冷", 1: "制热", 2: "自动", 3: "送风", 4: "除湿"}
FAN = {0: "自动", 1: "低", 2: "中", 3: "高"}
print(f"{dev['name']}: {POWER[r[0]['value']]} {MODE[r[1]['value']]} {r[2]['value']}°C {FAN[r[3]['value']]}")
from acnexus_core import init, typhoon
init()
# ✅ One-liner: shutdown all devices on all brands if storm < 100km,
# also pauses scheduler to prevent auto-adjust/timed-on from
# re-opening the AC. Returns list of alert dicts.
alerts = typhoon.judge_and_shutdown(print)
if not alerts:
print("No storm threat — all clear")
from acnexus_core import init, fetch_weather, decide_ac, send_ac
init()
w = fetch_weather()
if w:
target, mode = decide_ac(float(w["temp"]))
send_ac("on", mode, target, "auto")
from acnexus_core.ir_learner import learn_one, save_learned_codes
hex_code = learn_one("192.168.8.214") # Broadlink device IP
save_learned_codes("MyAC", "gree", {"关机": hex_code})
send_ac("off", "cool", 26, "auto") # Routes to learned code automatically
⚠️ All schedule changes are persistent — they survive Python process exit and will be executed by the background scheduler daemon. Always confirm with the user before enabling or modifying schedules.
The scheduler runs all devices across all providers. Typhoon auto-shutdown (<100km) pauses the scheduler for all devices.
import acnexus_core.config as _cfg
from acnexus_core import init
init()
# Navigate the nested structure: devices[provider][mac]
provider = _cfg.config.get("current_brand_type", "broadlink")
mac = _cfg.config.get("current_device_mac", "")
dev = _cfg.config["devices"][provider][mac]
print(dev.get("active_template"))
print(dev.get("schedule_enabled"))
templates = _cfg.config.setdefault("schedule_templates", {})
templates["工作日"] = {
"groups": [{
"days": [1, 2, 3, 4, 5],
"slots": [{
"on": "08:00", "on_enabled": True,
"off": "18:00", "off_enabled": True
}]
}, {
"days": [6, 7],
"slots": [{
"on": "12:00", "on_enabled": True,
"off": "23:00", "off_enabled": True
}]
}]
}
dev["active_template"] = "工作日"
dev["schedule_enabled"] = True
_cfg.save_config(_cfg.config)
dev["auto_adjust"] = True
_cfg.save_config(_cfg.config)
Pre-built installers (Windows/macOS/Linux), auto-built by GitHub Actions. Download from Releases.
7×24 unattended AC control on OpenWRT routers. See AC-Nexus-OpenWRT.