2021.7:全新实体、触发器 ID 与脚本调试

七月快乐,也意味着 Home Assistant 核心 2021.7 来了!

这是一次很有意思的发布,带来了一堆小惊喜,让创建自动化、脚本以及编写模板都变得更轻松。这些东西总是会让我特别开心。主要原因嘛,毕竟我就是拿 Home Assistant 来做自动化的 😁

此外,我们还要向一种全新的实体类型说声“你好!”👋 这真的非常令人兴奋,我已经迫不及待想看看未来大家会怎么使用它了。

最后,我还想特别感谢一下 @klaasnicolaas!在过去几个月里,他一直在 Nabu Casa 实习。除了负责社区精选内容之外,他还做了很多很棒的东西,并会在接下来的 Home Assistant 发布中陆续上线。

现在他的实习已经结束了,而且还拿到了很不错的成绩。不过看起来,他还是留下了一份小礼物才离开:他贡献了 Forecast.Solar 集成,为你的太阳能板带来了发电量预测功能。真的很酷!

好了,就这些!祝你享受这次发布!

../Frenck

新实体:Select

在这次发布中,我们欢迎 select 实体加入 Home Assistant 大家庭。select 实体和下拉辅助器(也就是 input_select)算是近亲。

不同之处在于,input_select 是由你自己配置和管理的,而 select 实体则由集成提供。

这意味着,集成现在可以提供带有可选项的实体。它既可以在 Lovelace 界面中使用,也可以在自动化里通过服务调用,还能通过 Google Assistant 使用。

Screenshot of a select 实体, providing a choice from a list of options Screenshot of a select 实体, providing a choice from a list of options.

从这次发布开始,一些集成已经率先实现了首批 select 实体。MQTT 和 KNX 已经可以使用它;WLED 用它来提供用户预设的选择与启用控制;而在 Rituals Perfume Genie 中,你现在可以用它来调整香薰机的房间大小。

触发器条件与触发器 ID

如果你正在用 YAML 创建比较复杂的自动化,那你大概对这个场景不陌生。想象一个很大的自动化,里面有一堆触发器。那么,你要怎么知道到底是哪个触发器真正触发了这个自动化呢?

你现在可以给触发器分配一个 id,当自动化被触发时,这个 id 会一并传入自动化,从而让你可以基于它来做判断。

automation:
  - alias: "Trigger IDs!"
    trigger:
      - platform: state
        id: "normal"
        entity_id: binary_sensor.gate
        state: "on"
      - platform: state
        id: "forgotten"
        entity_id: binary_sensor.gate
        state: "on"
        for:
          minutes: 10
    ...

上面的例子会在两种情况下触发同一个自动化:大门打开时,以及大门持续打开 10 分钟时(大概是忘了关)。每个触发器都有自己的 ID。

现在,新的触发器条件来了!你可以根据“是哪一个触发器触发了自动化”来添加条件。

automation:
  - alias: "Trigger IDs!"
    ...
    action:
      ...
      - condition: trigger
        id: "forgotten"
      - service: notify.frenck_iphone
        data:
          message: "Someone left the gate open..."

你可以在所有其他条件可用的地方使用这个触发器条件,包括像从一组动作中进行选择这样的场景。

如果你更喜欢通过 UI 创建和管理自动化,也完全没问题!这些新功能也已经加入自动化编辑器了!

Screenshot of using a 触发器 条件 in the 自动化 editor Screenshot of using a 触发器 条件 in the 自动化 editor.

脚本调试

Home Assistant 核心 2021.4 中,我们加入了自动化调试能力。而在这次发布中,我们把同样强大的工具也带给了脚本!

所以下次当你再疑惑“为什么这个脚本没执行?”、“它为什么会这样运行?”、“这脚本到底在搞什么?”时,这个功能就能帮上忙了。

Screenshot of using the new 脚本 debugger on my office announce 脚本 Screenshot of using the new 脚本 debugger on my office announce 脚本.

上面的截图展示了一次脚本的历史运行记录。它会用一张交互式图形展示脚本中的每一步,并高亮显示实际走过的路径。图中的每个节点都可以点击,从而查看脚本序列中该步骤发生了什么。

