cancel
Showing results for 
Search instead for 
Did you mean: 

Automation script error adding time delay

Trig007
Community Member

Hi All

 

hoping that someone can help, tying to set up a simple automation in the script edito (new at this so be gentle) to turn on a light when the front door is opened after sunset & then automatically turn it off again after a set time, but keep getting either a 'the current structure has duplicate fields (type) or indentation error & its driving me nuts this is the structure (have copied the actions from the help pages example & getting the error) hoping someone can put me straight, any help would be massively appreciated, have pasted script below

thanks in advance

metadata:
name: Hall Light Automation # Choose a short name that summarizes important starters and actions, like “Sunset lights”.
description: After sunset if Front door is opened, turn on hall light # Write a detailed description that includes everything the automation does, like “At sunset, on weekdays, close blinds, turn on lights to 50%, and play the sunset playlist on certain speakers.”


starters:
 - type: device.state.OpenClose
    state:
openPercent
    is: 100
    device: Front Door - Hall

condition:
    type: time.between
    before: sunrise+10min 
    after: sunset+10min
   weekdays:
      - MON
      - TUE
      - WED
      - THU
      - FRI
      - SAT
      - SUN

actions:
      type: device.command.OnOff
         devices: Hall Light - Hall
         on: true
         type: time.delay
         for: 30sec
      type: device.command.OnOff
         devices: Hall Light - Hall
         on: false

5 REPLIES 5

dionney
Community Member

The following instruction do not seem to be on the same indentation as of the other "type:" instruction

         type: time.delay
         for: 30sec

In the actions section, have the "type:" instructions on the same indentation:
actions:
      type: device.command.OnOff
         devices: Hall Light - Hall
         on: true
      type: time.delay
         for: 30sec
      type: device.command.OnOff
         devices: Hall Light - Hall
         on: false

Trig007
Community Member

Thanks for speady response dionney, have made that adjustment but still getting this: 

Screenshot_20231230_144749.jpg

any thoughts?

dionney
Community Member

Instead of "type", use "- type".

I have the same error when I modify one of my scripts from dash type to a simple type.

salbando
Community Member

My understanding is if you have multiple items of the same kind, you need to use a dash. So for your example, put a dash in front of each word "type" (i.e. -type) The parameters underneath need to be aligned with the t of type (not the dash). So the d of device will be aligned with the t of type. If you have done any programming before, it may help to know that you are essentially defining an array of the key called "actions" and each "type" is the next element in that array. Dashes are the way we tell YAML that these are elements in that array... I think.

Trig007
Community Member

Thanks guys, all sorted