Automation YAML Error

I’m just new to this and read a lot about the syntax of yaml automation files. I think I have followed all the rules for spacing and indentation and still it gives me errors.

Here’s my automation text. Any help on obvious errors are appreciated.

- automation:

- id: SunDownLights
- alias: Hallway Lamp at Dusk
  trigger:
    platform: sun
    event: sunset
  action:
    service: light.turn_on
    entity_id: light.hall_light
    data:
      brightness: "1"
 
- id: SunRiseLights
- alias: Hallway Lamp at Dawn
  trigger:
    platform: sun
    event: sunrise
  action:
    service: light.turn_off
    entity_id: light.hall_light
    data:
      brightness: "0"
      
- id: SunsetKitchen
- alias: Kitchen Lamp at Sunset
  trigger:
    platform: sun
    event: sunset
  action:
    service: light.turn_on
    entity_id: light.kitchen_lamp
    data:
      brightness: "9"
      
- id: SunriseKitchen
- alias: Kitchen Lamp at Sunrise
  trigger:
    platform: sun
    event: sunrise
  action:
    service: light.turn_off
    entity_id: light.kitchen_lamp
    data:
      brightness: "0"

Can you paste your config then highlight it and then hit the < / > in the bar above the text box? This preserves the formatting so it can be checked.

Also, is there any thing in the error log? Often it will point to a specific line that is causing the issue.

Thanks. I was struggling to get the formatting to come across.

automation:

  - id: SunDownLights
    alias: Hallway Lamp at Dusk
    trigger:
      platform: sun
      event: sunset
    action:
      service: light.turn_on
      entity_id: light.hall_light
      data:
        brightness: "1"

Try this formatting. You have hyphens in a few to many places.

Keep in mind that hyphen = start of an item in a list.

That’s funny I was going to say the opposite :wink:

 - alias: 'Turn on Garden Cams in mornin'
   trigger:
     - platform: sun
       event: sunrise
   action:
     - service: switch.turn_on
       entity_id: switch.pilivingroomgardencam, switch.pilivingroomgardencamseat

I always put hyphens before platform and service, however mine are in a separate automations file so that probably makes a difference.

This seems to have done the trick. Thanks so much.

I was led to believe you needed a hyphen when you repeat a variable such as alias.

To clarify, if I want to add a new item of automation I just need to create a line such as this and everything beneath is fine?

- id: SunDownLights

Yep, that’s right.

Like this:

- id: SundownLights
  alias: Sundown

etc.

1 Like

Yeah,sorry I should have been clearer. Hyphens are used for lists. Multiple automations under the automation heading, multiple platforms, services etc.