Questions about platform time trigger supported format

Official documentation gives this:

automation:
  trigger:
    platform: time
    # Military time format. This trigger will fire at 3:32 PM
    at: "15:32:00"

When I create automation with assistant i get this:

trigger:
  - at: '23:00'
    platform: time

and sometimes even without quote:

trigger:
  - at: 23:00
    platform: time

I’ve found this in some examples:

trigger:
    - platform: time
      at: '22:00:00'

I know yaml is strict, but there, I would like it to be more restrictive, because now I have some automations that I run without problems and some that did not trigger. So I would like to know what is the recommended code. Sometimes platform is before at, and with assistant it’s at before platform. sometimes double quote, sometimes single quote for hours format. Sometimes 09:00, sometimes 9:00, or 09:00:00

Any recommendations welcome!

1 Like

This is normal behaviour of the automation editor, don’t know why it does it this way, however the order doesn’t matter, no worries here.

As far as I can see all the different notations for time are correct like this, could it be that there are other issues than the time trigger in the not working automations. I suggest always using the same format, I use always use it like this “09:00:00”

1 Like

ok, thanks, will follow your recommendation, but what about the minus sign

- platform

that is not in the official documentation? Works with and without? Typo error?

Someone made the choice to sort the dictionary/map alphabetically when generated by the UI. A lot of people think this is a bad idea.

Order doers not matter in dictionarys so other than human readability it makes no difference. There’s a nice primer by Thomas Loven here: Thomas Lovén - YAML for Non-programmers

2 Likes

The minus is needed if you have multiple entries in one section (trigger, conditon, action). If you have have more than one trigger, condition, action you need to put a minus in front of each one that. If you only have one trigger, condition, action the minus is not needed.

Which is also covered in the link above.

if you refer to the minus as dash, or better: ‘list-indicator’ it makes more sense :wink:

also, instead of the list with minuses , you can also use a comma separated list.

entity_id:
  - entity_1
  - entity_2
  - entity_3

or

entity_id: entity_1, entity_2, entity_3

Even the list braces can be used though must admit not sure about quotes in that, which would depend on the list being made up of strings (which need quotes) or not:

entity_id: [entity_1, entity_2, entity_3]
1 Like

thanks for all these clarifications

This only works in limited scenarios. The schema for the particular option needs to support it, and most don’t. entity_id is one of the few that does.

For time formats it accepts H:M or H:M:S. In general you should quote them, because HA wants the value to be a string (that it can parse), and YAML might convert the (unquoted) time to an integer (number of seconds), depending on what you enter. This is similar to having to quote on, otherwise YAML will convert it to True.

2 Likes