Cross-platform AC control library for Broadlink RM series IR blasters. 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.
> 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=False and auto_adjust=False for the device, then call _cfg.save_config(_cfg.config).
git clone https://github.com/oywq00008-cell/BroadlinkAC-For-Agent.git
cd BroadlinkAC-For-Agent
pip install -r requirements-core.txt
from broadlinkac_core import init, send_ac, fetch_weather
# One-time setup — all config persisted
init(
baidu_key="your_baidu_key", # Baidu weather (default)
# or use QWeather:
# api_key="your_qw_key", qw_host="https://xxx.re.qweatherapi.com",
location={"lat": 22.54, "lon": 114.05, "name": "Shenzhen"},
brand="Gree"
)
# Control AC
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() # Real-time temp, humidity, feels-like
# Storm threat — returns (distance_km, storm_name)
from broadlinkac_core import typhoon_threat_distance
dist, name = typhoon_threat_distance()
if dist < 100:
send_ac("off", "cool", 26, "auto") # Storm protection: auto-shutdown
| 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 — safe to call multiple times. |
| Function | Description |
|----------|-------------|
| send_ac(power, mode, temp, fan) | Send IR command. power: "on"/"off". mode: "cool"/"heat"/"dry"/"fan"/"auto". temp: 16-30. fan: "auto"/"1"/"2"/"3" |
| decide_ac(outdoor_temp) | Run temperature rules → returns (target_temp, mode) |
| get_device() | Get connected Broadlink device |
> send_ac covers the minimum universal set across all brands. For advanced features (turbo, swing, etc.), modify ac_control.py locally.
| Function | Description |
|----------|-------------|
| learn_one(host) | Enter learning mode on Broadlink device, wait for IR signal → returns raw hex or None (timeout 45s) |
| get_raw_code(name, power, mode, temp, fan) | Look up learned hex code for a 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 all custom device names |
> Use ir_learner to teach the system codes from any AC remote — no brand limits. Codes persist automatically and send_ac routes to learned codes when the current brand is a custom one.
| Function | Description |
|----------|-------------|
| fetch_weather() | Current weather — auto-routes via Baidu/QWeather based on config |
| fetch_weather_alerts() | Local weather warnings — [{headline, severity, description, ...}] |
| Function | Description |
|----------|-------------|
| fetch_typhoons() | Active storms from NMC (NW Pacific) or NHC (Atlantic, configurable) |
| fetch_typhoon_detail(typhoon_id) | Detailed track + forecast points |
| typhoon_threat_distance() | Agent-critical: nearest storm distance (km) + name. < 100km = should shutdown. Never throws — returns (99999, "") on error |
| calc_distance(lat1, lon1, lat2, lon2) | Haversine distance |
| Function | Description |
|----------|-------------|
| write_log(category, msg) | Append daily operation 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 (ported from IRremoteESP8266 C++)
Multi-brand mappings: Xiaomi, Hualing → Midea protocol; Carrier NQV → Carrier MCA
Select in Settings or pass brand= to init(). Supports Chinese and English names.
| Provider | Free Tier | Features |
|----------|-----------|----------|
| Baidu (default) | 5,000 calls/day | Real-time + forecast + alerts |
| QWeather | 50,000 calls/month | Real-time + forecast + alerts |
import broadlinkac_core has zero side effects — no I/O, no threads
init() is idempotent — safe to call multiple times
~/.ac_controller/config.json (atomic write)
typhoon_threat_distance() never throws — returns (99999, "") on any error
threading.Lock
from broadlinkac_core import init, typhoon_threat_distance, send_ac
init()
dist, name = typhoon_threat_distance()
if dist < 100:
send_ac("off", "cool", 26, "auto")
print(f"⚠️ {name} only {dist}km away — AC shut down for safety")
from broadlinkac_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 broadlinkac_core import init, fetch_weather, fetch_weather_alerts
init()
w = fetch_weather()
alerts, provider = fetch_weather_alerts()
for a in alerts:
print(f"[{a['severity']}] {a['headline']}")
from broadlinkac_core.ir_learner import learn_one, save_learned_codes, get_raw_code
# Learn "OFF" signal
hex_off = learn_one("192.168.1.100") # Broadlink device IP
save_learned_codes("MyAC", "gree", {"关机": hex_off})
# Learn "Cool 26°C Auto Fan"
hex_cool = learn_one("192.168.1.100")
save_learned_codes("MyAC", "gree", {"开机_制冷_26°C_自动": hex_cool})
# Send learned code
send_ac("on", "cool", 26, "auto") # Routes to learned hex 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 background scheduler starts automatically after init(). Agent can read/write config directly.
from broadlinkac_core import init
init()
dev = _cfg.config["devices"]["your_mac"]
print(dev.get("active_template")) # Current template name
print(dev.get("schedule_enabled")) # True/False
import broadlinkac_core.config as _cfg
from broadlinkac_core import init
init()
dev = _cfg.config["devices"]["your_mac"]
dev["schedule_enabled"] = True
_cfg.save_config(_cfg.config)
templates = _cfg.config.setdefault("schedule_templates", {})
templates["工作日"] = {
"groups": [{
"days": [1, 2, 3, 4, 5], # Monday-Friday
"slots": [{
"on": "08:00", "on_enabled": True,
"off": "18:00", "off_enabled": True
}]
}]
}
dev["active_template"] = "工作日"
_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 BroadlinkAC-OpenWRT.
共 5 个版本