How to: Select random WLED preset from provided list in the Automation

My current attempt:

alias: Holiday_Lights-Halloween
description: ""
trigger:
  - platform: calendar
    entity_id: calendar.halloween_holiday
condition:
  - condition: sun
    after: sunset
    after_offset: "-00:45:00"
    enabled: false
action:
  - if:
      - condition: state
        entity_id: calendar.halloween_holiday
        state: "on"
    then:
      - device_id: <wled_holiday_lights_device_UUID>
        domain: select
        entity_id: <wled_holiday_lights_entity_UUID>
        type: select_option
        option: "{{['Halloween_1','Halloween_2','Halloween_3','Halloween_4']|random}}"
mode: single

I am getting this error:

Error: Option {{[‘Halloween_1’,‘Halloween_2’,‘Halloween_3’,‘Halloween_4’]|random}} is not valid for entity select.wled_holiday_lights_preset, valid options are: …, Halloween_1, Halloween_2, Halloween_3, Halloween_4, …

I have tried a few different approaches this this. For example, tried variables as demoed in this thread: https://community.home-assistant.io/t/random-choice-in-automations-and-scripts/705783/11

This thread asks the same question, but about a different outcome: https://community.home-assistant.io/t/can-an-automation-randomly-select-from-a-list-during-action/315718/2

Interestingly, this post asks a very similar question in the last post, but with no answer: https://community.home-assistant.io/t/wled-and-presets-select/326901

This post on Reddit was almost exactly what I was trying to accomplish:
https://www.reddit.com/r/homeassistant/comments/17d1d0g/randomized_automation_action_data_help/

Their solution is the one I have left in my code, since it seems to be the closest to the solution, but it is resulting in the above error.

If I just do

    option: Halloween_1

The automation works fine.

Device actions (and device triggers and device conditions) are intended for composing with the UI and don’t accept templates.

Use an action instead.

And for that matter, never use device triggers/conditions/actions for anything, ever.

Thanks for responding, however I don’t understand what you mean here:

“never use device triggers/conditions/actions for anything”

I feel like majority of my automations use one of those three.

Following on why not to use device_ids though, that makes sense.

Perhaps my statement wasn’t clear, it should be to never use device triggers, device conditions, or device actions. Those will all use device_id’s.

Ahhhh, gotcha, that makes much more sense, thanks!

1 Like