Can't understand error in automations.yaml

I am getting this error in my automations.yaml from HA when I start the server:

ERROR:homeassistant.util.yaml:expected '<document start>', but found '<block sequence start>'
  in "/config/automations.yaml", line 244, column 1
Failed config
  General Errors: 
    - expected '<document start>', but found '<block sequence start>'
  in "/config/automations.yaml", line 244, column 1

…but I can’t understand what the problem is. If I check the syntax by copying and pasting it into the YAML syntax checker at www.yamllint.com it reports no errors. Can anyone tell me what’s wrong with the file?

Line 244 is the one which contains:
- alias: Microwave On In Evening

Here’s the full file:

# LMS GUI Volume control
  - alias: "LMS GUI Volume Control"
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_number.lms_volume
    action:
    - service:  media_player.squeezebox_call_method
      data_template:
        entity_id: "media_player.{{states.input_select.lms_player.state}}"
        command: "mixer"
        parameters: ["volume", "{{states.input_number.lms_volume.state}}"]


# LMS GUI Sleep Time control
  - alias: "LMS GUI Sleep Timer Control"
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_number.lms_sleep_time
    action:
    - service:  media_player.squeezebox_call_method
      data_template:
        entity_id: "media_player.{{states.input_select.lms_player.state}}"
        command: "sleep"
        parameters: ["{{states.input_number.lms_sleep_time.state|int * 60}}"]


# LMS GUI Shuffle On / Off
  - alias: "LMS GUI Shuffle Control"
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_boolean.lms_shuffle
    action:
    - service:  media_player.shuffle_set
      data_template:
        entity_id: "media_player.{{states.input_select.lms_player.state}}"
        shuffle: >
            {% if (states.input_boolean.lms_shuffle.state == "on") %} true
            {% else %} false {% endif %}


# LMS GUI Repeat On / Off
  - alias: "LMS GUI Repeat Control"
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_boolean.lms_repeat
    action:
    - service: input_text.set_value
      data_template:
        entity_id: input_text.lms_p1
        value:  >
            {% if (states.input_boolean.lms_repeat.state == "on") %} 2
            {% else %} 0 {% endif %}
    - service:  media_player.squeezebox_call_method
      data_template:
        entity_id: "media_player.{{states.input_select.lms_player.state}}"
        command: "playlist"
        parameters: ["repeat", "{{states.input_text.lms_p1.state}}"]


# LMS GUI Command for play playlist
  - alias: "LMS GUI Play Playlist Command"
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_select.lms_command
      to: "play playlist"
    action:
    - service: script.turn_on
      data_template:
        entity_id: >-
            {% if (states.input_select.lms_source.state == "lms") %}
                script.lms_cmd_play_playlist
            {% else %}
                script.lms_cmd_play_playlist_spot
            {% endif %}          


# LMS GUI Command for add playlist
  - alias: "LMS GUI Add Playlist Command"
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_select.lms_command
      to: "add playlist"
    action:
    - service: script.turn_on
      data_template:
        entity_id: >-
            {% if (states.input_select.lms_source.state == "lms") %}
                script.lms_cmd_add_playlist
            {% else %}
                script.lms_cmd_add_playlist_spot
            {% endif %}          

      
# LMS GUI Command for play artist
  - alias: "LMS GUI Play Artist Command"
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_select.lms_command
      to: "play artist"
    action:
    - service: script.turn_on
      data_template:
        entity_id: >-
            {% if (states.input_select.lms_source.state == "lms") %}
                script.lms_cmd_play_artist
            {% else %}
                script.lms_cmd_play_artist_spot
            {% endif %}          


# LMS GUI Command for add artist
  - alias: "LMS GUI Add Artist Command"
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_select.lms_command
      to: "add artist"
    action:
    - service: script.turn_on
      data_template:
        entity_id: >-
            {% if (states.input_select.lms_source.state == "lms") %}
                script.lms_cmd_add_artist
            {% else %}
                script.lms_cmd_add_artist_spot
            {% endif %}          


# LMS GUI Command for play album
  - alias: "LMS GUI Play Album Command"
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_select.lms_command
      to: "play album"
    action:
    - service: script.turn_on
      data_template:
        entity_id: >-
            {% if (states.input_select.lms_source.state == "lms") %}
                script.lms_cmd_play_album
            {% else %}
                script.lms_cmd_play_album_spot
            {% endif %}          


# LMS GUI Command for add album
  - alias: "LMS GUI Add Album Command"
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_select.lms_command
      to: "add album"
    action:
    - service: script.turn_on
      data_template:
        entity_id: >-
            {% if (states.input_select.lms_source.state == "lms") %}
                script.lms_cmd_add_album
            {% else %}
                script.lms_cmd_add_album_spot
            {% endif %}          


# LMS GUI Command for play song
  - alias: "LMS GUI Play Song Command"
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_select.lms_command
      to: "play song"
    action:
    - service: script.turn_on
      data_template:
        entity_id: >-
            {% if (states.input_select.lms_source.state == "lms") %}
                script.lms_cmd_play_song
            {% else %}
                script.lms_cmd_play_song_spot
            {% endif %}          


# LMS GUI Command for add song
  - alias: "LMS GUI Add Song Command"
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_select.lms_command
      to: "add song"
    action:
    - service: script.turn_on
      data_template:
        entity_id: >-
            {% if (states.input_select.lms_source.state == "lms") %}
                script.lms_cmd_add_song
            {% else %}
                script.lms_cmd_add_song_spot
            {% endif %}          