在触发器和条件中引用其他实体

这是对脚本和自动化的一项小改动,但可能会非常有帮助。现在,你可以在数值状态触发器和条件的 above/below 值中引用其他实体。传感器和 number 实体都可以使用。

例如,你现在可以在室外温度高于室内温度时触发一个自动化。

automation:
  - alias: "Notify to close the window"
    trigger:
      - platform: numeric_state
        entity_id: sensor.outside_temperature
        above: sensor.inside_temperature
    action:
      - service: notify.frenck_iphone
        data:
          message: "Close all windows, it is warm outside!"

数值状态条件同样支持这一能力。

此外,时间条件现在也支持类似能力:可以在 beforeafter 选项中使用其他提供时间值的传感器。时间触发器在之前的发布中就已经支持这一点了。

在模板中处理日期

如果你曾经试过在模板里处理日期,那你大概知道这有多麻烦。说实话,这个问题也永远不会彻底消失,时间、日期和时区本来就是一群复杂的小怪兽。

不过我们意识到,在模板中使用日期和时间最麻烦的地方,其实是把传感器状态或文本转换成 datetime。这次发布新增了一个小巧的模板方法来帮助你完成这件事:as_datetime

它既可以作为过滤器使用,也可以作为方法使用。下面是一个计算“距离我的驾照到期还有多少天”的示例:

 days

Docker 容器的系列版本标签

如果你使用的是 Home Assistant 容器安装方式,我们通常建议你使用特定的版本标签;但这也意味着,每次我们发布新的补丁版本时,你都得手动更新标签。

感谢 @kmdm,从这次发布开始,除了现有的所有标签之外,我们还提供了一个系列版本标签,它会始终指向该发布系列中的最新补丁版本。

docker pull ghcr.io/home-assistant/home-assistant:2021.7

2021.7 这个标签会始终指向七月发布系列中的最新补丁版本,即使它实际对应的是 2021.7.2

其他值得注意的变化

这次发布还有很多内容;下面是其中一些同样值得关注的变化:

  • Z-Wave JS got quite a few updates this 发布:
    • A new zwave_js.multicast_set_value is available, allowing to issue a set value command via multicast. Thanks, @raman325!
    • Each node now has a status 传感器 available and can be pinged using the new zwave_js.ping 服务. Added by @raman325.
    • The Z-Wave JS 配置 面板 now has a "Heal Network" button, thanks @cgarwood!
    • Z-Wave JS Server connection can now be re-configured from the Z-Wave JS 配置 面板, added by @MartinHjelmare.
    • Z-Wave JS 日志 can now be downloaded, thanks @raman325!
  • The Google Assistant 集成 now has support for 风扇 speed percentages and preset modes. Thanks, @jbouwh!
  • @jbouwh didn't stop there and added 风扇 preset mode support to Alexa too!
  • The Philips TV 集成 now supports Ambilights, added by @elupus.
  • Yamaha MusicCast 集成 now supports grouping 服务, thanks @micha91!
  • @raman325 added a whole bunch of 传感器 to the ClimaCell 集成!
  • WLED now supports local push. Updates are now instantly both ways. Also, the master 灯光 can be kept and added support for controlling user presets.
  • Setting up Xiaomi 设备 has gotten way easier! There is no need to do difficult things to get the tokens. Instead, Home Assistant can now extract the tokens from a Xiaomi Cloud account. Thanks, @starkillerOG!
  • More Xiaomi updates, @jbouwh added support for 风扇 percentage-based speeds and preset modes.
  • @RenierM26 added a lot of new 服务 to the Ezviz 集成, thanks!
  • Tibber had quite a few improvements and now provides a power factor 传感器, added by @Danielhiversen!
  • Google Translate TTS now supports the Bulgarian language, thanks @hristo-atanasov!
  • If you have a SmartTube, you can now reset your reminders, thanks @mdz!
  • KNX had quite a lot of updates and added support for XY-color 灯光, thanks @farmio.
  • @OttoWinter added support for presets, custom presets and custom 风扇 modes for 温控 controls in ESPHome. Awesome!
  • Nuki now has a 服务 to enable/disable continuous mode, thanks @anaisbetts!
  • @cgomesu added quantiles to Statistics 集成, thanks!
  • The Home Assistant login page now better support password manager, thanks, @rianadon!

