Put pause in between command in scripts

So I have the following in my script.

abc:
  alias: 'ABC HD'
  sequence:
    - service: remote.send_command
      data:
        entity_id: remote.familyroom_hub
        device: 'Microsoft Xbox 360'
        delay_secs: 0.1
        command:
          - LiveTv
          - 1
          - 8
          - 7

Problem is I want to give my computer time to switch to live tv before entering the channels. So I don’t want to delay each individual item, but just basically like:

abc:
  alias: 'ABC HD'
  sequence:
    - service: remote.send_command
      data:
        entity_id: remote.familyroom_hub
        device: 'Microsoft Xbox 360'
        delay_secs: 0.1
        command:
          - LiveTv
          - **PAUSE 10 SECONDS**
          - 1
          - 8
          - 7

is this possible?

Thanks.

JR

The first example on https://www.home-assistant.io/integrations/script/ demonstrates the delay command, which does exactly what you want.

Brilliant, thank you so much. About to test it if I can get the family to free up the TV, however hope I can just do the:

      - delay:
          # supports seconds, milliseconds, minutes, hours
          minutes: {{ minutes }}

part but replace it with:

      - delay:
          # supports seconds, milliseconds, minutes, hours
          minutes: 2

Rather than having to set the variable and value and then use the variable down below like the example says:

**delay'**
**    fields:**
**      minutes:**
**        description: 'The amount of time to wait before turning on the living room lights'**
**        example: 1**
    sequence:
      # This is Home Assistant Script Syntax
      - event: LOGBOOK_ENTRY
        event_data:
          name: Paulus
          message: is waking up
          entity_id: device_tracker.paulus
          domain: light
      - alias: Bedroom lights on
        service: light.turn_on
        data:
          entity_id: group.bedroom
          brightness: 100
      **- delay:**
**          # supports seconds, milliseconds, minutes, hours**
**          minutes: {{ minutes }}**

Now nothing in that page you pointed to mentions commands specifically so maybe not compatible within a command list?

Absolutely. I use delay in a handful of automations,always with a hardcoded interval.

Thanks, have to see what is causing this error in the below.

Error

Error executing service <ServiceCall script.abc (c:9252ce047002457aa8bfd1c7afed1438)>

7:06:33 PM – core.py (ERROR)

Error executing script script.abc. Invalid data for call_service at pos 1: value should be a string @ data['command'][1]

7:06:33 PM – Script (ERROR)

Code:

abc:
  alias: 'ABC HD'
  sequence:
    - service: remote.send_command
      data:
        entity_id: remote.familyroom_hub
        device: 'Microsoft Xbox 360'
        delay_secs: 0.1
        command:
          - LiveTv
          - delay:
              seconds: 15
          - 1
          - 8
          - 7

Note I’m trying LiveTV with quotes but never had to do that for any other word based commands so assuming that won’t help…

Oh, sorry, I misread. You’re right, you can’t put a delay as one of the commands for remote.send_command. But you should be able to make it work with multiple service calls. I think you want something like this:

sequence:
  - service: remote.send_command
    data:
      entity_id: remote.familyroom_hub
      device: 'Microsoft Xbox 360'
      delay_secs: 0.1
      command:
        - LiveTv
  - delay:
      minutes: 2
  - service: remote.send_command
    data:
      entity_id: remote.familyroom_hub
      device: 'Microsoft Xbox 360'
      delay_secs: 0.1
      command:
        - 1
        - 8
        - 7

I just thought of a flaw in my original logic. I really only want the delay to happen when I’m either watching my media on Emby or Plex or doing anything else other than watching LiveTv. So if I’m already watching TV then don’t want the delay, but if I have to switch into it then would want it. But looking at what’s available within HA for the Harmony, I do not think there is a way to see what command was sent like this as it’s not an Activity and even an Activity I’m not sure I can tell what Activity I’m currently in thru HA.

I’m not at all familiar with the Harmony platform, but reading through the docs for it at https://www.home-assistant.io/integrations/harmony/ suggests that your remote.familyroom_hub entity might have a current_activity attribute that you can check to see what it’s doing? It might be as simple as using a template to check if current_activity is “LiveTv”. I can’t test it, but maybe something like

# Delay 1 second if LiveTV is active, 120 seconds otherwise. Maybe.
- delay:
    seconds: >
      {% if state_attr("remote.familyroom_hub", "current_activity") == "LiveTv") %}
      1
      {% else %}
      120
      {% endif %}

Yeah I do use that for other things. Only problem with that is it only knows what “Activity” you are in. For me that is basically:

  1. Run the XBox
  2. Play some music

The problem with that is the Activity is Run the XBox, not LiveTv. It launches the XBox and then I can navigate to LiveTV or play movies on Emby or use the local Recorded TV but those are buttons on Emby I can click to get to different things but not an Activity in the Harmony sense.

Now if there was a way to get from the XBox if it’s in those states then maybe but I can’t even ping this thing to see if it’s up let alone that.