Skip to content

Instantly share code, notes, and snippets.

@lesewudi
Created May 3, 2025 04:22
Show Gist options
  • Save lesewudi/2abffc69f2008d2727152bff489f5340 to your computer and use it in GitHub Desktop.
Save lesewudi/2abffc69f2008d2727152bff489f5340 to your computer and use it in GitHub Desktop.
blueprint:
name: 灵活房间灯光与窗帘自动化(最终修正版)
description: |
根据人员存在、光照强度及时间自动控制灯光和窗帘
灯光支持自适应/手动模式,窗帘支持环境光+时间混合控制
domain: automation
input:
# ... [保持所有input参数定义不变] ...
trigger:
- platform: state
entity_id: !input presence_sensor
- platform: numeric_state # 光照低于窗帘开启阈值时触发
entity_id: !input illuminance_sensor
below: !input curtain_lux_low
- platform: numeric_state # 光照高于窗帘关闭阈值时触发
entity_id: !input illuminance_sensor
above: !input curtain_lux_high
- platform: time
at: !input curtain_close_time
- platform: time
at: !input curtain_open_time
action:
- variables:
lux: "{{ states(illuminance_sensor) | float(0) }}"
presence: "{{ states(presence_sensor) }}"
# ... [保持原有变量计算逻辑] ...
# 灯光控制逻辑(保持原有结构)
- if: "{{ light_control_enabled }}"
then:
- choose:
# ... [强制关闭时段判断] ...
- conditions: "{{ presence == presence_state_on }}"
sequence:
# ... [灯光开启操作] ...
# 窗帘控制优化逻辑
- choose:
- conditions: "{{ curtain_control_mode in ['environment','both'] }}"
sequence:
- choose:
- conditions: "{{ lux > curtain_lux_high }}"
sequence:
- service: cover.close_cover
target: !input curtain
- conditions: "{{ lux < curtain_lux_low }}"
sequence:
- service: cover.open_cover
target: !input curtain
- conditions: "{{ curtain_control_mode in ['time','both'] and trigger.platform == 'time' }}"
sequence:
- choose:
- conditions: "{{ trigger.now.time() >= strptime(curtain_close_time, '%H:%M:%S').time() }}"
sequence:
- service: cover.close_cover
target: !input curtain
- conditions: "{{ trigger.now.time() <= strptime(curtain_open_time, '%H:%M:%S').time() }}"
sequence:
- service: cover.open_cover
target: !input curtain
mode: queued
max: 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment