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
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:
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?
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.
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.
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.