Need help making automation to check a group of entities and turn them on

so i made automation and group to use with unraid to turn on remote shares until they are on.. i trying to simulate like windows if a drive letter cant connect to the server it will keep trying to re connect till its connect ... i using this with unraids unassigned devices remote shares it doesnt have a built in re try mount and doesnt look they interested in adding.. but my configuration isnt working right i tried google to help to get the value template

alias: "!!! Test automount group"
description: ""
triggers:
  - value_template: >-
      {{ expand('group.k9_server_remote_share_automount') |
      map(attribute='state') | list is defined }}
    for:
      hours: 0
      minutes: 0
      seconds: 30
    trigger: template
  - trigger: homeassistant
    event: start
conditions: []
actions:
  - repeat:
      until:
        - condition: state
          entity_id: group.k9_server_remote_share_automount
          state:
            - "on"
          for:
            hours: 0
            minutes: 0
            seconds: 20
      sequence:
        - action: homeassistant.turn_on
          entity_id:
            - group.k9_server_remote_share_automount
        - delay:
            hours: 0
            minutes: 0
            seconds: 10
            milliseconds: 0
mode: single

so how it works is i got a group of toggle switchs and when home assistant boots or if mounting doesnt work
then turn the toggle... then wait 20 seconds and keep retrying till they are all on and stay on

i guess id like automation that polls incase the detecting if if a switch has toggled to off..

so not sure if best route is HA or the node red automation

I'm betting expand doesn't work in a trigger.... Not all functions and variables are available in triggers... Where to use templates - Home Assistant

Have you tested that template? I don't think it will ever render anything but true, so it will never actually fire.

Another issue could be the group. Which state behavior is the group using "any" or "all"? Based on the condition of the until I would guess it's supposed to be all, but is it?

alias: "!!! Test automount group"
description: ""
triggers:
  - trigger: template
    value_template: |
      {{ state_attr('group.k9_server_remote_share_automount', 'entity_id')
      | select('is_state','off') | list | count > 0 }}
    for: "00:00:30"
  - trigger: homeassistant
    event: start
conditions: []
actions:
  - repeat:
      until:
        #For this condition to work the group's state behavior needs to be "all"
        - condition: state
          entity_id: group.k9_server_remote_share_automount
          state: 'on'
          for: "00:00:20"
      sequence:
        - action: homeassistant.turn_on
          entity_id: |
            {{ state_attr('group.k9_server_remote_share_automount','entity_id')
            | reject('is_state','on') | list }}
          continue_on_error: true
        - delay: 20
mode: single

@Didgeridrew @Sir_Goodenough
no it doesnt work orginally i had just entity: group.xxxx
as the trigger but i remember from previous things like learned for my wled i need that select etc.. the triggering group wasnt always working

as all i need it to do is if any of the entities change i guess from unavalble to off or off to unavaliable or on to off etc
then toggle them all on and check if they are all on and if not keep looping every 20 seconds

so basiclly loop until all of the entites are in the ON position and the delay i put in to wait as i know if an entitiy not avaliable and you toggle on it will auto toggle off after like 3 4 seconds.. so that is my check delay for 20 seconds for if it cant mount and keep looping until they are all in the ON pos and stay on for 20 seconds

and this is my group of switchs that are linked to the unraid server remote shares

k9_server_remote_share_automount:
  name: K9 Server Remote Share Automount
  entities:
    - switch.k_9_remote_share_192_168_0_3_backup_files
    - switch.k_9_remote_share_192_168_0_3_family_files
    - switch.k_9_remote_share_192_168_0_3_music
    - switch.k_9_remote_share_192_168_0_3_tdarrtemp
    - switch.k_9_remote_share_192_168_0_3_temp
    - switch.k_9_remote_share_192_168_0_3_videos

so on is "mount" and off is "unmounted"

also i like it to poll too cuz i notice sometimes HA doesnt detect a change of entity changes sometimes.. so a poll like every 5 min to see if those in the group are on if not run the automaton till it is

