Script with !input and service in one sequence

I have a blueprint script that controls different light senario based on variables sent from HMI or automation. This is working fine but, when I try to add a service to one of the sequence it fails:

blueprint:
  name: Generell Lyskontroll
  description: En generell blueprint for lyskontroll.
  domain: script


  input:
    rommodus:
      name: "Rommodus"
      description: Velg hvilket rom skriptet gjelder for
      default: []
      selector:
        entity:
          domain: input_select

    lys_auto:
      name: "Lys i auto"
      description: "Trigges av: action == 'Auto' or action_automasjon == 'auto'. Ingen avhengigheter"
      default: []
      selector:
        action:

    lys_av:
      name: "Lys i av"
      description: "Trigges av: action == 'Av' or action_automasjon == 'av' or action == 'Av (Auto)'. Ingen avhengigheter"
      default: []
      selector:
        action:      
        
    lys_avnatt:
      name: "Lys i avnatt"
      description: "Trigges av: action_automasjon == 'avnatt' or action == 'Natt (Auto)'. Ingen avhengigheter, skal brukes for å sette gjestemodus og barnemodus i ulike senarioer."
      default: []
      selector:
        action:    

    lys_maks:
      name: "Lys i maks"
      description: "Trigges av: action == 'Maks' or action_automasjon == 'maks'. Ingen avhengigheter"
      default: []
      selector:
        action:          

    lys_kos:
      name: "Lys i kos"
      description: "Trigges av: action == 'Kos' or action_automasjon == 'kos'. Ingen avhengigheter"
      default: []
      selector:
        action:     

mode: single

sequence:
  - variables:
      action: "{{ action }}"
      action_automasjon: "{{ action_automasjon }}"

  - choose:
      - conditions:
          - condition: template
            value_template: "{{ action == 'Auto' or action_automasjon == 'auto' }}"
        sequence: !input lys_auto
      
      - conditions:
          - condition: template
            value_template: "{{ action == 'Av' or action_automasjon == 'av' or action == 'Av (Auto)' }}"
        sequence: !input lys_av

      - conditions:
          - condition: template
            value_template: "{{ action_automasjon == 'avnatt' or action == 'Natt (Auto)' }}"
        sequence: 
          - !input lys_avnatt
          - service: input_select.select_option
            target: !input rommodus
            data:
              option: "Auto"

      - conditions:
          - condition: template
            value_template: "{{ action_automasjon == 'maks' or action == 'Maks' }}"
        sequence: !input lys_maks

      - conditions:
          - condition: template
            value_template: "{{ action_automasjon == 'kos' or action == 'Kos' }}"
        sequence: !input lys_kos


This is working fine:

      - conditions:
          - condition: template
            value_template: "{{ action == 'Av' or action_automasjon == 'av' or action == 'Av (Auto)' }}"
        sequence: !input lys_av

This is not: :slight_smile:

      - conditions:
          - condition: template
            value_template: "{{ action_automasjon == 'avnatt' or action == 'Natt (Auto)' }}"
        sequence: 
          - !input lys_avnatt
          - service: input_select.select_option
            target: !input rommodus
            data:
              option: "Auto"

Following error: Message malformed: expected a dictionary for dictionary value @ data[‘sequence’][1][‘choose’][2][‘sequence’][1][‘target’]

It’s an entity selector, it needs to be used in entity_id fields.

            target: 
              entity_id: !input rommodus

I think the format of your service is not correct, you should have an “entity_id:” field:

      - service: input_select.select_option
        target:
          entity_id: input_select.who_cooks
        data:
          option: Paulus

Petro is exactly right. You are using an entity selector to !input an entity and your code is set up to accept a target. Should use a target selector in the top or change the action to use an entity.

Also I assume
"{{ action }}" & "{{ action_automasjon }}"
are variables fed in thru data when you call the script, because I don’t see where else they are coming from. Anyway setting them equal to themselves it odd (but that is just me I guess). I would set them to a default and then if they don’t come in with the calling data, it wouldn’t error, it would just not match anything and safely exit.

thanks for help, I have tried to change the script to:

      - conditions:
          - condition: template
            value_template: "{{ action_automasjon == 'avnatt' or action == 'Natt (Auto)' }}"
        sequence: 
          - !input lys_avnatt
          - service: input_select.select_option
            target:
              entity_id: !input rommodus
            data:
              option: "Auto"

but I have the same problem. When I remove the “!input lys_avnatt” the script run fine, so I think its the way I use this that its wrong. Is the syntax of using “- !input lys_avnatt” right?

What is the contents of that?
Your code is stopping there, you need to work that.

Petro wrote this somewhere else, posting it for you here:

Targets and entities are not the same thing...
a target selector returns a dictionary containing entity_id key with a list of entities.  e.g.
{'entity_id': [ ., ., . ] }

or the yaml variation
entity_id:
- .
- .
- .

so, when you use entity_id: !input <some_target_selector> and you select entities... you end up feeding this to the yaml:
entity_id:
  entity_id:
  - .
  - .

instead of the desired
entity_id:
- .
- .

that's why you can't use target selector
entity selector always returns a list of entities, which is just [ ., ., . ] or the yaml equivalent:
- .
- .
- .