YAML: did not find expected key while parsing a block mapping

I swear I can’t figure out where my configuration is going wrong here. Below is my YAML.

  christmas_holiday:
    sequence:
      - condition: or
        conditions:
          - condition: template
            value_template: "{{ now().strftime('%F') >= (now().strftime('%Y') | int ) ~ "-11-20" }}"
          - condition: template
            value_template: "{{ now().strftime('%F') <= (now().strftime('%Y') | int ) ~ "-01-07" }}"
      - service: homeassistant.turn_on
        entity_id:
          - switch.sonoff_outdoor1
          - input_boolean.christmas_outdoor_switch

  halloween_holiday:
    sequence:
      - condition: template
        value_template: { now().strftime('%F') >= (now().strftime('%Y') | int ) ~ "-10-24" and now().strftime('%F') <= (now().strftime('%Y') | int ) ~ "-10-31" }
      - service: homeassistant.turn_on
        entity_id:
          - switch.sonoff_outdoor1
          - input_boolean.halloween_outdoor_switch

In it’s current state, it prevents home assistant from restarting with the following error in YAMLlint.
did not find expected key while parsing a block mapping at line 5 column 13

I have a feeling, this is a YAML indenting issue but I simply can’t get it. Anyone able to help me figure this out or see any other issues? Thanks.

1 Like

What is ‘sequence’?

What is line 5 (config.yaml, not your automation)? What is before that? What is after that?

They’re scripts not automations. At least I hope they are…

Yes, this a script not an automation.
I have gotten conditions to work in scripts before, but I’m having trouble with this one. Most likely because of the OR condition.

I have my scripts separated into different YAML files in a ‘scripts’ folder. Home Assistant refuses to restart and the error log specifically calls out this file.

while parsing a block mapping
  in "/config/scripts/outdoor_holiday_lights_scripts.yaml", line 5, column 13
expected <block end>, but found '<scalar>'
  in "/config/scripts/outdoor_holiday_lights_scripts.yaml", line 6, column 90

Any other info I can provide? I’m still pretty new to posting for help here.

Yep. As @flamingm0e said, what are those line and column pointers in the errors actually pointing to?

Line 5 would be pointing to the line with the first - condition: template

Line 6 is pointing to the value_template: underneath.
The problem is on these lines I think, but I don’t know what’s wrong.

I am not sure how to get the column numbers. Does YAMLlint do that?

Some text editors (notepad++, VScode & others) will tell you what column your cursor is positioned at in a status bar (usually at the bottom of the window).

I think column 90 is “~” I have no idea what that does.

You have double quotes inside your templates (towards the end) , change them to single quotes.

The template in halloween does not have double quotes on the outside, it needs them.

Job done.

2 Likes

Thank you so much. I knew it had to be some missing syntax thing.

1 Like