YAML

Home Assistant uses the YAML syntax for configuration. YAML might take a while to get used to but is really powerful in allowing you to express complex configurations.

For each component that you want to use in Home Assistant, you add code in your configuration.yaml file to specify its settings. The following example entry specifies that you want to use the notify component with the pushbullet platform.

Home Assistant使用 YAML 语法进行配置。 YAML可能需要一段时间才能习惯,但真正强大的是允许您表达复杂的配置。

对于要在Home Assistant中使用的每个组件,您可以在 configuration.yaml 文件中添加代码以指定其设置。 以下示例条目指定您要将 notify 组件与 pushbullet 平台一起使用。

notify:
  platform: pushbullet
  api_key: "o.1234abcd"
  name: pushbullet
  • A component provides the core logic for some functionality (like notify provides sending notifications).
  • A platform makes the connection to a specific software or hardware platform (like pushbullet works with the service from pushbullet.com).

The basics of YAML syntax are block collections and mappings containing key-value pairs. Each item in a collection starts with a - while mappings have the format key: value. If you specify duplicate keys, the last value for a key is used.

  • 组件为某些功能提供核心逻辑(如 notify 提供发送通知)。
  • 平台连接到一个特定的软件或硬件平台(如 pushbullet 与pushbullet.com的服务配合使用)。

YAML语法的基础是包含键值对的块集合和映射。 集合中的每个项目都以连接符 - 开头,而映射的格式为 key: value 。 如果指定重复键,则使用键的最后一个值。

Note that indentation is an important part of specifying relationships using YAML. Things that are indented are nested “inside” things that are one level higher. So in the above example, platform: pushbullet is a property of (nested inside) the notify component. Getting the right indentation can be tricky if you’re not using an editor with a fixed width font. Tabs are not allowed to be used for indentation. Convention is to use 2 spaces for each level of indentation. You can use YAMLLint to check if your YAML-syntax is correct before loading it into Home Assistant which will save you some time. Please pay attention on not putting in private data, as it is a 3rd-party website not maintained by Home Assistant.

Text following a # are comments and are ignored by the system.

The next example shows an input_select component that uses a block collection for the options values. The other properties (like name) are specified using mappings. Note that the second line just has threat: with no value on the same line. Here threat is the name of the input_select and the values for it are everything nested below it.

请注意,缩进是使用YAML指定关系的重要部分。缩进的东西是嵌套在上一个层次的“内部”事物。所以在上面的例子中, platform: pushbulletnotify 组件的一个属性(嵌套在里面) 。如果您不使用固定宽度字体的编辑器,获得正确的缩进可能会很棘手。 Tabs 不允许用于缩进。约定是为每个级别的缩进使用2个空格。您可以使用 YAMLLint 检查您的YAML语法是否正确,然后将其加载到Home Assistant中,这将节省一些时间。请注意不要传入隐私内容,因为它不是Home Assistant维护的,而是一个第三方网站。

#后面的文字是注释,被系统忽略。

下一个示例显示了一个 input_select 组件,它的选项值使用块集合。其他属性(如名称)使用映射指定。请注意,第二行只是 threat: :同一行没有任何值。这里的 threat 是input_select的名称,它的值是嵌套在其下的一切。

input_select:
  threat:
    name: Threat level
# A collection is used for options
    options:
     - 0
     - 1
     - 2
     - 3
    initial: 0

The following example shows nesting a collection of mappings in a mapping. In Home Assistant, this would create two sensors that each use the MQTT platform but have different values for their state_topic (one of the properties used for MQTT sensors).

以下示例显示了在映射中嵌套映射集合。 在 Home Assistant 中,这将创建两个传感器,每个传感器使用MQTT平台,但对于 state_topic (用于MQTT传感器的属性之一)具有不同的值。

sensor:
  - platform: mqtt
    state_topic: sensor/topic
  - platform: mqtt
    state_topic: sensor2/topic

转载于:https://my.oschina.net/u/3379895/blog/1068728

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值