WLED and Presets / Select

In the latest version (2021.8) the wled set preset service is being deprecated. Its been replaced with a more flexible “select” entity and service. I use presets with my WLED devices quite a lot - and particularly through Node Red - set them to a variety of states depending on events. I couldn’t immediately see a clear example of how to quickly make the change …so here it is.

Old Service example…

service: wled.preset
target:
  entity_id: light.wled_server2
data: 
  preset: 3

New Service example…

service: select.select_option
target:
  entity_id: select.wled_server2_preset
data:
  option: Preset 3

Note the option is the name of the Preset - so could be “Blue” etc if thats how you’ve named the presets.

I actually used the fact the original preset service used an integer in Node Red to quickly select a random preset based on a generated random integer. As the select entity has the preset names in a list already, you can use this to template a random selection in HA…

{{ state_attr('select.wled_server2_preset','options') | random }}

In Node Red I can use a current state node to extract the same “options” attribute and pass that through a random-item node (add “node-red-contrib-random-item” to the palette). For that node use “msg.data.attributes.options” as the input and output the (randomly) selected preset name to the payload.
Capture1
A standard service node can use that as normal by using the payload as the text for the option under Data for the service.
Capture2

Hope the above helps someone else looking to make the transition.

9 Likes

Do you happen to use voice control for your WLED’s?

If so, how do you expose the “select.” entity to the voice assistant and use it to select the desired preset?

Thanks for that. I just installed the latest version and this has got me out the hole that I fell into. It was bit of pain because I have about a 15 different calendar events which I use as options to set the WLED presets depending on what is happening on certain days. And I have two WLED controllers for two different sets of lights. So I had to do through and change all the instances of the old code to the new code, and changing from preset numbers to preset names was also a pain. But thanks to your explanation, I manage to get it all sorted eventually.

1 Like

Thanks so much for this - super late to the party but was struggling to find the right way to call my WLEDs (and had previously used Preset numbers!)

I do have a weird issue where I can’t seem to get my presets list to update (i.e. if I change a name), which is frustrating as since I have to use names I am trying to align names so I can pass through msg in node red and can automate instead of numbers… - any ideas how I solve that?

EDIT - seems a restart of the integration is required before it picks up changes

EDIT2: Would love to know how to randomly select between a subset of presets… e.g. I have 3 different Christmas presets - how would I select Xmas 1 / Xmas 2 / Xmas 3 at random?