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

Hi,
I am trying to automate it so that when my homepod mini starts to play my radio alarm, my (tradfri) lights also switch on from 0% to 50% within 5 minutes. I got to below code, but I get the error Message malformed: extra keys not allowed @ data[‘automation’]:

automation:
  - alias: "Turn on bedroom light when HomePod mini plays"
    trigger:
      - platform: state
        entity_id: media_player.bedroom # your HomePod mini entity ID
        to: playing
    condition:
      - condition: time
        after: "06:00:00"
        before: "09:00:00"
    action:
      - service: light.turn_on
        target:
          entity_id: light.bedroom_light # your bedroom light entity ID
        data:
          brightness_pct: 50
          transition: 300 # 300 seconds = 5 minutes

How can I fix this?

Where did you put that YAML?

That’s an entire entry for configuration.yaml, though you’d have to change the first line to:

automation mine:

In the yaml editor of the automation which i started with the visual editor
This also did not work:

automation mine:
  - alias: "Turn on bedroom light when HomePod mini plays"
    trigger:
      - platform: state
        entity_id: media_player.bedroom # your HomePod mini entity ID
        to: playing
    condition:
      - condition: time
        after: "06:00:00"
        before: "09:00:00"
    action:
      - service: light.turn_on
        target:
          entity_id: light.bedroom_light # your bedroom light entity ID
        data:
          brightness_pct: 50
          transition: 300 # 300 seconds = 5 minutes

Are you saying what you posted above is exactly as it appears in the Automation Editor in YAML mode?

Because the Automation Editor doesn’t add the first line containing automation: nor does it display a hyphated alias:option.

Did you add that or is that example how it appears in the configuration.yaml file or perhaps the automations.yaml file?

This is in the yaml editor of the automation

You didn’t answer my question, so I will assume you added the things I mentioned in my previous post. Remove them from your automation.

For reference, here’s how a new automation looks like in the Automation Editor in YAML mode. Notice that it doesn’t include an automation: key, there’s no hyphenated alias key and all the keys description, mode, trigger, condition and action are not indented.

That’s why I have assumed you manually added the other things and suggested you remove them because it’s causing the error message you received.

The example you posted is how an automation would appear when viewed in configuration.yaml and not how it appears in the Automation Editor.

1 Like

Thanks! So I think I am a step further, but it gives me now the error: Message malformed: extra keys not allowed @ data[‘transition’] with the following code

alias: Wake up light
description: ""
trigger:
  platform: device
  device_id: 368401dc768f070cfcd0e808368fdffb
  domain: media_player
  entity_id: 1a3df2b89a2ca5b07e9129075ba8c17b
  type: playing
  for:
    hours: 0
    minutes: 0
    seconds: 5
condition: []
action:
  type: turn_on
  device_id: 352b8d5ebeb73f0fbc17912f20312e13
  entity_id: 8572addcd734216204d067b70fbb2714
  domain: light
  brightness_pct: 50
  transition: 300
mode: single

But when I remove the transition:300 line it is able to save it…How can I get the light to fade on over a period of 5 minutes now?

alias: Wake up light
description: ""
trigger:
  - platform: state
    entity_id: media_player.bedroom
    to: playing
    for:
      seconds: 5
condition: []
action:
  - service: light.turn_on
    target:
      entity_id: light.bedroom_light
    data:
      brightness_pct: 50
      transition: 300
mode: single
1 Like

That did the trick, thanks!

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.

I am sorry I have the same problem. I created an automation with the Automation Editor and then switched over to YAML mode. I want it to have several sub parts, so I wanted to add automation: and automation 2: but thats not accepted. Where do I edit this in a way thats allowed? thank you.

You’re trying to split an automation in two - don’t do that.

Create two automations.