场景
你可以创建场景来捕捉你希望特定实体处于的状态。例如,场景可以指定灯A应该打开,灯B应该是亮红色。
# Example configuration.yaml entry
scene:
- name: Romantic
entities:
light.tv_back_light: "on"
light.ceiling:
state: "on"
xy_color: [0.33, 0.66]
brightness: 200
- name: Movies
entities:
light.tv_back_light:
state: "on"
brightness: 125
light.ceiling: off
media_player.sony_bravia_tv:
state: "on"
source: HDMI 1
如何配置你的场景
在你的YAML文件中定义场景时,请确保使用下面列出的所有必需参数。
如你所见,有两种方式定义每个entity_id
的状态:
-
直接用实体定义
state
。请注意,必须定义state
。 -
使用属性定义复杂状态。你可以在
developer-tools -> state
下查看特定实体的所有可用属性。
场景可以使用scene.turn_on
动作激活(没有'scene.turn_off'动作)。
# Example automation
automation:
triggers:
- trigger: state
entity_id: device_tracker.sweetheart
from: "not_home"
to: "home"
actions:
- action: scene.turn_on
target:
entity_id: scene.romantic
应用未定义的场景
使用scene.apply
动作,你可以应用未通过配置预先定义的场景。相反,你可以将状态作为数据的一部分传递。数据格式与配置中的entities
字段相同。
# Example automation
automation:
triggers:
- trigger: state
entity_id: device_tracker.sweetheart
from: "not_home"
to: "home"
actions:
- action: scene.apply
data:
entities:
light.tv_back_light:
state: "on"
brightness: 100
light.ceiling: off
media_player.sony_bravia_tv:
state: "on"
source: "HDMI 1"
使用场景过渡
scene.apply
和scene.turn_on
动作都支持设置过渡,这使你能够平滑地过渡到场景。
这是一个设置浪漫场景的自动化示例,其中灯光将在2.5秒内过渡到场景。
# Example automation
automation:
triggers:
- trigger: state
entity_id: device_tracker.sweetheart
from: "not_home"
to: "home"
actions:
- action: scene.turn_on
target:
entity_id: scene.romantic
data:
transition: 2.5
目前过渡仅由灯光支持,而灯光本身也必须支持此功能。然而,场景本身不必仅由灯光组成就可以设置过渡。
重新加载场景
每当你对场景配置进行更改时,你可以调用scene.reload
动作来重新加载场景。