How does YAML get OK from validation sites, yet throws these crazy errors

I am pretty new to HA and even with all the online resources with automations, getting error-free YAML is driving me crazy. I have asked chatgpt for help. Polite, but not helpful. I’m running code I found online that others claims works for them through YAML validation sites. They all seem to say it’s perfect. Yet I keep getting the common error:

Message malformed: extra keys not allowed @ data['0']

I don’t know where to turn other than here, hope someone can help. Trying to turn a light on when entering and off when no activity using a Neolink camera for motion sensing. I’ve set up a timer timer.office_off_timer using Helpers. I’ve checked all the indentations (as have the validation sites) and see nothing wrong.

- id: Turn On Office Light
  alias: Turn on office light when motion detected
  trigger:
  - platform: state
    entity_id: binary_sensor.birch_neolink_1_motion
    to: on
  action:
  - service: timer.start
    data:
    duration: "0"
    target:
      entity_id: timer.office_off_timer
  - service: switch.turn_on
    entity_id: light.jasco_products_43080_light
  mode: single
- id: Turn Off Office Light
  alias: Turn off office light 10 minutes after last movement
  trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.office_off_timer
  action:
  - service: switch.turn_off
    entity_id: light.jasco_products_43080_light  
  mode: single

Valid YAML is different from valid HA config

In your case, you didn’t indent duration:

    data:
    duration: "0"

is valid YAML, but not valid HA configuration

    data:
      duration: "0"

is valid YAML and valid HA configuration

Single automation to do the same job without messing around with timers.

- alias: Office light manager
  description: >
    Turns the light on with motion; off 10 mins after last motion.
  id: 3dcf5794-d9b4-4247-81cd-30813d035e05
  trigger:
    - platform: state
      entity_id: binary_sensor.birch_neolink_1_motion
      to: 'on'
    - platform: state
      entity_id: binary_sensor.birch_neolink_1_motion
      to: 'off'
      for:
        minutes: 10
  action:
    - service: homeassistant.turn_{{ states('binary_sensor.birch_neolink_1_motion') }}
      entity_id: light.jasco_products_43080_light

Not a good idea for code. Much better to refer to the generally-excellent documentation. In this particular case:

Thank you so much for taking the time to look at this. I will report back. I will also read about service calls.

Still threw the same error. See changed code below:

- id: Turn On Office Light
  alias: Turn on office light when motion detected
  trigger:
  - platform: state
    entity_id: binary_sensor.birch_neolink_1_motion
    to: on
  action:
  - service: timer.start
    data:
      duration: "0"
    target:
      entity_id: timer.office_off_timer
  - service: switch.turn_on
    entity_id: light.jasco_products_43080_light
  mode: single
- id: Turn Off Office Light
  alias: Turn off office light 10 minutes after last movement
  trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.office_off_timer
  action:
  - service: switch.turn_off
    entity_id: light.jasco_products_43080_light  
  mode: single

I just re-read this thread, and your comment about SINGLE AUTOMATION. I’m feeling stupid now. Is my code supposed to be split up into two different automations? Is that why I’m having this issue?

It depends how you’re inputting that code. If you’ve pasted that all in to an automation’s Edit In YAML box, yes, probably.

Also, where are you imagining that the 10 minutes is specified?

Where are you getting that ID from:

3dcf5794-d9b4-4247-81cd-30813d035e05

You can make it up, that’s a GUID, something you can generate with a command line tool or on many websites, but it just has to be unique.

The 10 minutes is in my timer I created. Picture attached

So why are you specifying a zero duration in the service call? Try my single automation that does without timers. They’re an unnecessary complication here.

I use https://www.uuidgenerator.net/ to generate unique IDs. Saves me having to make them up.

So do I just paste your automation into a new YAML screen and save?

You could even create it with the UI, although you’ll need to paste in the action section. I’ve had to use one of my motion sensors for this screenshot:

I used your exact automation, generated my unique UUID string, below. Gave the same error message. Here’s what I entered into automations using YAML. Every single automation given to me with claims that it works throws the same error;
Message malformed: extra keys not allowed @ data['0']

- alias: Office light manager
  description: >
    Turns the light on with motion; off 10 mins after last motion.
  id: d55c5ccb-53a2-495f-a816-324974d8c931
  trigger:
    - platform: state
      entity_id: binary_sensor.birch_neolink_1_motion
      to: 'on'
    - platform: state
      entity_id: binary_sensor.birch_neolink_1_motion
      to: 'off'
      for:
        minutes: 10
  action:
    - service: homeassistant.turn_{{ states('binary_sensor.birch_neolink_1_motion') }}
      entity_id: light.jasco_products_43080_light

Because the UI editor expects different indentation without the initial - and first two spaces. Just create it in the UI as per my screenshot above.

Automations are not “given to you”, they’re provided as a starting point. Copy-paste without understanding what’s going on is somewhere between dangerous and useless.

Well, of course I modify with my own entities, devices etc.

I see. So you can’t take an automation, modified with the proper entities etc., and paste it into YAML for a new automation. Is that correct?

You can, as long as you format it correctly.

Thanks so much. I did it your way, using the visual editor, and then editing the YAML. Test it now. At least no errors for the first time. I learned a lot.

1 Like