0.113:自动化与脚本,以及更多性能提升!

又一篇带有鲜明主题的特别发布来了!

看起来 @bdraco 简直停不下来; 他一直在持续提升 Core 的性能。过去几个月里他交出的成果真的让我佩服, 不过,这并不是这次发布真正的主角。 抱歉啦,@bdraco

这次发布的主题是:自动化与脚本!没错!!!

一个存在了很久很久的自动化触发 bug 终于被修复了, 而且还不止如此,@pnbruckner 还全力扩展了自动化/脚本引擎。

现在加入了 repeat、choose,以及运行模式(顺带还带来了实现冷却时间的能力)。

我已经在自己家里把这些功能玩起来了,也顺手改进了不少东西。 真的,@pnbruckner,太感谢你了!

祝你享受这次发布!

../Frenck

Ludeeus 加入 Nabu Casa

今天我们很高兴地宣布, @ludeeus 已加入 Nabu Casa,全职投入 Home Assistant 的开发!

Ludeeus 长期以来一直是核心贡献者,参与过 Supervisor 面板和前端中的多个部分。 不过,大家最熟悉的还是他作为 Home Assistant Community Store (HACS) 创建者的身份。

现在他终于可以全职专注于 Home Assistant,我们也非常期待看到他接下来会带来什么。

欢迎你, @ludeeus

自动化与脚本

这个版本为我们的自动化和脚本带来了不少改动。正式开始前,请先注意:自动化中的 action 部分,本质上就是一个脚本 sequence

所以,下面提到的所有内容,同时适用于脚本和自动化。

在深入之前还要先说一句:这次所有自动化和脚本方面的改动,几乎都由 @pnbruckner 推动完成!真的太棒了,感谢!

自动化 & 脚本: Bug fix

There has been an issue with our 自动化 for a long time already, which you actually might have never noticed. It is kinda hard to explain, so this needs an example.

Consider the following 自动化:

automation:
  - alias: "Example"
    description: "On button press, turn on the light bulb for 10 seconds."
    trigger:
      - platform: state
        entity_id: binary_sensor.button
        to: "on"
    action:
      - service: light.turn_on
        target:
          entity_id: light.bulb
      - delay:
          seconds: 10
      - service: light.turn_off
        target:
          entity_id: light.bulb

This 自动化 turns on a 灯光 bulb when the 按钮 is pressed, and after 10 seconds, it turns off the 灯光 bulb again. A fairly basic 自动化, which does exactly what one would expect, except when a 按钮 is pressed twice.

So it takes 10 seconds for the bulb to 关闭, what if you press the 按钮 again after 5 seconds?

Please, think about this for a moment...

What actually happened before 0.113, is that the 灯光 bulb would 关闭 immediately! Chances are, you didn't expect that.

Let's explain this: So the first 按钮 push, turns on the 灯光, and the delay is active for 10 seconds. The second 按钮 push, done after 5 seconds, is actually not handled, however, it does cause the delay of the first run to cancel itself and continues to run the rest of the 动作/sequence, causing the 灯光 to 关闭 immediately!

That bug, has been fixed. As of this 发布, the second 按钮 press wouldn't do anything and the 灯光 will now 关闭 after 10 seconds, which the first 按钮 push has triggered.

自动化 & 脚本: Running modes

With the above-mentioned bug fix, it now becomes possible to introduce new running modes for both 脚本 and 自动化. It allows you to control what happens if 动作 of a previous 触发器 are still running.

Considering the 灯光 bulb example in the bug fix paraph above, it shows the default mode: single, which means: Do not run and ignore the 触发器 if a previous 动作 of the same 自动化 is still running.

Besides the default single mode, the following modes are now available:

ModeDescription
singleDo not start a new run, if running already.
restartStart a new run, after stopping the previous run.
queuedStart a new run after all previous runs complete.
parallelStart a new, independent, run in parallel with previous runs.

