#Cycle Light Effects via ZigBee button

1 messages · Page 1 of 1 (latest)

cunning matrix
#

I have a Twinkly Christmas Tree and a spare ZigBee button. I'm trying to create an automation where my son can press the button and the tree cycles through it's list of light effects.
I've got the button conditions set up with single press command, but I can't find any way to set the action to cycle through a light effect.
When I say light effects, I mean the ones at the bottom of the light entity screen, as a list. I've attached a screenshot.

Any help?

cunning matrix
#

Ok I've figured it out. I'll put it below in case anyone wants it.

Have the button start a script:

alias: Cycle Effects
sequence:
  - service: light.turn_on
    target:
      entity_id: light.christmas_tree
    data:
      effect: >
        {% set light = 'light.living_room_led' %}
        {% set current = state_attr(light, 'effect') %}
        {% set list = state_attr(light, 'effect_list') %}
        {% if current in list %}
          {% set next_index = (list.index(current) + 1) % list|length %}
          {{ list[next_index] }}
        {% else %}
          {{ list[0] }}
        {% endif %}