MQTT 场景
mqtt
场景平台让你控制你的 MQTT 使能场景。
配置
要在你的安装中启用 MQTT 场景,请将以下内容添加到你的 configuration.yaml
configuration.yaml 文件是 Home Assistant 的主要配置文件。它列出了要加载的集成及其特定配置。在某些情况下,需要直接在 configuration.yaml 文件中手动编辑配置。大多数集成可以在 UI 中配置。 [Learn more] 文件中:
# 示例 configuration.yaml 条目
mqtt:
- scene:
command_topic: zigbee2mqtt/living_room_group/set
Configuration Variables
一系列 MQTT 主题的列表,订阅以接收可用性(在线/离线)更新。不能与 availability_topic
一起使用。
当配置了 availability
时,控制将实体设置为 available
所需的条件。有效的条目为 all
,any
和 latest
。如果设置为 all
,必须在所有配置的可用性主题上接收到 payload_available
,然后实体才会被标记为在线。如果设置为 any
,在至少一个配置的可用性主题上接收到 payload_available
,实体才会被标记为在线。如果设置为 latest
,则任何配置的可用性主题上接收到的最后一个 payload_available
或 payload_not_available
控制可用性。
Defines a template to extract device’s availability from the availability_topic
. To determine the devices’s availability result of this template will be compared to payload_available
and payload_not_available
.
设备与外部世界的连接列表,以 [connection_type, connection_identifier]
元组的形式列出。例如网络接口的 MAC 地址:"connections": [["mac", "02:5b:26:a8:dc:12"]]
。
实体的 类别。
场景的图标。
Defines a template to extract the JSON dictionary from messages received on the json_attributes_topic
. Usage example can be found in MQTT sensor documentation.
订阅以接收 JSON 字典有效负载的 MQTT 主题,然后设置为传感器属性。使用示例可以在 MQTT 传感器 文档中找到。
必须是 scene
。仅在 MQTT 自动发现设备消息 中允许和必要。
确保你的主题完全匹配。some-topic/
和 some-topic
是不同的主题。
示例
在这一部分中,您将找到一些关于如何使用 MQTT 场景的真实例子。
完整配置
下面的示例显示了场景的完整配置。
# 示例 configuration.yaml 条目
mqtt:
- scene:
unique_id: living_room_party_scene
name: "聚会场景"
command_topic: "home/living_room/party_scene/set"
availability:
- topic: "home/living_room/party_scene/available"
payload_on: "ON"
qos: 0
retain: true
device:
name: "客厅"
identifiers: "livingroom_lights"
使用 JSON 有效负载
下面的示例显示了使用 JSON 有效负载的配置。
# 示例 configuration.yaml 条目
mqtt:
- scene:
name: 客厅蓝色场景
unique_id: living_room_blue_scene
command_topic: "home/living_room/set"
payload_on: '{"activate_scene": "蓝色场景"}'