Newbe Question- Asking for experienced help

Hi everyone. Im new to Home Assistant and im trying to write a YAML file to control my exterior lights. I want them turning on at sunset and running until 1:00 am and then I want my ring doorbell motion sensor to trun them on if any motion is detected.

Im part of the way there but im stuck with a Message malformed: extra keys not allowed @ data[‘action’][1][‘at’].

I was hoping that someone would be able to give me some pointers in my YAML below. Thankls

alias: Control Exterior Lights
description: ''
mode: single
trigger:
  - platform: sun
    event: sunset
condition: []
action:
  - type: turn_on
    device_id: 6185f72e84c34c64db08137baxxxxxxxx
    entity_id: switch.0003804224a160xxxxxxxx
    domain: switch
  - condition: time
    after: '01:00'
  - type: turn_off
    device_id: 6185f72e84c34c64db08137baxxxxxxxx
    entity_id: switch.0003804224a160xxxxxxxx
    domain: switch
trigger:
  - type: motion
    platform: device
    device_id: 87dcb00edf5fd7ce0632cf1f1xxxxxxxx
    entity_id: binary_sensor.ring_doorbell_front_door_motion
    domain: binary_sensor
action:
  - type: turn_on
    device_id: 6185f72e84c34c64db08137baxxxxxxxx
    entity_id: switch.0003804224a160xxxxxxxx
    domain: switch
  - delay: '00:05:00'
  - type: turn_off
    device_id: 6185f72e84c34c64db08137baxxxxxxxx
    entity_id: switch.0003804224a160xxxxxxxx
    domain: switch
  trigger:
    platform: sun
    event: sunrise
    offset: "-00:20:00"
    action:
 - type: turn_off
   device_id: 6185f72e84c34c64db08137baxxxxxxxx
   entity_id: switch.0003804224a160xxxxxxxx
   domain: switch
mode: single

Your automation is incorrect. It has multiple trigger and action sections. There can only be one of each in an automation.


On a separate note, you categorized your topic as Blueprints Exchange. That’s reserved for sharing blueprints with the community and not for general questions about fixing automations. You may wish to consider changing the category to Configuration.

Thank you for the information and for your reply. Its seems that the YAML route is not as flexible as I had hoped. Ill start investigating the use of Python to accomplish my automation in one script.

You should at least try to read up in the documentation of HA… :wink:

YAML is very flexible, or better YAML for automations is. But if you don’t understand the concept behind it, I’m tempted to assume you wont get far with python either. :wink:

It’s literally the first pragraph in the docs… Understanding Automations - Home Assistant

Hint: you can have multiple triggers, conditions and actions…

Respectfully, it’s your inexperience with it that has led you to create a structurally flawed automation and to wrongly conclude it’s inflexible.

If you tell us what you are trying to do we can help you achieve it.

Thanks Taras and Patrick, I come from a C++, C#, VB and Python background so I’m trying to wrap my head around the workflows and the constraints of the YAML file’s in HASS. Ill dig into the documentation and will come back with any questions.

For future reference, an automation has:

  • One mandatory trigger section that can contain multiple triggers (of all kinds such as State Trigger, Numeric State Trigger, Time Trigger, etc).
  • One optional condition section that can contain multiple conditions (of all kinds such as State Condition, Numeric State Condition, Time Condition, etc).
  • One mandatory action section that can contain service calls and execution-control statements like choose, repeat, condition, wait_template, delay, wait_for_trigger, etc.

Sometimes the best way to pick up a new language (or whatever YAML is) is to see working examples.

A good way in HA to get examples is to use the GUI to build an automation. Even if it doesn’t do everything you want, you can see the YAML that the GUI created and tweak from there.

2 Likes