ESPHome - Setting "select component", selected item causes esp8266 to reboot

Hello, i have an issue when trying to set the selected item on a select list using ESPHome on a esp8266,
if i use optimistic: true all work fine, but when i set optimistic to false and try to set the selected option programatically, the esp8266 freezes and reboots.

below is the code:

switch:
  - platform: template
    name: "Power Switch"
    id: esphue_powersw
    restore_mode: RESTORE_DEFAULT_OFF
    turn_on_action:
      - remote_transmitter.transmit_nec:
          address: 0xFF00
          command: 0xF807
      - switch.template.publish:
          id: esphue_powersw
          state: ON
    turn_off_action:
      - remote_transmitter.transmit_nec:
          address: 0xFF00
          command: 0xF906
      - switch.template.publish:
          id: esphue_powersw
          state: OFF

select:
  - platform: template
    name: Color
    id: esphue_color
    icon: mdi:palette
    options:
      - "Select Color"
      - "Red"
      - "Orange"
      - "Yellow"
      - "Light Green"
      - "Lime Green"
      - "Green"
      - "Turqoise"
      - "Light Blue"
      - "Blue"
      - "Indigo"
      - "Dark Purple"
      - "Purple"
      - "Mauve"
      - "Pink"
      - "Bright Pink"
      - "White"
    initial_option: "Select Color"
    optimistic: false
    set_action:
      - if:
          condition:
            - lambda: 'return x == "Red";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xF609
      - if:
          condition:
            - lambda: 'return x == "Orange";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xF20D
      - if:
          condition:
            - lambda: 'return x == "Yellow";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xEA15
      - if:
          condition:
            - lambda: 'return x == "Light Green";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xE619
      - if:
          condition:
            - lambda: 'return x == "Lime Green";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xEE11
      - if:
          condition:
            - lambda: 'return x == "Green";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xF708
      - if:
          condition:
            - lambda: 'return x == "Turqoise";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xF30C
      - if:
          condition:
            - lambda: 'return x == "Light Blue";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xEB14
      - if:
          condition:
            - lambda: 'return x == "Blue";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xE718
      - if:
          condition:
            - lambda: 'return x == "Indigo";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xEF10
      - if:
          condition:
            - lambda: 'return x == "Dark Purple";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xF50A
      - if:
          condition:
            - lambda: 'return x == "Purple";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xF10E
      - if:
          condition:
            - lambda: 'return x == "Mauve";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xE916
      - if:
          condition:
            - lambda: 'return x == "Pink";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xE51A
      - if:
          condition:
            - lambda: 'return x == "Bright Pink";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xED12
      - if:
          condition:
            - lambda: 'return x == "White";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xF40B
      - if:
          condition:
            - lambda: 'return x != "Select Option";'
          then:
            - lambda: 'id(esphue_color).make_call().set_option(x).perform();'
            - lambda: 'id(esphue_action).make_call().set_option("Select Action").perform();'

  - platform: template
    name: Action
    id: esphue_action
    icon: mdi:alarm-light
    options:
      - "Select Action"
      - "Disco lights"
      - "Fade In-Out"
      - "Smooth Fade"
      - "RGB"
    initial_option: "Select Action"
    optimistic: false
    set_action:
      - logger.log:
          format: "Chosen option: %s"
          args: ["x.c_str()"]
      - if:
          condition:
            - lambda: 'return x == "Disco lights";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xF00F
      - if:
          condition:
            - lambda: 'return x == "Fade In-Out";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xE817
      - if:
          condition:
            - lambda: 'return x == "Smooth Fade";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xE41B
      - if:
          condition:
            - lambda: 'return x == "RGB";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xEC13
      - if:
          condition:
            - lambda: 'return x != "Select Action";'
          then:
            - lambda: 'id(esphue_action).make_call().set_option(x).perform();'
            - lambda: 'id(esphue_color).make_call().set_option("Select Color").perform();'

the parts causing the problem are the following:

      - if:
          condition:
            - lambda: 'return x != "Select Option";'
          then:
            - lambda: 'id(esphue_color).make_call().set_option(x).perform();'
            - lambda: 'id(esphue_action).make_call().set_option("Select Action").perform();'

and

      - if:
          condition:
            - lambda: 'return x != "Select Action";'
          then:
            - lambda: 'id(esphue_action).make_call().set_option(x).perform();'
            - lambda: 'id(esphue_color).make_call().set_option("Select Color").perform();'
  • optimistic (Optional, boolean): Whether to operate in optimistic mode - when in this mode, any command sent to the Template Select will immediately update the reported state. Cannot be used with lambda. Defaults to false.

