Need a little help with REJECT part of this code

I’m trying to populate an input_select with the list of possible effects in WLED. I can test this code in the template editor and it works as expected, however the duplicate RSVD entries cause the automation to fail with the error below. Can anyone assist me with either a better way to do this or a solution that excludes the duplicates.

        {% set wled_effects = namespace(effect_name=[]) %}
        {%- for effect_list in state_attr('light.wled_home_1', 'effect_list') -%}
        {%- set wled_effects.effect_name = state_attr('light.wled_home_1', 'effect_list')  -%}      
        {%- endfor -%}
        {{wled_effects.effect_name}}

The error reported in the trace timeline is:

Stopped because an error was encountered at August 22, 2023 at 8:12:00 PM (runtime: 0.03 seconds)

Duplicated options: ['Akemi', 'Android', 'Aurora', 'Black Hole', 'Blends', 'Blink', 'Blink Rainbow', 'Blobs', 'Blurz', 'Bouncing Balls', 'Bpm', 'Breathe', 'Candle', 'Candle Multi', 'Chase', 'Chase 2', 'Chase 3', 'Chase Flash', 'Chase Flash Rnd', 'Chase Rainbow', 'Chase Random', 'Chunchun', 'Colored Bursts', 'Colorful', 'Colorloop', 'Colortwinkles', 'Colorwaves', 'Crazy Bees', 'DJ Light', 'DNA', 'DNA Spiral', 'Dancing Shadows', 'Dissolve', 'Dissolve Rnd', 'Distortion Waves', 'Drift', 'Drift Rose', 'Drip', 'Dynamic', 'Dynamic Smooth', 'Fade', 'Fairy', 'Fairytwinkle', 'Fill Noise', 'Fire 2012', 'Fire Flicker', 'Firenoise', 'Fireworks', 'Fireworks 1D', 'Fireworks Starburst', 'Flow', 'Flow Stripe', 'Freqmap', 'Freqmatrix', 'Freqpixels', 'Freqwave', 'Frizzles', 'Funky Plank', 'GEQ', 'Game Of Life', 'Ghost Rider', 'Glitter', 'Gradient', 'Gravcenter', 'Gravcentric', 'Gravfreq', 'Gravimeter', 'Halloween Eyes', 'Heartbeat', 'Hiphotic', 'ICU', 'Juggle', 'Juggles', 'Julia', 'Lake', 'Lighthouse', 'Lightning', 'Lissajous', 'Loading', 'Matripix', 'Matrix', 'Metaballs', 'Meteor', 'Meteor Smooth', 'Midnoise', 'Multi Comet', 'Noise 1', 'Noise 2', 'Noise 3', 'Noise 4', 'Noise Pal', 'Noise2D', 'Noisefire', 'Noisemeter', 'Noisemove', 'Octopus', 'Oscillate', 'Pacifica', 'Palette', 'Percent', 'Perlin Move', 'Phased', 'Phased Noise', 'Pixels', 'Pixelwave', 'Plasma', 'Plasma Ball', 'Plasmoid', 'Polar Lights', 'Popcorn', 'Pride 2015', 'Puddlepeak', 'Puddles', 'Pulser', 'RSVD', 'RSVD', 'RSVD', 'RSVD', 'RSVD', 'RSVD', 'RSVD', 'RSVD', 'RSVD', 'Railway', 'Rain', 'Rainbow', 'Rainbow Runner', 'Random Colors', 'Ripple', 'Ripple Peak', 'Ripple Rainbow', 'Rocktaves', 'Running', 'Running Dual', 'Saw', 'Scan', 'Scan Dual', 'Scanner', 'Scanner Dual', 'Scrolling Text', 'Sindots', 'Sine', 'Sinelon', 'Sinelon Dual', 'Sinelon Rainbow', 'Soap', 'Solid', 'Solid Glitter', 'Solid Pattern', 'Solid Pattern Tri', 'Spaceships', 'Sparkle', 'Sparkle Dark', 'Sparkle+', 'Spots', 'Spots Fade', 'Squared Swirl', 'Stream', 'Stream 2', 'Strobe', 'Strobe Mega', 'Strobe Rainbow', 'Sun Radiation', 'Sunrise', 'Sweep', 'Sweep Random', 'Swirl', 'TV Simulator', 'Tartan', 'Tetrix', 'Theater', 'Theater Rainbow', 'Traffic Light', 'Tri Fade', 'Tri Wipe', 'Twinkle', 'Twinklecat', 'Twinklefox', 'Twinkleup', 'Two Dots', 'Washing Machine', 'Waterfall', 'Waverly', 'Wavesins', 'Waving Cell', 'Wipe', 'Wipe Random']

I’m sure there is a simple solution, but I’m not having any luck at it right now.

For completeness here is the full attributes list from the states page:

