core icon indicating copy to clipboard operation
core copied to clipboard

wled/select.py:180/KeyError: 255

Open CoolhappyDE opened this issue 1 year ago • 13 comments

The problem

Wled is not working right on one controller. it always shows "Failed to perform the action light/turn_on. 255" when i change any atribute in the WLED device.

What version of Home Assistant Core has the issue?

core-2024.10.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

WLED

Link to integration documentation on our website

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

Diagnostics information

config_entry-wled-01J8TNVH5V0TRF8GMGGZMHPC2D.json

Example YAML snippet

action: light.toggle
target:
  entity_id:
    - light.eingangturwled
data: {}

Anything in the logs that might be useful for us?

Logger: homeassistant
Source: components/wled/select.py:180
First occurred: 6:17:19 PM (22 occurrences)
Last logged: 6:20:46 PM

Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 258, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 453, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 168, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 533, in _handle_coordinator_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1005, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1130, in _async_write_ha_state
    self.__async_calculate_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1067, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1011, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/select/__init__.py", line 145, in state
    current_option = self.current_option
                     ^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/wled/select.py", line 180, in current_option
    return self.coordinator.data.palettes[
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 255

Additional information

i did found a work around by disabling select.[name]_color_palette entity.

https://github.com/home-assistant/core/issues/124323#issuecomment-2306804233

CoolhappyDE avatar Oct 11 '24 17:10 CoolhappyDE

Hey there @frenck, mind taking a look at this issue as it has been labeled with an integration (wled) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of wled can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign wled Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


wled documentation wled source (message by IssueLinks)

home-assistant[bot] avatar Oct 11 '24 17:10 home-assistant[bot]

I have noticed this as well. I set up my WLED fixtures by using Presets, so usually I turn them on with a preset name and off with a script or automation. Two WLED controllers (running WLED v0.14.1 and v0.14.4) keep throwing this error, which causes the script to abort. If I manually turn it off, I get this error in a toast in the UI:

Option is not valid for entity select.wled_[name]_preset, valid options are: Sunset, Sunrise, Daylight, Night.

And if I turn it on:

Failed to perform the action light/turn_on. 255

I have another WLED controllers running v0.14.1 that is usually just a color/intensity set from Home Assistant directly, which doesn't seem to do this. Looks like if something happens that would cause Preset to become unset, this will occur?

tsmith512 avatar Nov 18 '24 20:11 tsmith512

This occurs to me when setting a preset via a scene created via the hass gui, but not via a service. I noticed that once this occurs, the log repeats indefinitely. Changing the preset via a service then sets things back in a good state, it succeeds and the exception stops spamming.

I wonder if this might be because the scene has all these extra presets. It's very likely that the autosave usermod preset no longer exists since its overwritten frequently and its name changes, but removing the 'options' array from my scenes didn't workaround it.

- id: '1732338106912'
  name: WLED - Movie evening
  entities:
    select.plants_preset:
      options:
      - Default All Off
      - Fairy
      - Forest Twinkle
      - Twinkle Up Forest
      - Twinkle Up Orange
      - Pacifica
      - Movie Dim
      - ~ 11-22 20:12:31 ~
      - Movie Theatre
      - Fairy Twinkle
      friendly_name: Plants Preset
      state: Twinkle Up Orange
    select.shelves_preset:
      options:
      - Default All Off
      - Sunset
      - Tetris AI
      - Skull Orange Twinkle
      - Fairy Forest Twinkle
      - Gentle Forest
      - Matrix
      - Fireworks
      - Black Hole
      - Comet
      - Spaceships
      - Rain
      - DNA Spiral
      - Sindots
      - Gentle sparkle
      - Movie Dim
      - Pacifica
      - ~ 11-17 20:01:22 ~
      - Movie Theatre
      friendly_name: Shelves Preset
      state: Movie Dim
    select.cane_preset:
      options:
      - 'Off'
      - Sunset Evening
      - Drip
      - Fire
      - Fireworks 1D
      - Movie
      - Forest
      - Autumn Sparkles
      - ~ 11-17 20:33:26 ~
      - Pacifica
      - Movie Dim
      - Movie Theatre
      friendly_name: Cane Preset
      state: Movie Dim
  icon: mdi:movie
  metadata:
    select.shelves_preset:
      entity_only: true
    select.cane_preset:
      entity_only: true
    select.plants_preset:
      entity_only: true```

zim514 avatar Nov 26 '24 18:11 zim514

I suspect this is because my segments change with different presets, making the palette entities different from time to time. The other entities seem to manage it okay but not that particular one.

zim514 avatar Dec 08 '24 18:12 zim514

I encounter the same problem. Both when activating a scene with a WLED device in it, and with turning off a group of lights with a WLED device in it. In my case, the specific WLED devices only have one segment which don't change.

In the scenes, I'm calling presets that are programmed on the WLED devices.

Part of the logbook:

[...]
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1079, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/select/__init__.py", line 188, in async_handle_select_option
    await self.async_select_option(option)
  File "/usr/src/homeassistant/homeassistant/components/wled/helpers.py", line 27, in handler
    self.coordinator.async_update_listeners()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 177, in async_update_listeners
    update_callback()
    ~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 558, in _handle_coordinator_update
    self.async_write_ha_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1023, in async_write_ha_state
    self._async_write_ha_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1148, in _async_write_ha_state
    self.__async_calculate_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1085, in __async_calculate_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1029, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/select/__init__.py", line 145, in state
    current_option = self.current_option
                     ^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/wled/select.py", line 180, in current_option
    return self.coordinator.data.palettes[
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        int(self.coordinator.data.state.segments[self._segment].palette_id)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ].name
    ^
KeyError: 255`

roybosch avatar Dec 11 '24 07:12 roybosch

I'm having the same issues with two WLED devices, both running 0.15.0.

2024-12-16 14:38:04.784 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None) Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 267, in _handle_refresh_interval await self._async_refresh(log_failures=True, scheduled=True) File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 478, in _async_refresh self.async_update_listeners() ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^ File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 177, in async_update_listeners update_callback() ~~~~~~~~~~~~~~~^^ File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 558, in _handle_coordinator_update self.async_write_ha_state() ~~~~~~~~~~~~~~~~~~~~~~~~~^^ File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1023, in async_write_ha_state self._async_write_ha_state() ~~~~~~~~~~~~~~~~~~~~~~~~~~^^ File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1148, in _async_write_ha_state self.__async_calculate_state() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^ File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1085, in __async_calculate_state state = self._stringify_state(available) File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1029, in _stringify_state if (state := self.state) is None: ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/select/__init__.py", line 145, in state current_option = self.current_option ^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/wled/select.py", line 180, in current_option return self.coordinator.data.palettes[ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ int(self.coordinator.data.state.segments[self._segment].palette_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ].name ^ KeyError: 254

AngusF22 avatar Dec 16 '24 21:12 AngusF22

I came across this same issue, the underlying wled library doesn't support custom palettes, so if one is set it'll start flooding the log with errors that HomeAssistant can't find the custom palette ID. For these palettes, the IDs start at 255 for ~ Custom 0 ~ and count down for each new one.

I proposed a fix for the underlying library https://github.com/frenck/python-wled/pull/1603

In the meantime, I created a custom integration that can cover the core integration targeting the changes and modifying the select platform to allow it to detect the custom palettes. https://github.com/bcpearce/hass-wled-custom

bcpearce avatar Dec 30 '24 03:12 bcpearce

Failed to perform the action light/turn_off. 255 when I turn a segment off in the WLED Integration. WLED v0.15.0 HAOS v2025.1.3

jkosharek avatar Jan 24 '25 03:01 jkosharek

I came across this same issue, the underlying wled library doesn't support custom palettes, so if one is set it'll start flooding the log with errors that HomeAssistant can't find the custom palette ID. For these palettes, the IDs start at 255 for ~ Custom 0 ~ and count down for each new one.

I proposed a fix for the underlying library frenck/python-wled#1603

In the meantime, I created a custom integration that can cover the core integration targeting the changes and modifying the select platform to allow it to detect the custom palettes. https://github.com/bcpearce/hass-wled-custom

Was this fix still working for you? I'm getting the same error basically. I have verified the manifest is updated to point at the custom core and have restarted.

Was there another step to getting it updated that needed to be done? I implemented it by adding the repo to hacs, then updating over the core wled implementation.

EDIT: I think I resolved it by doing ANOTHER reboot and restart of the Home Assistant Server and WLED device itself. Will report back if there are any further issues. Sorry for the ping. Keeping post to prevent ghost ping and hopefully help anyone else that ends up looking down this rabbit hole.

kylemccreery avatar Jan 24 '25 16:01 kylemccreery

I came across this same issue, the underlying wled library doesn't support custom palettes, so if one is set it'll start flooding the log with errors that HomeAssistant can't find the custom palette ID. For these palettes, the IDs start at 255 for ~ Custom 0 ~ and count down for each new one.

I proposed a fix for the underlying library frenck/python-wled#1603

In the meantime, I created a custom integration that can cover the core integration targeting the changes and modifying the select platform to allow it to detect the custom palettes. https://github.com/bcpearce/hass-wled-custom

Do you have any idea of the progress on this one? I saw that your fix went through some checks etc. but I have no clue what it all means... 😄

roybosch avatar Mar 04 '25 19:03 roybosch

Similar issue for me here, although the KeyError is 0

2025-03-12 18:30:16.689 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 268, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 479, in _async_refresh
    self.async_update_listeners()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 178, in async_update_listeners
    update_callback()
    ~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 559, in _handle_coordinator_update
    self.async_write_ha_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1023, in async_write_ha_state
    self._async_write_ha_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1148, in _async_write_ha_state
    self.__async_calculate_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1085, in __async_calculate_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1029, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/select/__init__.py", line 145, in state
    current_option = self.current_option
                     ^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/wled/select.py", line 180, in current_option
    return self.coordinator.data.palettes[
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        int(self.coordinator.data.state.segments[self._segment].palette_id)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ].name
    ^
KeyError: 0

this is a 5 segment led string. with 3 segments using "solid" as the effect - which subsequently has no "pallete" - just a colour selected into the "FX" colour slot. the other 2 segments are using "lighthouse" effect with the "default" palette.

I an running last weeks version of 0.16-alpha as I was trying to figure out if that fixes it, but from reading above this might be more of a case of how does the HA WLEd integration read the palette and process it.

The JSON returned appears to have the "pal" attribute for each segment set to 0 on all the segments.

as per:

Image

and the higher level Member "Palettes" is as follows:

Image

Comparing to another WLED that doesn't have this error, but IS on the same version, and has no segments defined, the top level "Member: Palettes" contains an array of all the palettes.

Image

Does this help to understand any more where a similar error might be coming from? - It doesn't sound like it is just custom palettes....

swampdogmash avatar Mar 12 '25 18:03 swampdogmash

Same issue for me on 15.0. I DELETED the color palette entities, and the issue would go away temporarily. They would get added back after HA restart.

DISABLING all the Color palette entities seems to have resolved this issue for me. I know it's not a fix, but since I don't use palettes anyway, it's a viable workaround until this is fixed.

stephack avatar Mar 23 '25 19:03 stephack

I’ve been experiencing the same issue and, after reading through this thread, I’ve decided to interact with my WLED device directly via its REST API instead of using the built-in integration. I’d appreciate any updates if a fix becomes available — or even just the option to fully remove the integration — to avoid giving Home Assistant a poor user experience by association.

flavio-fernandes avatar May 12 '25 12:05 flavio-fernandes

I also have exact same issue as https://github.com/home-assistant/core/issues/128181#issuecomment-2718828278. Also very similar behavior. The error was quite annoying, it makes it very hard to debug other issues:

Logger: homeassistant
Source: components/wled/select.py:183
First occurred: May 31, 2025 at 4:32:20 PM (9650 occurrences)
Last logged: 8:14:46 PM

Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 268, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 479, in _async_refresh
    self.async_update_listeners()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 178, in async_update_listeners
    update_callback()
    ~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 559, in _handle_coordinator_update
    self.async_write_ha_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1019, in async_write_ha_state
    self._async_write_ha_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1141, in _async_write_ha_state
    self.__async_calculate_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1081, in __async_calculate_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1025, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/select/__init__.py", line 145, in state
    current_option = self.current_option
                     ^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/wled/select.py", line 183, in current_option
    return self.coordinator.data.palettes[
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        int(self.coordinator.data.state.segments[self._segment].palette_id)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ].name
    ^
KeyError: 0

Luckily the workaround also solved the issue for me:

i did found a work around by disabling select.[name]_color_palette entity.

FrankTub avatar Jun 01 '25 18:06 FrankTub

Is this still being worked on? I had the same issue and I temporarily fixed it with the mentioned workaround of disabling the color palette entity but this is only a temporary solution for me as I also want to be able to change the color palette of my WLED devices from Home Assistant.

jensrossbach avatar Aug 16 '25 09:08 jensrossbach

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.