0.113: Automations & Scripts, and even more performance!

![](upload://m0Av21T0ATEMSj6GnfG89FfFdaj.png)

Another special, themed, release inbound!

It seems like @bdraco is unstoppable; he just keeps going on improving the performance of the Core. I truly admire him for the work he has been delivering the past months, however, that is not the point of this release. Sorry, @bdraco!

This release is about: Automations & Scripts! Yes!!!

A long, long time bug with automation triggering has been resolved, but not only that, @pnbruckner went all-in by extending the automation/script engine even more.

Adding repeat, a chooser and running modes (with cool down possibilities as a side-effect).

Iā€™ve been playing with these features on my home already and Iā€™ve changed/improved quite a few things. For real, @pnbruckner, thank you!

Enjoy the release!

../Frenck

Ludeeus joins Nabu Casa

Today weā€™re happy to announce that @ludeeus is joining Nabu Casa to work full-time on Home Assistant!

Ludeeus has been a core contributor for a long time working on the Supervisor panel and different bits of the frontend. He is, however, mainly known as the creator of the Home Assistant Community Store (HACS).

Weā€™re looking forward to seeing what he can do now that he is able to focus full-time on Home Assistant.

Welcome @ludeeus!

Automations & Scripts

This release brings changes to our automations and scripts. Before we start with this all, please note, that the action part of an automation is a script sequence.

So, all discussed below, apply to both scripts and automations.

Before diving in: All automation and script changes, have been driven by @pnbruckner! It is awesome! Thanks!

Automations & Scripts: Bug fix

There has been an issue with our automations 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:

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
        entity_id: light.bulb
      - delay:
          seconds: 10
      - service: light.turn_off
        entity_id: light.bulb

This automation turns on a light bulb when the button is pressed, and after 10 seconds, it turns off the light bulb again. A fairly basic automation, which does exactly what one would expect, except when a button is pressed twice.

So it takes 10 seconds for the bulb to turn off, what if you press the button again after 5 seconds?

Please, think about this for a momentā€¦

What actually happened before 0.113, is that the light bulb would turn off immediately! Chances are, you didnā€™t expect that.

Letā€™s explain this: So the first button push, turns on the light, and the delay is active for 10 seconds. The second button 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 actions/sequence, causing the light to turn off immediately!

That bug, has been fixed. As of this release, the second button press wouldnā€™t do anything and the light will now turn off after 10 seconds, which the first button push has triggered.

Automations & Scripts: Running modes

With the above-mentioned bug fix, it now becomes possible to introduce new running modes for both scripts and automations. It allows you to control what happens if actions of a previous trigger are still running.

Considering the light bulb example in the bug fix paraph above, it shows the default mode: single, which means: Do not run and ignore the trigger if a previous action of the same automation is still running.

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

Mode Description single Do not start a new run, if running already. restart Start a new run, after stopping the previous run. queued Start a new run after all previous runs complete. parallel Start a new, independent, run in parallel with previous runs.

![](upload://ssL2poZMdipMC5DQyc8iJGVp7zl.jpeg) Automation/script 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 light bulb would turn on for 10 seconds after a button press?

This would make every button press within the 10 seconds, restart the countdown again:

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

And this example, would turn on/off the light, for 10 seconds twice, if the button was pressed after 5 seconds.

automation:
  - trigger:
      - ...
    mode: queue
    action:
      - ...

The modes are also available for automations and scripts in the frontend UI:

![](upload://g7Wn4AA6BFAYg9NnhVmn2TyxMld.png) Screenshot of running modes in the frontend.

This is a powerful feature, which allows you to control how automations and scripts are run in ways you could not do before.

More information about the running mode can be found the automations and scripts documentation.

Automations & Scripts: Repeats

A brand new action is made to allow for repeating (also called loops) part of your automations or scripts.

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 condition(s) is/are met.
  • Repeat until: Runs at least once, and decides after that to repeat until the condition(s) is/are met.

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

- alias: Send notification spam to phone
  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 documentation.

Automations & Scripts: Chooser

Got multiple automations for that single light to turn it on/off? Or multiple automations/scripts to handle the different buttons on some remote?

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

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

automation:
  - alias: "Example"
    description: "On button press, turn on the light bulb for 10 seconds."
    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
              entity_id: light.bulb
        - conditions:
            - condition: state
              entity_id: binary_sensor.button2
              state: "on"
          sequence:
            - service: light.turn_off
              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 button isnā€™t handled by any of the conditions 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 documentation.

Automations & Scripts: Sub-second precision

Thanks to a bunch of optimizations done this release, which is discussed later in this blog 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 script that toggles the light every 500 milliseconds 10 times.

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

Automations & Scripts: Bonus! Cool down

An often requested feature is to allow for a cool down time on an automation. What that entails is setting a limiting the run of an automation or script 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 automation, combined with the last delay of 10 seconds, prevents this automation from being ran more often than only once every 10 seconds. This is ideal for things like a doorbell.

MDI icons updated

It has taken some time for us to upgrade to the newest version of Material Design Icons, 5.3.45, there was a reason for that, version 5.0.45 contains a lot of breaking changes.

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

A lot of icons are renamed, and some are removed. In this release, 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 warning in the log, in version 0.115,this conversion path will be removed and removed icons and old names no longer work.

So make sure to check your logs 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 integration.

Please note: It is possible that custom integrations (also known as custom components) use deprecated icons. These can throw warnings that need to be addressed in the custom integration.

Script and Scene editor updates

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

Especially the naming is helpful, you no longer have to search your states for a long numeric entity id that matches your script.

![](upload://tgJbUS2E2x4j4xdfjZIms3nkhLv.png) Screenshot of a script name, icon and run mode.

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

More speed optimizations

After, the well-received, speed optimization done in the 0.111 & 0.112 releases, the sega 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, Container or Supervised installation, this your Home Assistant instance will run on Python 3.8. No action from your end is needed for this.

It is not just a normal Python version, but @pvizeli has worked on a highly optimized Python version for Home Assistant, hitting performance improvements that can reach up to 40%! He wrote a more technical article about this on our developers blog.

Then @bdraco did his part on adding some improvements to the Core. He changed a lot of handling around event & state listeners, in such a way less things trigger unneeded, which reduces processing when states change.

This lowers CPU usage and improves response speed when you have many state changes happening in a short time span, or when having a lot of automations.

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 release should drastically lower the CPU usage of Home Assistant for most installations.

Other noteworthy changes

  • Philips Hue groups can now be turned on/off in the integration options via the UI.
  • The OpenZWave (beta) got 3 new services. Two of those are for setting user codes on locks. The other allows for setting device-specific configuration 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 release is full of RTL tweaks again!

New Integrations

Three new integration added this release:

New Platforms

The following integration got support for a new platform:

Integrations now available to set up from the UI

The following integrations are now available via the Home Assistant UI:

If you need helpā€¦

ā€¦donā€™t hesitate to use our very active forums or join us for a little chat.

Experiencing issues introduced by this release? Please report them in our issue tracker. Make sure to fill in all fields of the issue template.


This is a companion discussion topic for the original entry at https://www.home-assistant.io/blog/2020/07/22/release-113/
11 Likes

Awesome, finally some love for scripts and automations :grin:

@frenck you normally poat the blo posts right? Something seems to be wrong with the blog post, the ā€œbreaking changesā€ section is just an unstructured text.

1 Like

Just finished editing :wink:

1 Like

the sega towards improving resource usage and responsiveness of the platform continues.

Im quite glad that Sonic from SEGA has been helping you guys optimize home assistant! :wink: :wink:

3 Likes

I like the new format of the breaking changes section. Its quick to scan through and only ā€˜openā€™ the ones that impact me. Thanks!

14 Likes

Awesome Update!! Been waiting for that automation bug to be fixed and had workarounds to overcome, but this is a GOOD news!! Waiting to update my code nowā€¦ Thank you so much #HomeAssistant teamā€¦ :slight_smile:

LOL! Iā€™ve played too much when I was just a little boy :joy:
Spelling correction inbound!

1 Like

Cool news, thank you! pnbruckner was always my automations hero :slight_smile:

One little thing about actions and sequences. We still can not do if else in yaml, right? Or I was asleep for too long?
Like
-turn on the light
-delay 10 sec
-if motion is off - turn lights off
-else turn tv onā€¦

Yes you can, that is the choose that was added, see the examples in the blog post or the documentation.

2 Likes

Congratulations :tada: to @ludeeus for joining Nabu Casa hope you enjoy working with a great bunch of guys. :clap: :clap:

11 Likes

Amazing release as usual guys and awesome news that @ludeeus joining the team. He is always helpful and willing to share his knowledge. Itā€™s a pleasure to know him.

10 Likes

I just noticed that 0.113.0 is not on docker hub. Is this going to get pushed?

It always takes up to 2 hours after announcing the release, before it is available. However, with the speed improvements made in this release, the build itself should take only 40 minutes now :smiley:

Edit: And the build is done. 0.113.0 is now available for all platforms.

3 Likes

Thanks! I didnā€™t realize there was a delay. Rebuilding my container nowā€¦

1 Like

@bdraco Thanks for all the work. Especially the hidden ā€˜harmony hubā€™ gem.

5 Likes

What does this sentence even mean?
ā€œFirst of all, if you are running a Home Assistant OS, Container or Supervised installation, this your Home Assistant instance will run on Python 3.8. No action from your end is needed for this.ā€

It means unless youā€™re running HA Core all by itself, you donā€™t need to manage the python version yourself.

I suppose delay still doesnā€™t survive HA restart?

Correct, a delay is not a state, but a running program. A restart means you shutdown the running program.

Ohā€¦ so that broken English sentence does affect meā€¦ nice.