The Problem: A Slider That Refused to Stay Put
Apple's Scale vs Tuya's Scale
Rewriting the Characteristic
Js
service
.getCharacteristic(Characteristic.RotationSpeed)
.setProps({
minValue: 0,
maxValue: 100,
minStep: 1,
});
Js
function percentToTuyaWind(percent) {
if (percent <= 0) return 0;
if (percent <= 33) return 1;
if (percent <= 66) return 2;
return 3;
}
Debouncing the Signal Spam
Js
let debounceTimer = null;
function setSpeedDebounced(value) {
if (debounceTimer) clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => {
const tuyaValue = percentToTuyaWind(value);
device.set({ dps: WIND_DP, set: tuyaValue });
}, 800);
}
Persistence: Making a node_modules Edit Survive an npm install
- Edit the file inside node_modules until the behaviour is correct.
- Run npx patch-package homebridge-tuya-platform to generate a diff, stored in a patches/ directory at the repository root.
- Add a postinstall hook to package.json so that every install run replays the patch automatically.
- Commit npm-shrinkwrap.json so the dependency tree is locked in lockstep with the patch.
Json
{
"scripts": {
"postinstall": "patch-package"
}
}
Disaster Recovery: rsync, ZFS, and the 100 Megabit Bottleneck
Hardware Constraints That Shape the Strategy
The Exclusion List
Bash
rsync -aAXH --delete \
--exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} \
/ <NAS_USER>@<NAS_HOST>:<BACKUP_DATASET_PATH>/
ED25519 Keys and Why Privileges Matter
The Enterprise Perspective
Technology Stack
- Homebridge with the Tuya Platform plugin
- Node.js
- Ubuntu Server (Plex host)
- Raspberry Pi OS (Bullseye)
- TrueNAS with ZFS datasets and scheduled snapshots
- patch-package and npm-shrinkwrap for dependency-level patches
- rsync over SSH with ED25519 keys
- cron for scheduled execution
- tmux for persistent sessions on the Pi
- Raspberry Pi 3B (shared USB/Ethernet, 100 Mbps cap)
- NVMe-based Plex server with two externally mounted media drives
- Ubiquiti UniFi network: UCG Fiber gateway, US-48-500W switch, U6 Pro access points