自动化/脚本 running modes visual explained. 自动化/脚本 running modes visual explained.

For the queued and parallel modes, an additional parameter max is available to control the maximum number of runs that are awaiting each other. When omitting this setting, it would default to 10.

To clarify a little more, remember the first example in the bug fix paragraph where the 灯光 bulb would 打开 for 10 seconds after a 按钮 press?

This would make every 按钮 press within the 10 seconds, 重启 the countdown again:

automation:
  - trigger:
      - ...
    mode: restart
    action:
      - ...

And this example, would 打开/off the 灯光, for 10 seconds twice, if the 按钮 was pressed after 5 seconds.

automation:
  - trigger:
      - ...
    mode: queued
    action:
      - ...

The modes are also available for 自动化 and 脚本 in the 前端 UI:

Screenshot of running modes in the 前端 Screenshot of running modes in the 前端.

This is a powerful feature, which allows you to control how 自动化 and 脚本 are run in ways you could not do before.

More information about the running mode can be found in the 自动化 and 脚本 文档.

自动化 & 脚本: Repeats

A brand new 动作 is made to allow for repeating (also called loops) part of your 自动化 or 脚本.

The new repeat feature can be used in three different ways:

  • Counted repeat: Control how many times to repeat a sequence.
  • While loop: Keep repeating as long the 条件(s) is/are met.
  • Repeat until: Runs at least once, and decides after that to repeat until the 条件(s) is/are met.

For example, this would spam your phone with the same message 10 times:

# Send notification spam to phone
script:
  phone_spam:
    sequence:
      repeat:
        count: 10
        sequence:
          - service: notify.frenck
            data:
              message: Ding dong! Someone is at the door!

More information about repeats can be found in the 文档.

自动化 & 脚本: Chooser

Got multiple 自动化 for that single 灯光 to turn it on/off? Or multiple 自动化/脚本 to handle the different 按钮 on some 遥控器?

You can now combine them using a chooser. The chooser is able to pick the first sequence that matches a 条件, or if none match, run a default sequence.

This means each individual sequence in the chooser is paired with its own set of 条件.

automation:
  - alias: "Example"
    description: "On button press, choose the right thing to run."
    trigger:
      - platform: state
        entity_id:
          - binary_sensor.button1
          - binary_sensor.button2
          - binary_sensor.button3
    action:
      - choose:
          - conditions:
              - condition: state
                entity_id: binary_sensor.button1
                state: "on"
            sequence:
              - service: light.turn_on
                target:
                  entity_id: light.bulb
          - conditions:
              - condition: state
                entity_id: binary_sensor.button2
                state: "on"
            sequence:
              - service: light.turn_off
                target:
                  entity_id: light.bulb
        default:
          - service: notify.frenck
            data:
              message: Some other unknown button was pressed!

In the above example, pushing button1, turns on the bulb; while button2 turns it off again. The third 按钮 isn't handled by any of the 条件 in the chooser and the (optional) default is run instead.

The chooser can be used as an if/else statement, where the default acts as the else. Or even as if/else if/else statement as shown in the YAML example above.

More information about the chooser can be found in the 文档.

自动化 & 脚本: Sub-second precision

Thanks to a bunch of optimizations done this 发布, which is discussed later in this 博客 post, we now have sub-second precision available to our delays.

This precision is helpful in case you want a delay that is less than a second, for example, 500 milliseconds.

An example 脚本 that toggles the 灯光 every 500 milliseconds 10 times.

script:
  blink_light:
    sequence:
      repeat:
        count: 10
        sequence:
          - service: light.toggle
            target:
              entity_id: light.bulb
          - delay:
              milliseconds: 500

自动化 & 脚本: Bonus! Cool down

An often requested feature is to allow for a cool down time on an 自动化. What that entails is setting a limit on the run of an 自动化 or 脚本 to a certain time frame.

While this is not a feature specifically added or build, it can be achieved now using the new run modes.

