软件工程师的大脑
普通安装只会设“开门亮灯”。我们按软件工程的方式写自动化:事件防抖避免误触发、多设备并行执行、失败自动重试、全程日志可追溯——不是“能用就行”,而是长期稳定不出错。
// 事件驱动 · 防抖 · 并行执行 · 失败重试 · 可观测 automation('arrive_home') .on('lock.unlocked', { debounce: 2_000 }) .when(ctx => ctx.sun.below(-6) || ctx.lux < 50) .run(async ({ userId, ctx }) => { const who = await residents.resolve(userId) if (ctx.mode === 'sleep') return const res = await Promise.allSettled([ light('entry').on({ kelvin: 3000 }), light('living').on({ pct: who.pref.lux }), climate('ac').set(ctx.outdoor > 30 ? 26 : 24), ]) await retry(res.filter(failed), { times: 3 }) trace.emit('arrive_home', { who, latency: ctx.ms }) })


