Select Component

ESPHome has support for components to create a select entity. A select entity is basically an option list that can be set by either yaml, hardware or the user/frontend.

Note

Home Assistant Core 2021.8 or higher is required for ESPHome select entities to work.

Base Select Configuration

All selects in ESPHome have a name and an optional icon.

# Example select configuration
name: Livingroom Mood
id: my_select

# Optional variables:
icon: "mdi:emoticon-outline"

Configuration variables:

  • name (Required, string): The name for the select.

  • icon (Optional, icon): Manually set the icon to use for the select in the frontend.

  • internal (Optional, boolean): Mark this component as internal. Internal components will not be exposed to the frontend (like Home Assistant). Only specifying an id without a name will implicitly set this to true.

  • disabled_by_default (Optional, boolean): If true, then this entity should not be added to any client’s frontend, (usually Home Assistant) without the user manually enabling it (via the Home Assistant UI). Requires Home Assistant 2021.9 or newer. Defaults to false.

Automations:

  • on_value (Optional, Automation): An automation to perform when a new value is published. See on_value.

MQTT Options:

Select Automation

You can access the most recent state of the select in lambdas using id(select_id).state.

on_value

This automation will be triggered when a new option is published. In Lambdas you can get the value from the trigger with x.

select:
  - platform: template
    # ...
    on_value:
      then:
        - logger.log:
            format: "Chosen option: %s"
            args: ["x.c_str()"]

Configuration variables: See Automation.

select.set Action

This is an Action for setting a select state.

- select.set:
    id: my_select
    option: "Happy"

Configuration variables:

  • id (Required, ID): The ID of the select to set.

  • option (Required, string, templatable): The option to set the select to.

lambda calls

From lambdas, you can call several methods on all selects to do some advanced stuff (see the full API Reference for more info).

  • make_call(): Set the select option.

    // Within lambda, select the "Happy" option.
    auto call = id(my_select).make_call();
    call.set_option("Happy");
    call.perform();
    
  • .state: Retrieve the current option of the select.

    // For example, create a custom log message when an option is selected:
    ESP_LOGI("main", "Option of my select: %s", id(my_select).state.c_str());
    

See Also