Template syntax help - extra keys not allowed @data['script']

Hi, I have been struggling with this one for a while and I can’t see what my error is:

This script raises the extra keys not allowed @data[‘script’] error

script:
  notify_lawn_status:
    alias: Notify Lawn Status
    sequence:
      - service: notify.notify
        data:
          message: >
            {% if states('input_boolean.mow_lawn') == "on" %}
              It's time to mow the lawn! No rain in the last 6 hours.
              Last rain reported at {{ states('input_datetime.time_of_last_reported_rainfall') }}
            {% else %}
              Hold off on mowing. Rain reported within the last 6 hours.
              Last rain reported at {{ states('input_datetime.time_of_last_reported_rainfall') }}
            {% endif %}

So does the one below - but below is the example from Templating - Home Assistant. This is in the script editor in YAML mode.

script:
  msg_who_is_home:
    sequence:
      - service: notify.notify
        data:
          message: >
            {% if is_state('device_tracker.paulus', 'home') %}
              Ha, Paulus is home!
            {% else %}
              Paulus is at {{ states('device_tracker.paulus') }}.
            {% endif %}

It’s going to be something dumb but I just can’t see it. The input.datetime and input_boolean devices do exist in my setup.

Thanks in advance for help!

I think you have a script tag within a script tag. The one we’re seeing here is probably redundant. What is around this? In which file is this defined?

1 Like

Remove the first line script:

It already exists in your configuration.yaml file when you have

script: !include scripts.yaml

Currently your include would resolve to:

script:
  script: 
    msg_who_is_home:
      sequence: etc...

instead of:

script:
  msg_who_is_home:
    sequence: etc...

Thanks!! Incredibly fast answer. Below is the winning version. I also had to add alias: and remove the :

alias: notify_lawn_status
sequence:
  - service: notify.notify
    data:
      message: >
        {% if states('input_boolean.mow_lawn') == "on" %}
          It's time to mow the lawn! No rain in the last 6 hours.
          Last rain reported at {{ states('input_datetime.time_of_last_reported_rainfall') }}
        {% else %}
          Hold off on mowing. Rain reported within the last 6 hours.
          Last rain reported at {{ states('input_datetime.time_of_last_reported_rainfall') }}
        {% endif %}