"select" selector from template?

I want to create a script which does some stuff and then changes my ecobee’s preset mode. What I have (below) works fine, but I don’t want to hard-code the list of presets. This list is available in a preset_modes (note plural) attribute of the Ecobee climate entity… but it doesn’t seem to work to provide {{ state_attr("climate.top_floor","preset_modes") }} as a template to selector: select: options: instead of the typed-out list.

Is this possible in some way?

alias: "Ecobee: Change Preset with Timer"
description: >-
  Change an Ecobee preset, but only if it isn't already set to that. And, set a
  10 minute timer after any (actual) change.
mode: parallel
icon: mdi:tune-variant
max: 3
trace:
  stored_traces: 20
fields:
  ecobee:
    name: Ecobee thermostat
    description: Ecobee thermostat to change
    required: true
    selector:
      device:
        manufacturer: ecobee
        entity:
          domain: climate
  preset:
    name: Target climate preset
    description: Put the ecobee in this mode...
    required: true
    selector:
      select:
        options:
          - Home
          - Away
          - Sleep
          - Work Sit
          - Work Walk
          - TV
sequence:
  - if:
      - condition: template
        value_template: "{{ state_attr(\"climate.top_floor\",\"preset_mode\") == preset }}"
    then:
      - stop: Already in this preset mode.
  - service: climate.set_preset_mode
    data:
      preset_mode: "{{ preset }}"
    target:
      device_id: "{{ ecobee }}"
  - service: timer.start
    data:
      duration: "600"
    target:
      entity_id: timer.timer_minimum_heat_change
1 Like

The documentation for a script’s fields option doesn’t show that templates are supported. Neither does the documentation for Selectors.

That’s what I observed too. Is there another way?

Magic?

But seriously, it doesn’t support templates so that prevents you from dynamically assigning it with the preset_modes of a climate entity.

I would also like to dynamically populate field option selectors for scripts
I have a script that is executed when my template select changes.
It gets its value passed to it from the UI via an entity card (mushroom in this case) which populates the dropdown using a “template select”

  - type: custom:mushroom-select-card
    name: Area
    entity: select.room_settings_select_room

# ----------------------------------------------
# select.room_settings_select_room
# ----------------------------------------------
- select:
  - unique_id: room_settings_select_room
    name: room_settings_select_room
    optimistic: true
    state: >-
      {%- from "room_motion.jinja" import get_real_rooms_names -%}
      {{ get_real_rooms_names().split(',')
         | map('area_name')
         | list
         | sort
         | first
      }}
    options: >
      {%- from "room_motion.jinja" import get_real_rooms_names -%}
      {{ get_real_rooms_names().split(',') }}
    # -----------------------------------------------------------------
    # Action that happens when an option is selected in the dropdown
    # -----------------------------------------------------------------
    select_option:
    - variables:
        room_area_id: >
          {{ area_id(option) }}

    - service: script.room_settings_dict_load_item
      data:
        room_area_id: "{{ room_area_id }}"

Once in a while I was to call the script manually… I have added fields to the script. However, because I cannot dynamically populate a curated list of areas into the selector for the field ‘room_area_id’, the , the only choice I have to is show all areas to the user, or to hardcode in the list of rooms generated by my macro. I want to use the macro because its return value may change over time

image

script:

  room_settings_dict_load_item:
    alias: room_settings_dict_load_item
    mode: single

    fields:
      room_area_id:
        description: The room_area_id of an area
        example: 'room_area_id: bathroom'
        required: true
        # I want to dynamically generate the options in this selector 
        # so I do not have to maintain them anywhere except in the 
        # macro 'get_real_rooms_names()'
        # I want selector: to accept select.room_settings_select_room as a valid value for the *selector:* key
        selector:
          # Or I want area: to accept select.room_settings_select_room, or a template as a valid value for the *area:* key
          area:

    variables:
      room: "{{room_area_id}}"
      room_settings_storage_id: sensor.room_settings_storage
      room_settings: >-
        {%- from "room_motion.jinja" import room_settings_dict_load_item -%}
        {{ room_settings_dict_load_item(room_area_id) | from_json }}