Problems with new chooser feature in scripts

Hi everybody,

I was really happy as I’ve seen the chooser feature for scripts and automations introduced in Home Assistant 0.113 and started playing with it right away. Meanwhile I’m on 0.113.3 but I still can’t get it to work. I always get the error

Invalid config for [script]: [choose] is an invalid option for [script]

Has anybody managed to get a chooser in a script running and / or can see my mistake?
(All conditions and sequences are working when used in a single script without the ‘choose’ option)

arbeitszimmer_scene_changer:
 alias: Szene im Arbeitszimmer wechseln
 choose:
   - conditions:
       - condition: state
         entity_id: variable.scene_arbeitszimmer
         state: 'Hell'
     sequence:
       - service: hue.hue_activate_scene
         data_template:
           group_name: "Arbeitszimmer"
           scene_name: "Hell"
       - service: mqtt.publish
         data_template:
           topic: wled/buero/api
           payload: PL=5
   - conditions:
       - condition: state
         entity_id: variable.scene_arbeitszimmer
         state: 'Standard'
     sequence:
       - service: hue.hue_activate_scene
         data_template:
           group_name: "Arbeitszimmer"
           scene_name: "Standard"
       - service: mqtt.publish
         data_template:
           topic: wled/buero/api
           payload: PL=6
   - conditions:
       - condition: state
         entity_id: variable.scene_arbeitszimmer
         state: 'Abend'
     sequence:
       - service: hue.hue_activate_scene
         data_template:
           group_name: "Arbeitszimmer"
           scene_name: "Abend"
       - service: mqtt.publish
         data_template:
           topic: wled/buero/api
           payload: PL=3
   - conditions:
       - condition: state
         entity_id: variable.scene_arbeitszimmer
         state: 'Zocken'
     sequence:
       - service: hue.hue_activate_scene
         data_template:
           group_name: "Arbeitszimmer"
           scene_name: "Zocken"
       - service: mqtt.publish
         data_template:
           topic: wled/buero/api
           payload: PL=2
 default:
   - service: hue.hue_activate_scene
     data_template:
       group_name: "Arbeitszimmer"
       scene_name: "Standard"
   - service: mqtt.publish
     data_template:
       topic: wled/buero/api
       payload: PL=6

Thanks in advance!

2 Likes

I’ve found the solution in this thread:

(Yes - I’ve searched before I posted but apparently with the wrong key words…)

I had to insert another ‘sequence:’ before the chooser. The top of the script is looking like this now and works like a charm:

arbeitszimmer_scene_changer:
 alias: Szene im Arbeitszimmer wechseln
 sequence:
   choose:
     - conditions:
         - condition: state
           entity_id: variable.scene_arbeitszimmer
           state: 'Hell'
       sequence:
         - service: hue.hue_activate_scene
           data_template:
             group_name: "Arbeitszimmer"
             scene_name: "Hell"
         - service: mqtt.publish
           data_template:
             topic: wled/buero/api
             payload: PL=5
[...]

I hope it helps somebody to save some time…

1 Like

FWIW, the fix was not really to “insert another ‘sequence:’ before the chooser”, but rather to use the choose action correctly. It’s just another type of action (like service, wait_template, etc.), and all actions in a script go under its sequence key, which you were missing.

Now, the choose action itself does contain one or more of its own sequence keys because they contain the actions to run when the corresponding conditions evaluate to true.

The reason I say this is because I know some people found the original documentation confusing (since they were not complete examples.) But the documentation has since been updated to make it clearer. I’m surprised, then, that you’ve made the same mistake. Can I ask, what made you think you should write the script the way you did? Is there still some documentation or example that misled you?

Hi Phil,

thanks for explaining the solution correctly. I’m using HA for nearly two years now, but I’m still struggling with this YAML syntax and nesting things…

To answer your question: I wrote the script about two weeks ago just after 0.113 was out and tried to adapt the documentation that was available at this time. I was pretty sure that my script has to be OK and just tried to run it again with 0.113.3 but without checking the documentation again.

But I just took another look inside…
I started from the release notes:


There is an example for an automation. I clicked on ‘documentation’ there an got to:
Here’s again an example for an automation although this is the scripts documentation. Maybe it would help to have an example script with the correct nested ‘sequence - choose - conditions - sequence’ thing here…
1 Like

No, actually it’s not “the scripts documentation.” That would be Scripts.

The “Script Syntax” is used by both automations & scripts (and I believe that is stated in several places), so it’s just as valid for either. Hence I used both automations & scripts in the examples for the new stuff. Wherever you see something under an automation’s action, it can also go under a script’s sequence. The main point of the examples on this page is to show how to use each of the various action types, not how to fit them into automations or scripts.

Hi Phil,

I just shared my approach and my thoughts…
In the end, the problem is of course that I lack a deeper understanding of the technical context. I always try to find the most suitable examples for my current project and then adapt them for myself. This way I have been able to solve all things well so far and the understanding grows with time without having to read the complete documentation first and understand the technical connections completely. All in all the mixture of official documentation and community contributions works very well for me. Thanks again for your explanation and questioning the cause of the problem.

1 Like