YAML copied from automations.yaml does not work in new automation

I copied one of my automations from automations.yaml, created a new automation, then pasted the YAML code. When I try to save it I get the error below. I looked at the YAML in my original automation and the indentation is different than the same automation in the automation.yaml file.

Any ideas why the YAML in the automations.yaml does not work when using it to create a new automation?

-Thanks

image

Based on the error it seems likely that the indentation is incorrect…

You need to post the config if you want us to something other than guess.

Below is the YAML from automations.yaml for the simple automation. There is something different about the indentation compared to the automation editor. But the question is why? Just curious.

-Thanks

alias: Porch Light on At Sunset
  description:
  triggers:
  - trigger: sun
    event: sunset
    enabled: true
  conditions: []
  actions:
  - action: switch.turn_on
    metadata: {}
    data: {}
    target:
      entity_id:
      - switch.porch_light
  - wait_for_trigger:
    - trigger: time
      at: '23:30:00'
      enabled: true
      weekday:
      - sun
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
    enabled: true
  - action: switch.turn_off
    metadata: {}
    data: {}
    target:
      entity_id:
      - switch.porch_light
  mode: single

As the error stated, the second line was indented improperly. In the Automation Editor’s “Edit in YAML” page alias, description, triggers, conditions, actions and mode should all line up on the left margin:

alias: Porch Light on At Sunset
description:
triggers:
  - trigger: sun
    event: sunset
    enabled: true
conditions: []
actions:
  - action: switch.turn_on
    metadata: {}
    data: {}
    target:
      entity_id:
      - switch.porch_light
  - wait_for_trigger:
    - trigger: time
      at: '23:30:00'
      enabled: true
      weekday:
      - sun
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
    enabled: true
  - action: switch.turn_off
    metadata: {}
    data: {}
    target:
      entity_id:
      - switch.porch_light
mode: single

Those keys also need to line up for entries in automations.yaml, but they will be further to the right to accommodate the dash that demarcates each item in the list of automation configurations.

http://thomasloven.com/blog/2018/08/YAML-For-Nonprogrammers/

Yes thank you. I was curious as to why the indentation was incorrect when copied from the automations.yaml. Well, who knows what goes on under the hood!