Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input select - Select next getting stuck with duplicate items #64161

Closed
edagnin opened this issue Jan 15, 2022 · 7 comments · Fixed by #66680
Closed

Input select - Select next getting stuck with duplicate items #64161

edagnin opened this issue Jan 15, 2022 · 7 comments · Fixed by #66680

Comments

@edagnin
Copy link

edagnin commented Jan 15, 2022

The problem

Originally posted on forum: Input select - Select next getting stuck while cycling through options

After asking on the Discord server, moderator RobC pointed out that this could be an issue:

image

It appears that if an input_select has items that are not unique in the list, it would revert to the first occurrence of that item and never update beyond it.

What version of Home Assistant Core has the issue?

core-2021.12.9

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Core

Integration causing the issue

Helper - Input Select

Link to integration documentation on our website

https://www.home-assistant.io/integrations/input_select/

Example YAML snippet

input_select:
  red_color:
    options:
      - 255
      - 255
      - 255
      - 239
      - 119
      - 70
      - 0
      - 0
      - 0
      - 255
  green_color:
    options:
      - 239
      - 96
      - 71
      - 70
      - 70
      - 144
      - 255
      - 255
      - 255
      - 174
  blue_color:
    options:
      - 72
      - 71
      - 129
      - 255
      - 255
      - 255
      - 255
      - 106
      - 0
      - 0

Anything in the logs that might be useful for us?

Nothing in the logs

Additional information

Example Automation:

- id: '1642148439200'
  alias: Lights Control (Automation)
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.button_click
    to: double
    id: double
  condition: []
  action:
  - service: light.turn_on
    target:
      entity_id: light.lamp
    data:
      rgb_color:
      - '{{ states(''input_select.red_color'') }}'
      - '{{ states(''input_select.green_color'') }}'
      - '{{ states(''input_select.blue_color'') }}'
  - service: input_select.select_next
    target:
      entity_id:
      - input_select.red_color
      - input_select.green_color
      - input_select.blue_color
  mode: single
@probot-home-assistant
Copy link

input_select documentation
input_select source
(message by IssueLinks)

@probot-home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (input_select) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@tdejneka
Copy link

Until the bug is fixed, you can mitigate the problem by consolidating RGB into a single input_select and modifying the automation like this:

input_select:
  light_color:
    options:
      - 255,239,72
      - 255,96,71
      - 255,71,129
      - 239,70,255
      - 119,70,255
      - 70,144,255
      - 0,255,255
      - 0,255,106
      - 0,255,0
      - 255,174,0
- id: '1642148439200'
  alias: Lights Control (Automation)
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.button_click
    to: double
    id: double
  condition: []
  action:
  - service: light.turn_on
    target:
      entity_id: light.lamp
    data:
      rgb_color: "{{ states('input_select.light_color').split(',') }}"
  - service: input_select.select_next
    target:
      entity_id: input_select.light_color
  mode: single

That should work for now, provided each option's value is unique (otherwise it will encounter the bug again).

@edagnin
Copy link
Author

edagnin commented Jan 17, 2022

@tdejneka Thank you for the workaround :)

I actually did something similar, but with an input_number instead. I think your solution is less code, so I will probably implement it. Thank you!

@emontnemery
Copy link
Contributor

emontnemery commented Jan 18, 2022

The problem is that input_select does not keep track of the index selected, it instead keeps track of the selected value.
We should either validate the options and not allow duplicated options, or keep track of which index is selected.

A problem with the latter is that it makes restoring the state ambiguous.

@emontnemery
Copy link
Contributor

It's not really feasible to support duplicated options, selecting an option would still be ambiguous because that's done by selecting a value, not an index. The linked PR hence deprecates creating or updating input_select with duplicated options.

@edagnin
Copy link
Author

edagnin commented Feb 17, 2022

Makes sense! Thank you 🙂

@github-actions github-actions bot locked and limited conversation to collaborators Mar 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants