Combining automation "Choose" and "Repeat until"

Im trying to setup a combined automation where i have a “choose” function nested in a ‘‘repeat until’’ function.

I’ve tried several configurations however im not getting a working solution, has someone similar experience/solution?

Thanks!

####################################################
# Close TRV's in woonkamer when turning the boiler on       #
####################################################        
- alias: "Livingroom IO TRV controller CLOSE "
  trigger: 
    platform: state
    entity_id: switch.boiler_manual_state
    to: 'on'
  action: 
    repeat:
      sequence:
      - service: mqtt.publish
        data_template:
         topic: zigbee2mqtt/trv_living_achter/set/force
         payload: close
         qos: 1
      - delay:
          seconds: 5
      - service: mqtt.publish
        data_template:
         topic: zigbee2mqtt/trv_living_voor/set/force
         payload: close 
         qos: 1
      - delay:
          seconds: 20 
      - choose:
         - conditions:
             - condition: template
               value_template: "{{ repeat.index == 5 }}"
           sequence:
           - service: notify.notify
             data:
             message: 'Cant reach one of the TRVs --> Tried 5 times allready'            
      until:
      - condition: template
        value_template:
          "{{ 
          state_attr('climate.trv_living_achter','position') | float == 0  
          and
          state_attr('climate.trv_living_voor','position') | float == 0  
          }}"
      - condition: template
        value_template: "{{ repeat.index <= 6 }}"    

What’s your problem?

@petro

Invalid config for [automation]: expected dict for dictionary value @ data['action'][0]['repeat']['sequence'][4]['choose'][0]['sequence'][0]['data']. Got None
extra keys not allowed @ data['action'][0]['repeat']['sequence'][4]['choose'][0]['sequence'][0]['message']. Got None. (See /config/configuration.yaml, line 26).

I’m more looking for a general answer on how to combine a “choose” function and “repeat until” function

what you’re doing is fine but your spacing is off. That error message is telling you so. If you look at the message, it’s telling you exactly what’s wrong:

Invalid config for [automation]: expected dict for dictionary value @ data[‘action’][0][‘repeat’][‘sequence’][4][‘choose’][0][‘sequence’][0][‘data’]. Got None

So if you follow your automation, look at the following

data['action'][0]['repeat']['sequence'][4]['choose'][0]['sequence'][0]['data'].  Got None
         ^     ^     ^           ^      ^      ^     ^       ^      ^     ^            ^
         |     |     |           |      |      |     |       |      |     |            |

If you follow the nodes…

inside the action section, at the first service which is repeat, inside its sequence, on its 5th service which is choose, inside it’s sequence, at it’s first service, data is None.

Notice how message is not indented.

Then look at your second error…

extra keys not allowed @ data['action'][0]['repeat']['sequence'][4]['choose'][0]['sequence'][0]['message']. Got None. (See /config/configuration.yaml, line 26).

it states “extra keys not allowed”. Then it has the same sequence as the previous error message but the last item is ‘message’.

It’s saying, message is not allowed.

This is because the indentation is wrong.

           - service: notify.notify
             data:
               message: 'Cant reach one of the TRVs --> Tried 5 times allready'  

It’s best if you start trying to understand the error messages. They tell you exactly what’s wrong in most cases.

@petro

Thankyou very much for this clear explanation:)! I’ve never understood the error messages, but this helps me alot!

Got the function working as well!

Thanks