effect_list: Akemi, Android, Aurora, Black Hole, Blends, Blink, Blink Rainbow, Blobs, Blurz, Bouncing Balls, Bpm, Breathe, Candle, Candle Multi, Chase, Chase 2, Chase 3, Chase Flash, Chase Flash Rnd, Chase Rainbow, Chase Random, Chunchun, Colored Bursts, Colorful, Colorloop, Colortwinkles, Colorwaves, Crazy Bees, DJ Light, DNA, DNA Spiral, Dancing Shadows, Dissolve, Dissolve Rnd, Distortion Waves, Drift, Drift Rose, Drip, Dynamic, Dynamic Smooth, Fade, Fairy, Fairytwinkle, Fill Noise, Fire 2012, Fire Flicker, Firenoise, Fireworks, Fireworks 1D, Fireworks Starburst, Flow, Flow Stripe, Freqmap, Freqmatrix, Freqpixels, Freqwave, Frizzles, Funky Plank, GEQ, Game Of Life, Ghost Rider, Glitter, Gradient, Gravcenter, Gravcentric, Gravfreq, Gravimeter, Halloween Eyes, Heartbeat, Hiphotic, ICU, Juggle, Juggles, Julia, Lake, Lighthouse, Lightning, Lissajous, Loading, Matripix, Matrix, Metaballs, Meteor, Meteor Smooth, Midnoise, Multi Comet, Noise 1, Noise 2, Noise 3, Noise 4, Noise Pal, Noise2D, Noisefire, Noisemeter, Noisemove, Octopus, Oscillate, Pacifica, Palette, Percent, Perlin Move, Phased, Phased Noise, Pixels, Pixelwave, Plasma, Plasma Ball, Plasmoid, Polar Lights, Popcorn, Pride 2015, Puddlepeak, Puddles, Pulser, RSVD, RSVD, RSVD, RSVD, RSVD, RSVD, RSVD, RSVD, RSVD, Railway, Rain, Rainbow, Rainbow Runner, Random Colors, Ripple, Ripple Peak, Ripple Rainbow, Rocktaves, Running, Running Dual, Saw, Scan, Scan Dual, Scanner, Scanner Dual, Scrolling Text, Sindots, Sine, Sinelon, Sinelon Dual, Sinelon Rainbow, Soap, Solid, Solid Glitter, Solid Pattern, Solid Pattern Tri, Spaceships, Sparkle, Sparkle Dark, Sparkle+, Spots, Spots Fade, Squared Swirl, Stream, Stream 2, Strobe, Strobe Mega, Strobe Rainbow, Sun Radiation, Sunrise, Sweep, Sweep Random, Swirl, TV Simulator, Tartan, Tetrix, Theater, Theater Rainbow, Traffic Light, Tri Fade, Tri Wipe, Twinkle, Twinklecat, Twinklefox, Twinkleup, Two Dots, Washing Machine, Waterfall, Waverly, Wavesins, Waving Cell, Wipe, Wipe Random
supported_color_modes: rgb
color_mode: rgb
brightness: 128
hs_color: 9.123, 67.059
rgb_color: 255, 110, 84
xy_color: 0.589, 0.329
effect: Solid
icon: mdi:led-strip-variant
friendly_name: WLED Home 1
supported_features: 36

Thanks in advance!

{{ wled_effects.effect_name | unique }} will exclude duplicates but leave one “RSVD”.

{{ wled_effects.effect_name | reject('eq', 'RSVD') | list }} will remove all “RSVD” items from the list.

EDIT: Fixed missing list filter.

@ Didgeridrew

Thanks for the quick response. Unfortunately, it didn’t work in the template editor. I get these responses from the code:

{{ wled_effects.effect_name | unique }}
results in: <generator object do_unique at 0x7e73c44d00>

{{ wled_effects.effect_name | reject(‘eq’, ‘RSVD’) }}
results in: <generator object select_or_reject at 0x7f63980820>

here’s the template editor code I tested with:

        {% set wled_effects = namespace(effect_name=[]) %}
        {%- for effect_list in state_attr('light.wled_home_1', 'effect_list') -%}
        {%- set wled_effects.effect_name = state_attr('light.wled_home_1', 'effect_list')  -%}      
        {%- endfor -%}
        {{ wled_effects.effect_name }}
        {{ wled_effects.effect_name | unique }}
        {{ wled_effects.effect_name | reject('eq', 'RSVD') }}

The first line AFTER the endfor statement works but includes the duplicates, the next two. (with the piped filters) generate the above errors. I’m assuming that this is where you intended me to put the code (replacing the unfiltered with one of the filtered) and it seems the only logical place to use it. I did try some other variations but all resulted in an immediate fail and could not be rendered. And yes, I did try using just one of the options at a time. The above template editor code is just for examples sake.

There was a missing list filter in the earlier post, but I don’t really understand how you are trying to use this template… or why you are using a loop to set a variable to the same thing over and over. If you just need the list of effects without the RSVD's, you should be fine with:

{{ state_attr('light.wled_home_1', 'effect_list') | reject('eq', 'RSVD') | list }}

Can you post the automation you are trying to use?

1 Like

@ Didgeridrew

OK, so I mistakenly assumed that when trying to populate an input select, one would need to iterate through the items in the list, adding each one to the list in sequence. Your suggestion is not only much easier, it opens up a completely new way for me to use dropdown selectors in other areas of my config. I have marked your final update as a solution and appreciate the simple approach answer.

One thing to be aware of when using the input_select.set_options service is that the values do not survive restart. You may also want to check out Template select entities (1, 2).