This repository provides a Bash script to control an external cooling fan for the UniFi UCG-Fiber gateway.
The fan is powered by PoE from port 4, and the script automatically enables or disables PoE based on the temperature of the PON module.
- Reads PON module temperature using
ethtool. - Toggles PoE on port 4 through the local UniFi API.
- Uses configurable high and low temperature thresholds for hysteresis control.
- Designed to run via
cronon the UCG-Fiber itself.
- UniFi UCG-Fiber with firmware supporting local API.
- API key generated in UniFi Console (Settings → Control Plane → Integrations).
- External fan connected to port 4 (PoE powered).
- PON module inserted in port 7 (SFP+).
- SSH access to UCG-Fiber.
- Generate an API key in the UniFi Console, name it
PON_Fan_Control, and save it securely. - SSH into UCG-Fiber and retrieve device information:
curl -k -X GET 'https://127.0.0.1/proxy/network/api/s/default/stat/device' \ -H 'X-API-KEY: YOUR_API_KEY' \ -H 'Accept: application/json' \ -o '/persistent/ucg_devices.json' - Download
/persistent/ucg_devices.jsonand identify the correctdevice_idcorresponding to UCG-Fiber (look for the entry with public IP). - Edit
pon_fan_control.sh, configure your API key and device ID. - Upload the script to
/persistent/scriptsand make it executable:Schedule the script withchmod +x /persistent/scripts/pon_fan_control.shcron(every 5 minutes):crontab -e */5 * * * * /persistent/scripts/pon_fan_control.sh
本仓库提供一个 Bash 脚本,用于为 UniFi UCG-Fiber 网关控制外接散热风扇。 风扇通过 4 号端口的 PoE 供电,脚本会根据 PON 模块温度自动启用或关闭 PoE。
- 使用
ethtool读取 PON 模块温度。 - 通过内置的 UniFi API 切换 4 号端口的 PoE。
- 使用可配置的高温和低温阈值,实现滞后启动的控制。
- 在 UCG-Fiber 上通过
cron定时运行。
- UniFi UCG-Fiber 固件版本需支持 API。
- 在 UniFi 控制台中生成 API Key(设置 → 控制平面 → 集成)。
- 风扇连接至 4 号端口(PoE 供电)。
- PON 模块插入 7 号端口(SFP+)。
- 可通过 SSH 访问 UCG-Fiber。
- 在 UniFi 控制台生成 API Key,名称建议设为
PON_Fan_Control,并妥善保存。 - SSH 登录 UCG-Fiber,获取设备信息:
curl -k -X GET 'https://127.0.0.1/proxy/network/api/s/default/stat/device' \ -H 'X-API-KEY: YOUR_API_KEY' \ -H 'Accept: application/json' \ -o '/persistent/ucg_devices.json' - 下载
/persistent/ucg_devices.json文件,找到带公网 IP 的条目,即为 UCG-Fiber 的device_id。 - 编辑
pon_fan_control.sh,填写 API Key 和设备 ID。 - 将脚本上传至
/persistent/scripts并赋予可执行权限:使用chmod +x /persistent/scripts/pon_fan_control.shcron定时运行脚本(每 5 分钟执行一次):crontab -e */5 * * * * /persistent/scripts/pon_fan_control.sh