# LMS GUI Command for next track
  - alias: "LMS GUI Next Track Command"
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_select.lms_command
      to: "next track"
    action:
    - service: script.turn_on
      data_template:
        entity_id: script.lms_cmd_next_track

# LMS GUI Command for pause player
  - alias: "LMS GUI Pause Player Command"
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_select.lms_command
      to: "player pause"
    action:
    - service: script.turn_on
      data_template:
        entity_id: script.lms_cmd_pause_player
        
# LMS GUI Command for re-start of player
  - alias: "LMS GUI Player Re-start Command"
    initial_state: true
    trigger:
    - platform: state
      entity_id: input_select.lms_command
      to: "player restart"
    action:
    - service: script.turn_on
      data_template:
        entity_id: script.lms_cmd_start_player

  - alias: Microwave On In Evening
    trigger:
      platform: time
      at: '18:00:00'
    action:
      - service: switch.turn_on
        entity_id: switch.microwave
    id: '1519915869971'

  - alias: Microwave Off at Night
    trigger:
      platform: time
      at: '18:00:00'
    action:
      - service: switch.turn_off
        entity_id: switch.microwave
    id: '1519915933353'

  - alias: Subwoofer Off at Night
    trigger:
      platform: time
      at: '02:00:00'
    action:
      - service: switch.turn_off
        entity_id: switch.subwoofer
    id: '1519916269791'

  - alias: Subwoofer On in Morning
    trigger:
      platform: time
      at: '09:00:00'
    action:
      - service: switch.turn_on
        entity_id: switch.subwoofer
    id: '1519916312961'
  
  - alias: First Person Home
    trigger:
      platform: state
      entity_id: input_boolean.someone_home
      from: 'off'
      from: 'on'
    action:
      - service: ifttt.trigger
        data: {"event":"iSmartAlarmOff"}
      - service: switch.turn_off
        entity_id: switch.bi_cameras

  - alias: Last Person Leaves
    trigger:
      platform: state
      entity_id: input_boolean.someone_home
      from: 'on'
      from: 'off'
    action:
      - service: ifttt.trigger
        data: {"event":"iSmartAlarmOn"}
      - service: switch.turn_on
        entity_id: switch.bi_cameras

  - alias: Gill Leaves Home (Asus wifi)
    trigger:
      platform: state
      entity_id: device_tracker.android64082b6e603d76d9
      from: 'home'
      from: 'not_home'
    condition:
      - condition: state
        entity_id: device_tracker.android28005555987cbc20
        state: 'not_home'
    action:
      - service: input_boolean.turn_off
        data: {"entity_id":"input_boolean.someone_home"}

I think it’s throwing an error on your - alias: not being in single or double quotes. all of your other automations above have single or double quotes around the alias name except that one and down. also I don’t think you need a data_template: for your actions that turn on a script. Though that shouldn’t be contributing to the error you’re getting.

When looking through your file I noticed a few things. That may cause a problem. My first thoughts was your ids are at the bottom of your automations with my automations anyway I generally put my ids above my alias like the example below:

- id: media_paused_stop
  alias: Media player paused/stopped

But I am not sure if this might be contributing to your error.

1 Like

Is it not cause both
“Microwave On In Evening”
and
“Microwave Off at Night”
both trigger at 18:00:00 ?
so they would fight each other ?
do you use initial_state to make them disabled, and then enable them one at a time ?

You don’t have to have quotes around your alias names. I have it both ways in mine and it’s working.

It doesn’t really matter the order in which all of the entries are made in the automation as long as the sections are all there and indentation is correct. Look at the results of the automation editor output and you’ll see what I mean.

HA won’t error out on start up for a logic error. you could have two automations that do opposite things at the same time and it’s not going to give you a syntax error.

@itm1960 I just pasted your code section from the automation directly above your first microwave automation (starting at # LMS GUI Command for re-start of player) and adding both microwave automations and (after I removed white spaces to match my formatting) I don’t get any errors when I restart HA with that code inserted.

What I recommend is to go thru your code in that section line by line and make sure there isn’t any stray whitespacing issues (extra spaces, tabs, etc). I’ve had that happen to me before and I just started deleting all white spaces and re-entering them and it fixed the problem. I would concentrate on the transition above the line 244. It may be seeing something there and flagging 244 as the problem but it’s really on 243.

It’s worth a shot…

and here is the code of yours that I posted in mine that works:

# LMS GUI Command for re-start of player
- alias: "LMS GUI Player Re-start Command"
  initial_state: true
  trigger:
  - platform: state
    entity_id: input_select.lms_command
    to: "player restart"
  action:
  - service: script.turn_on
    data_template:
      entity_id: script.lms_cmd_start_player

- alias: Microwave On In Evening
  trigger:
    platform: time
    at: '18:00:00'
  action:
    - service: switch.turn_on
      entity_id: switch.microwave
  id: '1519915869971'
  
- alias: Microwave Off at Night
  trigger:
    platform: time
    at: '18:00:00'
  action:
    - service: switch.turn_off
      entity_id: switch.microwave
  id: '1519915933353'

Thanks for correcting me on that, i though it might if you had them both enabled on startup, but obviously not.

Hmmm…so adding double-quotes to my alias names seemed to fix it. Strange, as I thought that quotes were optional in alias names. Maybe just a quirk in the HA compiler?

I’m not sure that was the real issue

Like I said I have the alias named both ways and mine doesn’t complain. And i posted the exact same code as above into my config and it didn’t complain about that either.

If it was the missing quotes then it shouldn’t have worked in my setup either.

But I’m glad it worked. It would just be nice to know why it worked.