Multiple delays in script / Delay seems to stop script execution

I am testing a script that performs multiple actions with a few delays. In my scripts.yaml I have this:

tv_on:
  alias: 'TV On'
  sequence:
    - service: switch.turn_on
      data:
        entity_id: switch.tv_ir
    - delay: '00:00:05'
    - service: switch.turn_on
      data:
        entity_id: switch.speaker
    - service: shell_command.luther_sound_bluetooth
    - delay: '00:00:03'
    - service: broadlink.send_packet_192_168_11_39
      data:
        packet:
          - JgBQAAABJ5USExITETgSExITEhMSExISEzcSNBY3EzcSExISExITEhITEhMSNxMSEhMSExI3ExITNxI3ExITNxI3EzcSExI3EwAFlQABKUkTAA0FAAAAAAAAAAA=
    - service: shell_command.luther_sound_vol_reset

and

tv_off:
  alias: 'TV Off'
  sequence:
    - service: switch.turn_off
      data:
        entity_id: switch.tv_ir
    - delay: '00:00:15'
    - service: switch.turn_off
      data:
        entity_id: switch.speaker

When running the TV on script it seems to go wrong after the first delay. The switch.turn_on command is fired (another automation gets triggered) but the UI / state for switch.speaker remains off. The other call to send a IR packet doesn’t seem to get run either.

When turning the TV off it also seems to fail after the first delay.

The switch looks like this:

- platform: mqtt
  name: "Speaker"
  state_topic: "sycamore/tvspeaker/switch"
  command_topic: "sycamore/tvspeaker/switch"
  payload_on: "on"
  payload_off: "off"
  retain: true

and when it changes state from on/off some simple automations run.

Are there any known issues with delay? or obvious syntax issues with the above?

Thanks

I would remove the data:'s as they are not needed except for the broadlink command and the packet data needs to be enclosed in single quotes. I think data: is only needed for strings and when there are multiple attributes to send such as light rgb/brightness etc.

1 Like

I think delay is also the one place in HA where you don’t put quotes around the time unless it’s a template.

1 Like

Thanks for the tips @keithh666 and @anon43302295. I tested all those variations and they all seem valid.

I tracked my issue down a bug in my config… it was the way in which TV Off and On were being called (via an automation). I had a few mistakes there.