I pressume it cannot be set to “true” when using lambda as it defaults to false anyways. I’ve tried without the use of lambda & without defining the optimistic variable at all. Same result, when trying to set the state manually, esp8266 crashes & reboots. Nothing specific visible in the log.

   - if:
          condition:
            - lambda: 'return x != "Select Action";'
          then:
            - lambda: 'id(esphue_action).make_call().set_option(x).perform();'
            - lambda: 'id(esphue_color).make_call().set_option("Select Color").perform();'

You shouldnt even need any of this. It doesnt make sense and it and that isnt how the documentation shows you.

If you selct Color “Orange” then what is this supposed to do?


id(esphue_color).make_call().set_option(x).perform();

When you select a Select option then that is automatically the “Active” option or its the option that is ON and your if Orange condition will be True and then execute. Nothing else needs done.

When i select Orange, then it has to be published (set/saved) on the frontend aswell, otherwise it resets to the default option. So the option is not automatically active with optimistic set to false, the states is being reset after u reload the page on front end.

If you read the code you will understand that the second select box has to be reset to “select option” when the first box has an option set.

And thats the reason you have the option to set “optimistic” to false, so you can set the actual state programmatically.

Now my question remains, why does it crash/reboot when setting the option programatically, it works fine with switches when publishing the state programatically.

even if i set optimistic to true, and only try to set the active option of the second select compoment, it still crashes. The problem relies somewhere else.

here is the code using optimistic: true

select:
  - platform: template
    name: Color
    id: esphue_color
    icon: mdi:palette
    options:
      - "Select Color"
      - "Red"
      - "Orange"
      - "Yellow"
      - "Light Green"
      - "Lime Green"
      - "Green"
      - "Turqoise"
      - "Light Blue"
      - "Blue"
      - "Indigo"
      - "Dark Purple"
      - "Purple"
      - "Mauve"
      - "Pink"
      - "Bright Pink"
      - "White"
    initial_option: "Select Color"
    optimistic: true
    set_action:
      - if:
          condition:
            - lambda: 'return x == "Red";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xF609
      - if:
          condition:
            - lambda: 'return x == "Orange";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xF20D
      - if:
          condition:
            - lambda: 'return x == "Yellow";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xEA15
      - if:
          condition:
            - lambda: 'return x == "Light Green";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xE619
      - if:
          condition:
            - lambda: 'return x == "Lime Green";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xEE11
      - if:
          condition:
            - lambda: 'return x == "Green";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xF708
      - if:
          condition:
            - lambda: 'return x == "Turqoise";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xF30C
      - if:
          condition:
            - lambda: 'return x == "Light Blue";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xEB14
      - if:
          condition:
            - lambda: 'return x == "Blue";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xE718
      - if:
          condition:
            - lambda: 'return x == "Indigo";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xEF10
      - if:
          condition:
            - lambda: 'return x == "Dark Purple";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xF50A
      - if:
          condition:
            - lambda: 'return x == "Purple";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xF10E
      - if:
          condition:
            - lambda: 'return x == "Mauve";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xE916
      - if:
          condition:
            - lambda: 'return x == "Pink";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xE51A
      - if:
          condition:
            - lambda: 'return x == "Bright Pink";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xED12
      - if:
          condition:
            - lambda: 'return x == "White";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xF40B
      - if:
          condition:
            - lambda: 'return x != "Select Option";'
          then:
            - select.first:
                id: esphue_action

  - platform: template
    name: Action
    id: esphue_action
    icon: mdi:alarm-light
    options:
      - "Select Action"
      - "Disco lights"
      - "Fade In-Out"
      - "Smooth Fade"
      - "RGB"
    initial_option: "Select Action"
    optimistic: true
    set_action:
      - logger.log:
          format: "Chosen option: %s"
          args: ["x.c_str()"]
      - if:
          condition:
            - lambda: 'return x == "Disco lights";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xF00F
      - if:
          condition:
            - lambda: 'return x == "Fade In-Out";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xE817
      - if:
          condition:
            - lambda: 'return x == "Smooth Fade";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xE41B
      - if:
          condition:
            - lambda: 'return x == "RGB";'
          then:
            - remote_transmitter.transmit_nec:
                address: 0xFF00
                command: 0xEC13
      - if:
          condition:
            - lambda: 'return x != "Select Action";'
          then:
            - select.first:
                id: esphue_color

Found the solution to my problem, apparently the command to publish the new state was only mentioned on a “Note” box and not on the available command list in the documentation. For those who have similar issue here is the answer:

Note
If you don’t set a lambda and optimistic is false (default), updates to the select component state will need to be taken care of as part of your set_action using id(my_select).publish_state(x); (in a lambda). Do not use select.set Action here, as this would generate a loop. Also, don’t use id(my_select).state = x as this won’t have the desired effect (e.g. HA won’t update with the change).

haesphome

Basically instead of using “set_option” you should use “.publish_state(x);” otherwise it will result in a loop.