YAML issues - just need a sanity check

Hey,

I’m no stranger to YAML but I’m running into an issue that has be scratching my head. I’ve got the following configuration:

- id: outside_on_sunset
  alias: "Turn on the outside lights at sunset"
  trigger:
  - event: 'sunset'
    platform: sun
    offset: 0
  action:
    - service: switch.turn_on
      target:
        entity_id: switch.switch_2

- id: outside_off_sunrise
  alias: "Turn off the outside lights at sunrise"
  trigger:
  - event: 'sunrise'
    platform: sun
    offset: 0
  action:
    - service: switch.turn_off
      target:
        entity_id: switch.switch_2

It seems simple enough but when checking the configuration within the Automations menu, one of those two become inoperable and I’m seeing this warning:

Depending on the order I place the two automations, it’ll change which one shows that error - so, I’ve got a YAML problem, unless I’ve also got another problem (PEBCAK).

Anyone else have any input? I’m not sure why this is wrong.

TIA.

I think it might be a simple indentation problem. I’ve modified both of your automations to where they should work. Either variant should be ok, just keep your indentation consistent. Look for the minor changes I made and let us know if that was the problem.

- id: outside_on_sunset
  alias: "Turn on the outside lights at sunset"
  trigger:
    - event: 'sunset'
      platform: sun
      offset: 0
  action:
    - service: switch.turn_on
      target:
        entity_id: switch.switch_2

- id: outside_off_sunrise
  alias: "Turn off the outside lights at sunrise"
  trigger:
  - event: 'sunrise'
    platform: sun
    offset: 0
  action:
  - service: switch.turn_off
    target:
      entity_id: switch.switch_2

Don’t copy and paste this code! Fix the indentation on your code so that BOTH ‘event’ and ‘service’ blocks are on the same indentation. My example was to demonstrate that either version would work, and if copied and pasted verbatim should still produce the error. I prefer the minimally indented code myself just for the space savings it offers. also, I use Atom editor for Mac and it has some great tools for keeping your YAML in order, plus tools to indent/un-indent blocks of code.

1 Like

Thanks @kartcon - pesky indentations.