automation:
  - alias: "Doorbell cool down"
    description: "Prevent multiple message being send when spamming the doorbell."
    mode: single # Which is the default
    trigger:
      - platform: state
        state: binary_sensor.doorbell
        to: "on"
    action:
      - service: notify.frenck
        data:
          message: Ding dong! Someone is at the door!
      - delay:
          seconds: 10

The single run mode of this 自动化, combined with the last delay of 10 seconds, prevents this 自动化 from being ran more often than only once every 10 seconds. This is ideal for things like a doorbell.

MDI 图标更新

It has taken some time for us to 升级 to the newest 版本 of Material Design Icons, 5.3.45, there was a reason for that, 版本 5.0.45 contains a lot of backward-incompatible changes.

We wanted to handle these well, so it took some time.

A lot of icons are renamed, and some are removed. In this 发布, we included all new, and all removed icons and we made sure the new and the old name work.

If you use an icon that is renamed or removed we will show a 警告 in the 日志, in 版本 0.115, this conversion path will be removed and removed icons and old names will no longer work.

So make sure to check your 日志 if you need to adjust any of your used MDI icons.

Most of the removed MDI icons can be found in Simple icons, which is available as a custom 集成.

Please note: It is possible that custom 集成 (also known as custom components) use deprecated icons. These can throw 警告 that need to be addressed in the custom 集成.

脚本与场景编辑器更新

The UI to edit or create a 脚本 has been updated, besides support for the new running mode, you can now give your 脚本 a custom icon and ID from the UI.

Especially the ID is helpful, you no longer have to search your 状态 for a long numeric 实体 id that matches your 脚本.

Screenshot of a 脚本 name, icon and run mode. Screenshot of a 脚本 ID, icon and run mode.

The support for setting a custom icon, is also added to the 场景 editor.

更多速度优化

After, the well-received, speed optimization done in the 0.111 & 0.112 releases, the saga towards improving resource usage and responsiveness of the platform continues.

This time we have both @bdraco and @pvizeli to thank for some great optimizations that will reduce the CPU usage of Home Assistant.

First of all, if you are running a Home Assistant OS, 容器 or 受监管模式 安装, then your Home Assistant instance will run on Python 3.8. No 动作 from your end is needed for this.

It is not just a normal Python 版本, but @pvizeli has worked on a highly optimized Python 版本 for Home Assistant, hitting performance improvements that can reach up to 40%! He wrote a more technical article about this on our 开发者 博客.

Then @bdraco did his part on adding some improvements to the 核心. He changed a lot of handling around event & 状态 listeners, in such a way less things 触发器 unneeded, which reduces processing when 状态 change.

This lowers CPU usage and improves response speed when you have many 状态 changes happening in a short time span, or when having a lot of 自动化.

Also, all time listeners now have microsecond precision as they are scheduled on the internal event loop, instead of the previous situation when it relied on the internal clock that triggered every second.

This 发布 should drastically lower the CPU usage of Home Assistant for most 安装.

其他值得注意的变更

  • Philips Hue groups can now be turned on/off in the 集成 options via the UI.
  • The OpenZWave (beta) got 3 new 服务. Two of those are for setting 用户 codes on 门锁. The other allows for setting 设备-specific 配置 parameters.
  • After a moment of absence, @yosilevy is back! He has been the one fixing all kinds of RTL issues we had in Home Assistant, with his return, this 发布 is full of RTL tweaks again!

新集成

Three new 集成 added this 发布:

新平台

The following 集成 got support for a new platform:

现已可通过 UI 设置的集成

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

如果你需要帮助……

欢迎前往我们非常活跃的 论坛,或者加入 聊天频道

如果这个版本带来了问题,请到我们的 issue tracker 提交报告,并尽量完整填写 issue 模板中的所有字段。

不向后兼容的变更

