Set WLED preset in automation

Hey guys,
I am trying to build an automation to cycle through a list of WLED presets on a remote button press, which I get via select.wled_preset.
I have built 2 templates for this with an input_number that stores the index of the currently selected preset to determine which is the next one. One gives me the new option name and the other the new index.
Setting the new index into the input_number via the input_number.set_value service also works without problems, but I can’t change the WLED preset this way:
Error: Option {{ states('sensor.wled_sofa_next_template_string') }} not valid for Preset
The sensor gives me a matching string which I can select manually in the options

This is my sensor code for getting the new string (new index sensor is basically the same except that it returns only nextOptionIndex):

- sensor:
    - name: 'WLED Sofa nächste Vorlage String'
      state: >
        {% set presetList = state_attr('select.wled_sofa_preset', 'options') %}
        {% set presetListLength = presetList | length | int(0) %}
        {% set currentPresetIndex = states('input_number.sofa_dimmingswitch_presetvalue') | int(0) %}
        {% set presetIndexAddiert = currentPresetIndex+1 %}
        {% set nextOptionIndex = presetIndexAddiert if presetIndexAddiert < presetListLength else 0 %}
        {{presetList[nextOptionIndex] if presetListLength > 0 else "KEINE VORLAGE VORHANDEN" }}
      availability: >
        {{ presetListLength > 0 }}

which returns something like “Dunkelblau” or “Leselicht” without the quotes

and this is the automation part:

alias: Ambilight Sofa Szenenwechsel
description: ""
trigger:
  - platform: device
    domain: mqtt
    device_id: 95b823b2506872a8436be62860282824
    type: action
    subtype: off_press
    discovery_id: 0x001788010bdbc4bb action_off_press
condition: []
action:
  - device_id: c19e395eafd9870ffa2398625eec608b
    domain: select
    entity_id: select.wled_sofa_preset
    type: select_option
    option: "{{ states('sensor.wled_sofa_nachste_vorlage_string') }}"
  - service: input_number.set_value
    data:
      value: "{{ states('sensor.wled_sofa_nachste_vorlage_index') | int(0) }}"
    target:
      entity_id: input_number.sofa_dimmingswitch_presetvalue
mode: single

As a HA newbie I just don’t know what else I could do so help would be awesome :slight_smile:

Device automations don’t support templating.

Use the service instead.

Do yourself a favour and stop using device actions, triggers and conditions. They may seem simpler but they have disadvantages. Lack of templating is just one of them. You’ll discover the other issue if you ever have to replace a device.

1 Like

Thanks for the quick help with the service, I just missed it on the wled integration page :man_facepalming:
I’ve already come across the device trigger disadvantages with a broken Zigbee remote control, so thanks for the tip.