Strange automation behavior

hello,

I migrated as everyone else many releases ago from doing automations the old way to the new way. I’ve even tried to create a few automations from the automation editor provided by the GUI.

What is very strange is that new automations seem be added in reverse order, I can’t really figure it out, the syntax looks off, yet still it validates and works.

Take a look at the following lines from my automations.yaml, the last one added by the automation editor is in reverse order yet it works :open_mouth:
What is also strange is that adding automations manually like I always did all the time results in a validation error… wtf is going on :slight_smile:

ledstrip_animation_speed * valid
grow_light2 * valid
1521567548635 * works but looks all messed up

- id: ledstrip_animation_speed   
  alias: Ledstrip Animation Speed
  initial_state: true
  hide_entity: false
  trigger:
  - platform: state
    entity_id: input_number.led_strip_1_animspeed
  action:
  - service: mqtt.publish
    data_template:
      topic: huset/LedStrip1/set
      payload: '{"transition":{{ trigger.to_state.state | int }}}'
- id: grow_light2
  alias: Växtlampa
  initial_state: true
  hide_entity: false
  trigger:
  - at: 04:30
    platform: time
  condition:
  - after: 04:30
    before: '18:00'
    condition: time
  action:
  - data:
      entity_id: group.grow_light
    entity_id: group.grow_light
    service: homeassistant.turn_on
- action:
  - data:
      entity_id: group.grow_light
    service: homeassistant.turn_off
  alias: Växtlampa av
  condition: []
  id: '1521567548635'
  trigger:
  - at: '18:00'
    platform: time

The order of keys doesn’t matter. So like for a the broadlink you could put:

switch:
  - platform: broadlink
    host: IP_ADDRESS
    mac: 'MAC_ADDRESS'

or

switch:
  - mac: 'MAC_ADDRESS'
    platform: broadlink
    host: IP_ADDRESS

so long as all the required keys are there.

The only time ordering matters is with script sequences (and therefore actions in automations) because they’re run in the order they appear.

From a readability point of view, for a human like you or I, we see the automation as trigger > condition > action, because that’s how it works, but for the computer so long as it has all three it doesn’t care.

As for why the automation editor doesn’t spit it out in human readable format, that’s anyone’s guess. It’s been raised several times before because if something goes wrong and we need to fix it, it’s much easier to fix if we can read it, but nothing seems to be being done to sort it out.