so i tried paying with just hard coding since group wasnt always working but this isnt workight right either.. it polls ever 5 min and its supposed to check all of them if they are unknown off or unavaliable and if they are to switch on and wait 20 seconds and if its still on to exit

but its really only doing the first one its not checking all of them.. since i polling and just check if its "off"

but how do i do that and perferable in a group so i dont have to repeat the code so much

alias: "!! Remount 2"
description: ""
triggers:
  - trigger: time_pattern
    minutes: /5
conditions: []
actions:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: >-
                  binary_sensor.k_9_remote_share_192_168_0_3_backup_files_mounted
                state:
                  - "off"
        sequence:
          - repeat:
              until:
                - condition: state
                  entity_id: >-
                    binary_sensor.k_9_remote_share_192_168_0_3_backup_files_mounted
                  state:
                    - "on"
              sequence:
                - action: switch.turn_on
                  metadata: {}
                  target:
                    entity_id: switch.k_9_remote_share_192_168_0_3_backup_files
                  data: {}
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 20
                    milliseconds: 0
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: >-
                  binary_sensor.k_9_remote_share_192_168_0_3_family_files_mounted
                state: "off"
        sequence:
          - repeat:
              until:
                - condition: state
                  entity_id: >-
                    binary_sensor.k_9_remote_share_192_168_0_3_family_files_mounted
                  state:
                    - "on"
              sequence:
                - action: switch.turn_on
                  metadata: {}
                  target:
                    entity_id: switch.k_9_remote_share_192_168_0_3_family_files
                  data: {}
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 20
                    milliseconds: 0
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: binary_sensor.k_9_remote_share_192_168_0_3_music_mounted
                state: "off"
        sequence:
          - repeat:
              until:
                - condition: state
                  entity_id: binary_sensor.k_9_remote_share_192_168_0_3_music_mounted
                  state:
                    - "on"
              sequence:
                - action: switch.turn_on
                  metadata: {}
                  target:
                    entity_id: switch.k_9_remote_share_192_168_0_3_music
                  data: {}
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 20
                    milliseconds: 0
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: binary_sensor.k_9_remote_share_192_168_0_3_temp_mounted
                state: "off"
        sequence:
          - repeat:
              until:
                - condition: state
                  entity_id: binary_sensor.k_9_remote_share_192_168_0_3_temp_mounted
                  state:
                    - "on"
              sequence:
                - action: switch.turn_on
                  metadata: {}
                  target:
                    entity_id: switch.k_9_remote_share_192_168_0_3_temp
                  data: {}
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 20
                    milliseconds: 0
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: binary_sensor.k_9_remote_share_192_168_0_3_tdarrtemp_mounted
                state: "off"
        sequence:
          - repeat:
              until:
                - condition: state
                  entity_id: binary_sensor.k_9_remote_share_192_168_0_3_tdarrtemp_mounted
                  state:
                    - "on"
              sequence:
                - action: switch.turn_on
                  metadata: {}
                  target:
                    entity_id: switch.k_9_remote_share_192_168_0_3_tdarrtemp_mounted
                  data: {}
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 20
                    milliseconds: 0
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: binary_sensor.k_9_remote_share_192_168_0_3_videos_mounted
                state: "off"
        sequence:
          - repeat:
              until:
                - condition: state
                  entity_id: binary_sensor.k_9_remote_share_192_168_0_3_videos_mounted
                  state:
                    - "on"
              sequence:
                - action: switch.turn_on
                  metadata: {}
                  target:
                    entity_id: switch.k_9_remote_share_192_168_0_3_videos
                  data: {}
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 20
                    milliseconds: 0
mode: single

Choose actions are for mutually-exclusive options... it will only ever run the first option who's conditions pass.

@Didgeridrew what do i need to force it to check them all then

i figure options would check them all

and is there a way like i orginally had can you not check a group of switchs if they off to turn them on

cuz when i did a group it was hit and miss if it turned on the switchs in the group..