Below is a listing of the breaking change for this 发布, per subject or 集成. Click on one of those to read more about the breaking change for that specific item.

最低 Python 版本 3.7.1

The minimum required Python 版本 has been bumped from Python 3.7.0 to 3.7.1.

(@bdraco - #37184)

TensorFlow

The TensorFlow 集成 will fail to 升级 due to missing wheels for Python 3.8. This affects all 安装 that rely on our default Docker 图像 running Python 3.8.

To work around this, remove the tensorflow platform under the image_processing domain from your 配置.yaml, before upgrading to 0.113.

Work is under way to resolve the problem. 更多信息 follow this issue: #38073

自动化/脚本

The way 自动化 behaved when they were triggered while "suspended" in a delay or wait_template step from a previous 触发器 event was unexpected. If this happened the suspended step would be aborted and the 自动化 would continue the 动作 sequence with the following step.

This change removes support for that "legacy" behavior, in both 自动化 and 脚本 (although 脚本 were less affected by this.)

It also provides new "modes" of operation for these 动作 sequences, namely single, restart, queued & parallel. To minimize the impact on existing 自动化 and 脚本, the default mode is single.

In addition, for queued & parallel modes there is now a new 配置 option -- max -- that controls the maximum number of "runs" that can be running and/or queued up at a time.

And lastly, the delay step is now much more precise, and supports delays of less than one second.

(@pnbruckner - #37729) (自动化 docs) (脚本 docs)

模板

Most of the 模板 platforms would check for extract_entities failing to extract 实体 and avoid setting up a 状态 change listener for "all" after extract_entities had warned that it could not extract the 实体 and updates would need to be done manually.

This protection has been extended to all 模板 platforms.

Alter the behavior of extract_entities to return the successfully extracted 实体 if one or more 模板 fail extraction instead of returning "all" and getting rejected by the platform itself.

(@bdraco - #37831) (模板 docs)

相对时间

Previously, the value used for displaying a relative time was floored before being interpolated into the localized string, leading to situations like these:

  • 47 hours ago is displayed as "1 day ago" instead of "2 days ago"
  • 13 days in the future is displayed as "in 1 week"

This change modifies the relativeTime function to use Math.round instead of Math.floor so the output more closely matches the actual relative time of the input.

(@GMTA - #37125)

MQTT

Birth and will messages are now published by default.

MQTT birth message defaults to:{"topic": "homeassistant/status", "payload": "online"} MQTT will message defaults to: {"topic": "homeassistant/status", "payload": "offline"}

MQTT will published also on clean connect from broker.

(@emontnemery - #37371) (MQTT docs)

ZHA 与 Hue 遥控器

This 更新 does contains a breaking change if you are using 设备 触发器 for the Hue Dimmer models RWL020 and RWL021.

We decided to 配置 these to use the extended manufacturer support so that we can support 4 触发器 per 按钮.

If you were previously using 设备 触发器 in 自动化 for these 设备 you will have reconfigure the 设备 leveraging the 按钮 on the 设备 page or remove and re-pair the 设备 after updating Home Assistant.

Then you will have to 更新 the 自动化 to use the new 触发器.

Sorry for the inconvenience.

(@dmulcahey - #37859) (zha docs)

ZHA 功率计量单位

Previously ZHA was displaying power as kilowatt (kW) for some 设备 (the ones with the SmartEnergy cluster), but since watts are more common as household power unit, ZHA will start using W for those instead.

If you have any calculations or accumulation based on power 传感器, they may need to be updated.

(@abmantis - #37896) (zha docs)

Philips Hue

Configuring a Hue bridge via YAML 配置 is now deprecated. Your current YAML 配置 is imported and can be safely removed after upgrading.

Adding Hue bridges manually by IP can now be done via the UI. Changing allowing Hue groups or unreachable Hue bulb is now managed by clicking the options 按钮 on the Hue 集成 in the UI.

(@frenck - #37268) (hue docs)

InfluxDB

Support for glob matching is added with InfluxDB filters.

InfluxDB was not using the common filtering logic shared by recorder, logbook, homekit, etc. and as a result had filtering logic that is inconsistent with the filtering logic of every other recorder-like component. This has been corrected causing the following changes in filtering logic.

Same domain specified in both include and exclude:

  • Previous behavior: All 实体 in that domain excluded
  • New behavior: All 实体 of that domain included unless 实体 is excluded by ID or by glob

Same 实体 ID specified in both include and exclude:

  • Previous behavior: 实体 excluded
  • New behavior: 实体 included

Filtering has 1+ exclude domains, 0 include domains, and 1+ include 实体 ID's specified:

  • Previous behavior: All 实体 not specifically listed by ID were excluded
  • New behavior: All 实体 not specifically excluded by either domain or ID are included.

(@mdegat01 - #37069) (influxdb docs)

Transmission

For all torrents 传感器 (e.g., active_torrents or started_torrents) order of the content of the torrent_info 属性 has changed to oldest first which means older torrents will appear first in the list.

Also a default limit of 10 items is also applied to the list to avoid very long strings stored in the recorder database. Both 配置 options, order and limit, can be adjusted in the 集成 UI.

(@zhulik - #35411) (transmission docs)

Logitech Harmony Hub

New 设备 and activities are visible as harmony 属性. The current activity is now updated as soon as the 遥控器 starts the activity change instead of being delayed until the activity is finished setting up.

(@bdraco - #37559) (harmony docs)

Xiaomi Miio

风扇 and 遥控器 components now have unique LED strings. If you had previously set your 自动化 calls from "风扇_set_led_on/off" to "遥控器_set_led_on/off", you will now need to set those back to "风扇".

(@alexhardwicke - #37605) (xiaomi_miio docs)

Samsung SyncThru Printer

Syncthru 配置 is now done through the 集成 UI page.

(@scop - #36690) (discovery docs) (syncthru docs)

Slack

Re-added the ability to use 遥控器 files (by URL) in Slack messages.

The data schema for sending files in Slack messages has changed, so be sure to 更新 any Slack-related 服务 calls with the new schema as listed in the Slack 集成 文档.

(@bachya - #37161) (slack docs)

RFXCOM RFXtrx

  • 配置 of 实体 name must now be done inside Home Assistant
  • Multiple 实体 may be generated for a single 设备
  • The events signalled from 实体 id's are removed in favor of events from an 集成 level.
  • The events format has changed.

(@elupus - #37742) (rfxtrx docs)

Fibaro

Fibaro Home Center 开关 that control 灯光 sources will now correctly be configured as 灯光 实体 (instead of 开关 实体). This causes those 实体 IDs to change from switch. to light. If this is not desirable, change the 设备 role in Home Center to something that isn't a 灯光 source (e.g., Other 设备).

(@danielpervan - #37690) (fibaro docs)

前端:已弃用的 HTML 导入

extra_html_url is now deprecated and support will be removed in 0.115. You can 开关 to the new extra_module_url or extra_js_url_es5 by changing your imported file to JavaScript.

With the start of custom components, you would import a HTML file for your component instead of JavaScript. That's why we have always supported importing extra HTML in the 前端 and custom 面板.

This has been deprecated and superseded by ES modules since some time and has no support anymore in browsers. We have a polyfill in place to still support this, but we are going to remove this.

In 版本 0.115 we will remove the ability to import HTML, you can use ES modules as a replacement.

(@bramkragten - #37843) (前端 docs)

前端:主题

The theme variable paper-card-background-color is removed. You can use ha-card-background or card-background-color as a replacement.

In general, all variables that start with paper will be removed at some point.

(@bramkragten - 前端#6377) (前端 docs)

发布 0.113.1 - July 24

发布 0.113.2 - July 28

发布 0.113.3 - August 1

所有变更

点击查看所有变更!