#Trying to use repeat to create a repeatable section of yaml. Not actions.

1 messages · Page 1 of 1 (latest)

whole kraken
#

I'm attempting to build a list for a repeatable section of yaml and I thought I could use repeat, but it seems it's only valid for actions.
how can I correct this to run the right way? the item under the regions variable should repeat for each room selected from the rooms field
I currently get that repeat is undefined.

sequence:
  - action: vacuum.send_command
    metadata: {}
    data:
      command: start
      params:
        pmap_id: VUFWNCMZQJ6MePE3X-_L3g
        user_pmapv_id: 240903T144808
        regions:
          - repeat:
              for_each: "{{ rooms.options }}"
              sequence:
                - region_id: "{{ repeat.item.value }}"
                  type: rid
    target:
      entity_id: vacuum.robert
fields:
  rooms:
    selector:
      select:
        multiple: true
        custom_value: false
        options:
          - label: Bedroom
            value: "1"
          - label: Living Room
            value: "2"
          - label: Dining Room
            value: "3"
          - label: Bathroom
            value: "4"
          - label: Kitchen
            value: "5"
    default:
      - 1
      - 2
      - 3
      - 4
      - 5
    name: Rooms
    required: true
alias: Robert Clean Room
description: ""
raven musk
#

You can't do that. You would need to use a template to output a list

exotic wedge
# whole kraken I'm attempting to build a list for a repeatable section of yaml and I thought I ...

Like Rob alluded to, the Repeat actions can only be used to repeat other actions in their entirety, they do not work to repeat internal portions of action configuration. In this case you actually do not want to use the Repeat, because it would just send the commands one after the other in quick succession and only one of them would be done.

Instead, you can use templates to build the mapping value for regions, but you also need to template the value for params for it to work.

sequence:
- variables:
    regions: |
      {% set ns = namespace(r=[]) %}
      {% for room in rooms %}
        {% set ns.r = ns.r + [{"region_id": room, "type": "rid"}]%}
      {% endfor %}
      {{ ns.r }}
- action: vacuum.send_command
  metadata: {}
  data:
    command: start
    params:
      pmap_id: VUFWNCMZQJ6MePE3X-_L3g
      user_pmapv_id: 240903T144808
      regions: "{{regions}}"
    target:
      entity_id: vacuum.robert
fields:
  rooms:
    selector:
      select:
        multiple: true
        custom_value: false
        options:
          - label: Bedroom
            value: 1
          - label: Living Room
            value: 2
          - label: Dining Room
            value: 3
          - label: Bathroom
            value: 4
          - label: Kitchen
            value: 5
    default:
      - 1
      - 2
      - 3
      - 4
      - 5
    name: Rooms
alias: Robert Clean Room
description: ""

EDIT: Updated to reflect comments below.

wispy sphinx
exotic wedge
wispy sphinx
#

I don't believe there is an issue with it, there shouldn't be