How to create a Script With input select?

I have this script that worked fine up to a few versions, but now it gives me an error in the log, how do I solve it?

Input Select:

  numeri_canali:
    name: "Numero Canale"
    icon: mdi:format-list-numbered
    options:
      - Seleziona canale
      - Zero
      - Uno
      - Due
      - Tre
      - Quattro
      - Cinque
      - Sei
      - Sette
      - Otto
      - Nove
    initial: Seleziona canale

Script:

    seleziona_numero:
      alias: Seleziona Numero
      sequence:
      - service: input_select.set_options
        data_template:
          entity_id: input_select.numeri_canali
      - service: script.turn_on
        data_template:
          entity_id: >-
            {% if is_state("input_select.numeri_canali", "Zero") %} script.zero
            {% elif is_state("input_select.numeri_canali", "Uno") %} script.uno
            {% elif is_state("input_select.numeri_canali", "Due") %} script.due
            {% elif is_state("input_select.numeri_canali", "Tre") %} script.tre
            {% elif is_state("input_select.numeri_canali", "Quattro") %} script.quattro
            {% elif is_state("input_select.numeri_canali", "Cinque") %} script.cinque
            {% elif is_state("input_select.numeri_canali", "Sei") %} script.sei
            {% elif is_state("input_select.numeri_canali", "Sette") %} script.sette
            {% elif is_state("input_select.numeri_canali", "Otto") %} script.otto
            {% elif is_state("input_select.numeri_canali", "Nove") %} script.nove
            {% endif %}

Error:

2019-10-20 18:32:04 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall script.seleziona_numero (c:60bd95c243a84eb598c44fb96c3fbbde)>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1241, in _safe_execute
    await self._execute_service(handler, service_call)
  File "/usr/src/homeassistant/homeassistant/core.py", line 1258, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 142, in service_handler
    await script.async_turn_on(variables=service.data, context=service.context)
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 214, in async_turn_on
    raise err
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 209, in async_turn_on
    await self.script.async_run(kwargs.get(ATTR_VARIABLES), context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 181, in async_run
    await self._handle_action(action, variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 265, in _handle_action
    await self._actions[_determine_action(action)](action, variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 348, in _async_call_service
    context=context,
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 97, in async_call_from_config
    domain, service_name, service_data, blocking=blocking, context=context
  File "/usr/src/homeassistant/homeassistant/core.py", line 1211, in async_call
    processed_data = handler.schema(service_data)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 432, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: required key not provided @ data['options'] 

Delete this from your script.


      - service: input_select.set_options
        data_template:
          entity_id: input_select.numeri_canali

@tom_l Thanks, work it and add delay for command?
I would like the command to run 1 second after I run it

delay:
  seconds: 1

@tom_l thanks

it’s right?

    seleziona_numero:
      alias: Seleziona Numero
      sequence:
        delay:
          seconds: 1
      - service: script.turn_on
        data_template:
          entity_id: >-
            {% if is_state("input_select.numeri_canali", "Zero") %} script.zero
            {% elif is_state("input_select.numeri_canali", "Uno") %} script.uno
            {% elif is_state("input_select.numeri_canali", "Due") %} script.due
            {% elif is_state("input_select.numeri_canali", "Tre") %} script.tre
            {% elif is_state("input_select.numeri_canali", "Quattro") %} script.quattro
            {% elif is_state("input_select.numeri_canali", "Cinque") %} script.cinque
            {% elif is_state("input_select.numeri_canali", "Sei") %} script.sei
            {% elif is_state("input_select.numeri_canali", "Sette") %} script.sette
            {% elif is_state("input_select.numeri_canali", "Otto") %} script.otto
            {% elif is_state("input_select.numeri_canali", "Nove") %} script.nove
            {% endif %}
seleziona_numero:
  alias: Seleziona Numero
  sequence:
    - delay:
        seconds: 1
    - service_template: "script.{{ states('input_select.numeri_canali') | lower }}"

@anon43302295 thanks, works it

1 Like