新集成

欢迎以下新集成加入本次发布:

新平台

以下集成新增了对新平台的支持:

现已支持通过 UI 设置的集成

以下集成现在可以直接通过 Home Assistant UI 进行设置:

发布 2021.7.1 - July 8

发布 2021.7.2 - July 12

发布 2021.7.3 - July 16

发布 2021.7.4 - July 21

如果你需要帮助……

……欢迎随时使用我们非常活跃的论坛,或者加入我们的聊天频道

如果你遇到了这次发布引入的问题,请到我们的 issue tracker 提交反馈,并确保填写问题模板中的所有字段。

破坏性变更

下面按主题或集成列出了本次发布中的破坏性变更。点击对应项目即可阅读该条变更的更多说明。

Home Assistant will now block HTTP requests when a misconfigured reverse proxy, or misconfigured Home Assistant instance when using a reverse proxy, has been detected.

If you are using a reverse proxy, please make sure you have configured use_x_forwarded_for and trusted_proxies in your HTTP 集成 配置.

更多信息, see the HTTP integrations 文档.

Additionally, access to Home Assistant from the same IP address as a trusted proxy will be rejected if the request is marked as forwarded.

(@frenck - #51839) (http docs)

Our Docker images are now based on Alpine 3.13 and run Python 3.9.

This is mainly interesting if you running custom Docker 容器 based on our 容器.

If you are using Home Assistant 容器, Home Assistant OS or the Home Assistant 受监管模式 安装 method, you will automatically get this 更新 on 升级 and no additional interaction is needed.

Please note, that Alpine 3.13 on ARM 设备 running a 32-bits operating system (armhf/armv7), requires your Docker 版本 to be at least 19.03.9 (although, we recommend updating to an even higher 版本). Additionally, you need to have libseccomp 2.42 or newer.

(@pvizeli - #51628)

The AirQuality platform has been marked as deprecated. The air_quality 实体 is removed and replaced with 传感器 实体. You will need to 更新 their 自动化 and 仪表盘 if you have been using the air_quality 实体 of Airly.

(@bieniu - #52225) (airly docs)

When using 此integrations with IoTHub, the event_hub_name is now a required field can be filled by the DeviceID when using IoTHub.

(@eavanvalkenburg - #52049) (azure_event_hub docs)

Our Docker 容器 has limited support for CEC drivers to those provided by the Linux kernel. This applies to the Home Assistant 容器, Home Assistant OS and Home Assistant 受监管模式 安装 types.

This will 遮盖 most CEC drivers out there.

(@pvizeli - #51637)

The Coinbase 集成 migrated to 配置 via the UI. Configuring Coinbase via YAML 配置 has been deprecated and will be removed in a future Home Assistant 发布. Your existing YAML 配置 is automatically imported on 升级 to this 发布; and thus can be safely removed from your YAML 配置 after upgrading.

(@TomBrien - #45354) (coinbase docs)


Only accounts explicitly included in account_balance_currencies will be loaded. Excluding the option will no longer load all provided accounts as Coinbase's API now provides at least 29 accounts even if they are not configured in your API 设置 on Coinbase.

(@TomBrien - #51981) (coinbase docs)

The statistics table is a Home Assistant data table that is not exposed or used by Home Assistant yet and is part of an alpha / feature that is in development. However, it does exist and you might already want to check it out or find a use for it.

In this 发布, the content of this table is reset. This does not impact any 状态 history and this data isn't used by Home Assistant as of yet.

If you have no idea what this message is about, you can safely ignore it. We have merely listed this to be complete in our backward-incompatible changes report.

(@emontnemery - #52331) (history docs)

Configuring the DSMR 集成 via YAML has been deprecated and will be removed in Home Assistant 2021.9. If you have an existing YAML 配置 for the DSMR platform is will be imported into the UI automatically on 升级. You can safely remove the DSMR YAML 配置 after upgrading Home Assistant.

(@frenck - #52179) (dsmr docs)


The Hourly Gas Consumption 传感器 has been removed from the DSMR 集成. This 传感器 was calculated and it is not an actual datapoint from the energy meter.

If you are looking for a replacement, you can use the Derivative integrations to re-create the hourly (or any other timeframe) 传感器 based on the total Gas consumption 传感器.

(@frenck - #52147) (dsmr docs)

  • The 集成 has been disabled since it requires an old 版本 of the websocket-client library which is incompatible with the requirements of other 集成 that are actively maintained.

  • It's not clear if 此integrations still works with the gpmdp app that now only supports YouTube Music. If there's someone that uses the 集成 successfully and wants to take on the maintenance task that is required to get the 集成 in a compatible 状态, please create an issue to discuss the future of 此integrations.

(@MartinHjelmare - #51509) (gpmdp docs)

The Growatt API has changed individual PV array units from Watts to Kilowatts. This change is to 更新 the units used for these values in Home Assistant, therefore the units for these values will change.

(@muppet3000 - #52021) (growatt_server docs)

Kuler Sky 灯光 no longer supports the deprecated white_value 属性 for its 灯光. Use the rgbw_color 属性 instead.

(@emontnemery - #52080) (kulersky docs)

You can no longer use the 2 letters of your country code, but must now use the complete country name in your 配置. To find out which country names you can use, please look at meteoalarm.org.

(@rolfberkenbosch - #51383) (meteoalarm docs)

As announced in 2021.4, the “old style” YAML was deprecated and now removed:

Example “old style” 配置, that is now invalid:

modbus:
  - name: hub1
    type: tcp
    host: IP_ADDRESS
    port: 502

binary_sensor:
  platform: modbus
  registers:
    - name: Sensor1
      hub: hub1
      slave: 1
      register: 100

Same 配置 in valid new style:

modbus:
  - name: hub1
    type: tcp
    host: IP_ADDRESS
    port: 502
    binary_sensors:
      - name: Sensor1
        slave: 1
        address: 100

(@janiversen - #51117) (modbus docs)


The coil and register 配置 options are changed to address and (if not default) input_type.

Previous 配置 example:

modbus:
  - name: hub1
    type: tcp
    host: IP_ADDRESS
    port: 502
    covers:
      - name: Door1
        coil: 117
      - name: Door2
        register: 131
        state_open: 1
        state_closed: 0

The new 配置 looks like this:

modbus:
  - name: hub1
    type: tcp
    host: IP_ADDRESS
    port: 502
    covers:
      - name: Door1
        input_type: coil
        address: 117
      - name: Door2
        address: 131
        state_open: 1
        state_closed: 0

(@janiversen - #51154) (modbus docs)


The 配置 属性 curent_temp_register and current_temp_register_type are changed to address and input_type in order for all platforms to have a common configurations.

Before this PR, this was legal:

modbus:
  - name: hub1
    type: tcp
    host: IP_ADDRESS
    port: 502
    climates:
      - name: "Watlow F4T"
        current_temp_register: 27586
        current_temp_register_type: holding

This changes to:

modbus:
  - name: hub1
    type: tcp
    host: IP_ADDRESS
    port: 502
    climates:
      - name: "Watlow F4T"
        address: 27586
        input_type: holding

(@janiversen - #51202) (modbus docs)


Modbus 传感器 ‘reverse_order’ is no longer supported, please use ‘swap’ instead.

Old 配置:

modbus:
  - name: hub1
    type: tcp
    host: IP_ADDRESS
    port: 502
    sensors:
      - name: Sensor1
        address: 100
        reverse_order: true

New 配置:

modbus:
  - name: hub1
    type: tcp
    host: IP_ADDRESS
    port: 502
    sensors:
      - name: Sensor1
        address: 100
        swap: word

(@janiversen - #51665) (modbus docs)


data_count is no longer supported, please use count.

No longer supported:

modbus:
  - name: hub1
    type: tcp
    host: IP_ADDRESS
    port: 502
    climates:
      - name: "Watlow F4T"
        address: 27586
        input_type: holding
        data_count: 1
        ...

Please change it to:

modbus:
  - name: hub1
    type: tcp
    host: IP_ADDRESS
    port: 502
    climates:
      - name: "Watlow F4T"
        address: 27586
        input_type: holding
        count: 1
        ...

(@janiversen - #51668) (modbus docs)

It's no longer possible to set 属性 defined in the base component via a configured json_attributes_topic.

For example, a 灯光 no longer accepts brightness via the json_attribute_topic. This was unintended and an undocumented functionality that lead to unexpected behavior.

This change applies to all supported MQTT platforms.

(@emontnemery - #52242 #52278 #52280 #52285 #52286 #52283 #52289 #52291 #52290 #52288 #52282 #52279) (MQTT docs)

The AirQuality platform has been marked as deprecated. The air_quality 实体 will be deleted and replaced with sensor 实体. You need to 更新 your 自动化 and 仪表盘 if you have been using these air_quality 实体 in those.

(@bieniu - #52152) (nam docs)

Open Z-Wave 灯光 no longer support the deprecated white_value 属性, use rgbw_color instead.

(@emontnemery - #52063) (ozw docs)

Prometheus is now converting temperatures in °F to °C. If you are relying on temperature_c being in Fahrenheit, you will need to make adjustments, for example by doing a unit conversion in a PromQL query.

(@masto - #52212) (prometheus docs)

The underlying library that is used for the database connections, has been updated. This fixes a bug, that might be a breaking change for you.

If you use an @ in your database username or password, you will have to adjust your database connection string to use %40 instead.

Database connection strings are considered URLs, thus special characters need to be encoded. %40 is the URL encoded 版本 of @.

The 开关 extra 状态 属性 fan_speed and room_size will be removed in the next 发布. As of this 发布, both 属性 are available as 实体, making it possible to change the value with Home Assistant.

(@milanmeu - #51993) (rituals_perfume_genie docs)

From April 2020, the Sony Bravia TV 集成 has been automatically importing your import of existing YAML configurations. Now we have removed this option for migration. Your existing 配置 has been imported to the UI already and can now be safely removed from your YAML 配置 files.

(@bieniu - #52141) (braviatv docs)

With the change to the new, and unique, electric tariff 2.0TD, if you previously had configured multiple PVPC 传感器 monitoring prices for more than one of the old tariffs, only the first one will survive. This means if you have any 自动化 or 脚本 that depends on these removed 传感器, you might need to adjust them.

(@azogue - #51789) (pvpc_hourly_pricing docs)

Tasmota doesn't support independent control of all four channels of an RGBW 灯光, so rgbw_color was a very poor fit for it and gave counter-intuitive results. Tasmota 灯光 supporting color and white will now be added as a 灯光 supporting color modes hs and white, not as a 灯光 supporting color_mode rgbw. now supports setting white instead.

场景 setting a Tasmota 灯光 can be updated by using the 场景 UI editor.

自动化 setting a Tasmota 灯光 need to be updated manually, to set a 灯光 to white mode do:

  - service: light.turn_on
    target:
      entity_id: light.genbbc05
    data:
      white: 242

(@emontnemery - #51608) (tasmota docs)

In preparation for multi-设备 support, 配置 via the UI and support for discovery; 此integrations is migrating 实体 属性 into 传感器 to be later added as 设备 实体. The following 开关 实体 属性 migrated to 传感器:

属性传感器 Name
power_consumptionPower Consumption
electric_currentElectric Current
remaining_timeRemaining Time
auto_off_setAuto Shutdown

(@thecode - #51964) (switcher_kis docs)

The 集成 has been rewritten from the ground up and is now configurable via the user interface only. Existing platform YAML config will automatically be imported into the user interface on 升级 and can be safely removed from the YAML 配置 after the 升级 has been completed.

(@vigonotion - #51561) (yamaha_musiccast docs)

The IPv6 配置 option has been deprecated in favor of the 设置 provided by the network 集成.

(@bdraco - #51173) (zeroconf docs)

全部变更