自动化要求
触发
- 传感器livingroom_motion的state变成”on“的状态的时候
条件
- 实体input_boolean.trigger_first_morning的state处于”on“的时候
执行
- 首先关闭实体input_boolean.trigger_first_morning
- 如果全部满足以下条件:
- 设备light.livingroom_ec处于打开状态,并且brightness(亮度)在128之下
- 设备light.kitchen_bar处于打开状态,并且brightness(亮度)在128之下
- 设备light.kitchen_ceiling处于打开状态,并且brightness(亮度)在128之下
则继续执行脚本morning_first_motion
homeassistant
automation:
- alias: First Morning Motion
trigger:
platform: state
entity_id: binary_sensor.livingroom_motion
to: 'on'
# only complete the automation if we're still waiting for the first motion
condition:
condition: state
entity_id: input_boolean.trigger_first_morning
state: 'on'
action:
# turn off the "waiting" boolean regardless of whether lights will turn on
# so that this happens only once
- service: homeassistant.turn_off
entity_id: input_boolean.trigger_first_morning
# But only turn on lights if the living room and kitchen lights are off or dimmed
# If a condition tests false, the automation will end
- condition: and
conditions:
- condition: numeric_state
entity_id: light.livingroom_ec
# if light is off, force a 0, otherwise use the brightness value
value_template: '{% if is_state('light.livingroom_ec', 'on') %}{{ state_attr('light.livingroom_ec', 'brightness') }}{% else %}0{% endif %}'
# brightness below 50% (255 = 100%)
below: 128
- condition: numeric_state
entity_id: light.kitchen_bar
value_template: '{% if is_state('light.kitchen_bar', 'on') %}{{ state_attr('light.kitchen_bar', 'brightness') }}{% else %}0{% endif %}'
below: 128
- condition: numeric_state
entity_id: light.kitchen_ceiling
value_template: '{% if is_state('light.kitchen_ceiling', 'on') %}{{ state_attr('light.kitchen_ceiling', 'brightness') }}{% else %}0{% endif %}'
below: 128
# Trigger a scene
# You could add as many services or scenes as you'd like
- service: script.turn_on
entity_id: script.morning_first_motion
node-red
接着重复其他两个灯的设置,因为都是一样的。
First Morning Motion.json (6.8 KB)