unless i just poll and just turn on if its on or off if cant be easilly checked or you gotta do in nodered?

I provided an automation that should work in my previous post and I asked a question about the group entity... which you have not answered.

If you prefer to use a Time Pattern trigger, you can swap that into my previous answer instead of the Template trigger.

i just scrolled up i didnt see your reply as i dont get updates and pages dont refresh so i just added to the bottom of my writtings.. ill go test yours

ill try it all.. i sorry i didnt see it.. it showed up after i hit refresh

i know why i didnt see it cuz at the time of reading your reply orginally

Have you tested that template? I don't think it will ever render anything but true, so it will never actually fire.

was all you had before i replied next .. i had never saw your updated message.. sorry about that

@Didgeridrew to your code i copied cant be run its
Message malformed: not a valid value for dictionary value @ data['actions'][0]['repeat']['sequence'][0]['entity_id']

as to your question about state behavior i have no idea?
i made
a group

k9_server_remote_share_automount:
  name: K9 Server Remote Share Automount
  entities:
    - switch.k_9_remote_share_192_168_0_3_backup_files
    - switch.k_9_remote_share_192_168_0_3_family_files
    - switch.k_9_remote_share_192_168_0_3_music
    - switch.k_9_remote_share_192_168_0_3_tdarrtemp
    - switch.k_9_remote_share_192_168_0_3_temp
    - switch.k_9_remote_share_192_168_0_3_videos

and it was just to check which ever one is off turn it on delay 20seconds if its on good if not turn it on again

so if all of them were off then turn them all on .. if 2 on then trying to turn the other ones on.. but if its too complicated then id do a different way of doing it

i orginally was going to do 1 automation per switch but figured it be easiier in the end doing a group check of each entitiy

@Didgeridrew so i tried to figure out how to fix that malform i couldnt

but i noticed your automation is to loop until the group. is on.. but apparently its always on from what i see even if switchs are off in the group.. the group state is on... so it wouldnt run if it did cuz even if all switchs but 1 are off the group is on i noticed

so if all switchs are off.. it goes "off" for the group.. if one turns on the the group is on...
maybe easier just to make 1 automation per switch i guess? and forget the group? i dunno i just playing around at the moment

Is there a reason you are using the old style groups when you don't have to and they are no longer recommended? All your entities are switches, so you can just use a Switch Group Helper.

@Didgeridrew
didnt know there is a change.. not like i read every update i just update homeassistant and if i create a group its like once or twice a year so i d didnt know of changes..

i did try this which seems to work.. ill look up the switch group.
and see how it works

alias: "!!!!!remount test"
description: ""
triggers:
  - trigger: time_pattern
    seconds: /20
conditions:
  - condition: or
    conditions:
      - condition: state
        entity_id: switch.k_9_remote_share_192_168_0_3_backup_files
        state: "off"
      - condition: state
        entity_id: switch.k_9_remote_share_192_168_0_3_family_files
        state: "off"
      - condition: state
        entity_id: switch.k_9_remote_share_192_168_0_3_music
        state: "off"
      - condition: state
        entity_id: switch.k_9_remote_share_192_168_0_3_tdarrtemp
        state: "off"
      - condition: state
        entity_id: switch.k_9_remote_share_192_168_0_3_temp
        state: "off"
      - condition: state
        entity_id: switch.k_9_remote_share_192_168_0_3_videos
        state: "off"
actions:
  - action: homeassistant.turn_on
    metadata: {}
    target:
      entity_id: group.k9_server_remote_share_automount
    data: {}
mode: single

i made switch group i was able to add those entitys so its switch.remote_share_group_helper
i find no matter what if all the switchs are off but one that switch group is still on i guess best way is what i got
poll every 20 seconds or ill change poll every 5 min and check the indvidual and then group toggle that switch group..

guess making it small foot print not always the easiest... but my last coding seems to be working using the turn on switch for the group switch you told me about...

i appreciate your help so far.. always learning something new

It's been more than 4 years...