Learning automations... why is this broken?

OK, so… I am just starting out with HA. I did program things years and years (and years) ago, have learned custom integrations in the past (RTI, AMX, Creston), and also well-versed in the industrial side (Rockwell/Ladder Logic stuff). However, I’m scratching my head with yaml. I have successfully added all my devices in (localtuya), done a crapload of simple automations (tied to single or multi-location switches), and done a few more “complex” automations that involve calling scripts. But, I’m having issues with a simple one to brighten up the front door during a doorbell press.

Here is what I have. The last bit is breaking it. It’s looking for expected dictionary @ data[‘action’][1]. Got none

But, I have used this in the past in other spots and it seems to work out fine. Why is it broken here? I thought I had the whole list vs dictionary thing down pat, but…

  1. Any clue on how to fix?
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- id: 'FrontDoorRing'
  alias: Front Door Ring
  trigger:
  - platform: state
    entity_id: binary_sensor.front_door_ding
    to: 'on'
  action:
  - service: scene.create
    data:
      scene_id: pre_fd_ring
      snapshot_entities: 
      - light.front_door_l
      - light.front_door_r
  - delay 00:00:01
  - service: light.turn_on
    entity_id: light.front_door_l
    data:
      brightness_pct: 100
#  - service: light.turn_on
#    entity_id: light.front_door_r
#    data:
#      brightness_pct: 100
#      transition: 0
#  mode: single

I’m not sure if this is the cause of your woes, but I’m pretty sure you need single quotes around your delay time:

- delay '00:00:01'

Don’t beat yourself up, it’s just a typo. You forgot the colon after the word delay

  - delay 00:00:01
         ^

Wrapping the time in quotes is optional.

BTW, this @ data[‘action’][1] means the second item in the action (it indicates 1 but it’s indexed from zero). The second item in the action is the delay.

The second service call is incorrectly ordered. When a service call requires / has a ‘data’ section in it then the entity_id needs to be under the ‘data’ heading with the rest of the service call data. (I think… maybe it works both ways)

#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- id: 'FrontDoorRing'
  alias: Front Door Ring
  trigger:
  - platform: state
    entity_id: binary_sensor.front_door_ding
    to: 'on'
  action:
  - service: scene.create
    data:
      scene_id: pre_fd_ring
      snapshot_entities: 
      - light.front_door_l
      - light.front_door_r
  - delay: '00:00:01'
  - service: light.turn_on
    data:
      entity_id: light.front_door_l
      brightness_pct: 100
#  - service: light.turn_on
#    data:
#      entity_id: light.front_door_r
#      brightness_pct: 100
#      transition: 0
#  mode: single

Much thanks. I thought I had the basics down, figured it was a simple thing staring me at the face.

Also, thanks for the explanation of the data[‘action’][1]. That is probably more help than the actual fixing of this issue. (Teach a man to fish, yadda yadda). I just wish it would direct you to the automation that was causing the error as well…

1 Like

Can confirm, it does work both ways.

1 Like

I think it does because I vaguely recall having it outside data when I used brightness and it worked. I say ‘vaguely’ because I normally move it into data for neatness. :slightly_smiling_face:

It’s pretty inconsistent across different services. Some require the entity_id in, some out. There has been an issue open about it for ages.

1 Like