# HearthNodes recipe 02 - corridor room-following light handoff
alias: "Presence - corridor follows you"
id: hn_presence_room_follow_lights
description: "Three-zone corridor light handoff at 20 percent, direction aware"
mode: restart
max_exceeded: silent
trigger:
- platform: state
entity_id:
- binary_sensor.corridor_zone_a_presence
- binary_sensor.corridor_zone_b_presence
- binary_sensor.corridor_zone_c_presence
to: ["on", "off"]
variables:
zones: ['a','b','c']
here: "{{ trigger.to_state.entity_id.split('_')[2] }}"
prev: "{{ states('input_text.corridor_last_zone') }}"
going_up: "{{ zones.index(here) > zones.index(prev) if prev in zones else true }}"
next_zone: >-
{{ zones[zones.index(here) + (1 if going_up else -1)]
if (going_up and zones.index(here) < 2) or ((not going_up) and zones.index(here) > 0)
else here }}
condition:
- condition: state
entity_id: input_boolean.night_path_armed
state: "on"
- condition: template
value_template: "{{ trigger.to_state.state != trigger.from_state.state }}"
- condition: numeric_state
entity_id: sensor.corridor_illuminance
below: 80
action:
- service: input_text.set_value
target:
entity_id: input_text.corridor_last_zone
data:
value: "{{ here }}"
- service: light.turn_on
target:
entity_id:
- "light.corridor_segment_{{ here }}"
- "light.corridor_segment_{{ next_zone }}"
data:
brightness_pct: 20
color_temp_kelvin: 2200
transition: 0.8
- service: light.turn_off
target:
entity_id: "light.corridor_segment_{{ prev }}"
data:
transition: 6
# Direction unknown (two neighbours in the same second) -> light both, fall back
# to a 90 second all-corridor timer. Thread border router loss -> plain motion
# trigger at 20 percent with the same 90 second off delay.
触发器 · state
binary_sensor.corridor_zone_{a|b|c}_presence
走廊三个分区存在传感器中的任意一个发生状态变化(有人或无人)。
分步说明
- light.corridor_segment_a|b|c点亮当前所在分区,以及行进方向上的下一个分区;两者均为 20 %、2200 K。
turn_on · brightness_pct 20 · color_temp_kelvin 2200 · transition 0.8s - light.corridor_segment_prev身后那个人分区在 6 秒内淡出,让灯光看起来是在跟人移动而不是跳变。
turn_off · transition 6s - input_text.corridor_last_zone记录最后一个被占用的分区,让 1 秒后的下一次切换能判断行进方向。
set_value {{ trigger.to_state.entity_id }}
把走廊切成三个互相重叠的分区
分区之间应重叠约 0.6 米。如果严丝合缝地相接,就会出现一段死区:前一盏已经淡出、后一盏还没触发。用卷尺量出重叠宽度并写在传感器标签上;大多数跟随灯闪烁,就是因为这里靠猜。
淡出时间要明显长于淡入时间
亮起 0.8 秒、熄灭 6 秒,这个比例看起来最像「光在跟着人走」。两者都短会变成频闪;两者都长会显得迟钝,人走得比光快。先调淡出值,因为那才是人真正注意到的部分。
每层楼保留一个边界路由器
Thread 分区会自动合并,但要花几秒。如果走廊横跨两个分区,人走得快时接力就会卡顿。要么每层一个边界路由器,要么在走廊中点插一个支持 Thread 路由的市电设备,让两端留在同一个分区里。
硬件
| 型号 | 协议 | 连接 | 在本链路中的作用 |
|---|---|---|---|
| Eve Motion (Thread) | thread |
无线 | A 区和 C 区传感器;电池供电,支持 Thread 路由,可顺带增强网状网络。 |
| Aqara FP2 | wifi |
无线 | B 区(走廊中段)毫米波传感器,用于避免有人静止站在门口时灯光熄灭。 |
| Thread border router (HomePod mini or SkyConnect) | thread |
有线 | 走廊网状网络的唯一边界路由器;另备一台冷备机,因为 Thread 分区合并是接力出现 2–3 秒卡顿的常见原因。 |
失效时怎么办
如果无法判断方向(相邻两个分区在同一秒内都发生切换),自动化会同时点亮两侧分区到 20 %,并回退成 90 秒整条走廊计时。如果 Thread 边界路由器掉线,场景降级为普通的人体感应全走廊 20 %,同样是 90 秒后关闭——更暗,但绝不会让你摸黑。