How to repeat inside a script sequence?

Hey there,
I have several basic scripts for my TV automations. I wonder how I can repeat commands to let it look more clean in my scripts.yaml?

tv_volume_on:
sequence:
- service: remote.send_command
  entity_id: remote.harmony_hub
  data:
    device: "50346430"
    command: "VolumeUp"
- service: remote.send_command
  entity_id: remote.harmony_hub
  data:
    device: "50346430"
    command: "VolumeUp"

Just want to repeat “VolumeUp” a few times.

Probably better to get the current volume level, and add a set number to it as an automation:

- alias: increase volume
  trigger:
    platform: blah blah
    action:
  service: media_player.volume_set
    data_template:
      entity_id: media_player.yamaha_receiver
      volume_level: >
        {% if is_state('media_player.yamaha_receiver', 'on')  %}
          {% set n = states.media_player.yamaha_receiver.attributes.volume_level | float %}
          {% if n <= 0.85 %}
            {{ n + 0.05 | round(2) }}
          {% endif %}
        {% endif %}

This of course can only be done if you connect to your media device. Harmony does not have a VolumeSet function.

Your other option is to create a script of ‘5 volume ups’ and call that script when you want to increase by 5 or something.

Harmony is limited with its commands because it emulates the remote.

The remote.send_command service has a num_repeats argument that should do what you want.

2 Likes