WLED Countdown Timer

This is a blueprint to do a countdown timer on WLED powered strips. It:

  • makes a new segment (of whatever length you choose)
  • displays a coloured bar on it that gradually grows over the given duration
  • plays another animation for a while to signal the end of the time.

Note: it does require that the WLED devices have MQTT switched on, and the dev_name input needs the MQTT IDs (where the MQTT topic is mqtt//api)

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

File: https://raw.githubusercontent.com/mo-seph/ha_blueprints/refs/heads/main/scripts/countdown_mqtt.yaml

3 Likes

Cool! I just did similar about 2 weeks ago but used Node Red. I only setup a 5 minute version for now but will add 10, 15, and 20 minute versions in near future. They help giving kids time limits or warning until bedtime.

1 Like

Hello dmr,

Thanks for contributing to the community with a new Blueprint.

I have a suggestion for you. Many people who are not familiar with directory structures will have problems installing this without the Home Assistant MY tools.

Adding a MY link for this Blueprint to your top post would help them a lot.

Here is the link to make that.
Create a link – My Home Assistant

1 Like

Done! It’s up on github now, with a button link.

Hi @dmr,

I tried to set this up and it doesn´t work, but I´m pretty sure it´s because I´m doing something wrong, could you please check what I need to change in my setup:

I just found the issue, as I was using WLED-ID instead of only the ID in the field dev_name.

Now that it´s working I have another question. It would be really cool to be able to dinamically set the duration from an automation, for example to say “hey google, set a timer for 7 minutes”, is there any way to do this?

I haven’t looked into this, but scripts can expose variables that are called when they are run, so it should be possible.

1 Like

oh this is awesome, thank you! I have some wled panels around my desktop this is very useful!

:clock3: WLED Countdown Timer — Without MQTT, Using Live View Proxy

Hey everyone :wave:

Just dropping in to share an alternative way to run a countdown timer on WLED without needing MQTT or Node-RED.

I’ve been building a Home Assistant integration called WLED Live View Proxy, and it now supports sending full JSON commands to your WLED devices over WebSocket. Using this, I put together a flexible script that:

:white_check_mark: Reads the LED count dynamically from your WLED segment
:white_check_mark: Displays a smooth green progress bar across the strip
:white_check_mark: Last 10% of LEDs blink red at the end
:white_check_mark: Automatically resets after the timer ends
:white_check_mark: Works with any WLED setup and doesn’t require MQTT

:bulb: No MQTT, no polling, just JSON over WS using wled_liveviewproxy.send_command


:jigsaw: Full YAML Script

alias: WLED Progress with Final Blink and Reset
mode: restart
fields:
  duration:
    name: Timer duration (seconds)
    description: Total time in seconds
    required: true
    selector:
      number:
        min: 1
        max: 600
        unit_of_measurement: sec
  target_light:
    name: WLED Light
    description: Select your WLED light
    required: true
    selector:
      entity:
        domain: light
        integration: wled_liveviewproxy
variables:
  segment_id: 0
  palette: 0
  fx_id: 98
  color1: "00ff00"
  color2: "000000"
  brightness: 255
  flash_color: "ff0000"

sequence:
  - alias: "Request WLED state"
    action: wled_liveviewproxy.send_command
    data:
      targets:
        entity_id: "{{ target_light }}"
      command:
        v: true
    response_variable: wled_state

  - alias: "Prepare variables"
    variables:
      response_key: "{{ wled_state.responses.keys() | list | first }}"
      seg: "{{ wled_state.responses[response_key].state.seg[segment_id] }}"
      led_count: "{{ seg.stop - seg.start }}"
      step_count: "{{ duration | int }}"
      leds_per_step: "{{ 100 / step_count }}"
      last_led_index: "{{ seg.stop - 1 }}"
      flash_leds_count: "{{ (led_count * 0.1) | round(0, 'ceil') }}"
      flash_start_index: "{{ seg.stop - flash_leds_count }}"

  - alias: "Run countdown timer"
    repeat:
      count: "{{ step_count }}"
      sequence:
        - variables:
            current_ix: "{{ ((repeat.index) * leds_per_step) | round(0) }}"
        - alias: "Update progress"
          action: wled_liveviewproxy.send_command
          response_variable: response
          data:
            targets:
              entity_id: "{{ target_light }}"
            command:
              seg:
                - id: "{{ segment_id }}"
                  start: "{{ seg.start }}"
                  stop: "{{ seg.stop }}"
                  fx: "{{ fx_id }}"
                  ix: "{{ [current_ix, 100] | min }}"
                  col: ["{{ color1 }}", "{{ color2 }}"]
                  pal: "{{ palette }}"
                  bri: "{{ brightness }}"
        - delay:
            seconds: 1

  - alias: "Blink last 10% LEDs red"
    repeat:
      count: 4
      sequence:
        - alias: "ON — last 10% in red"
          action: wled_liveviewproxy.send_command
          response_variable: response
          data:
            targets:
              entity_id: "{{ target_light }}"
            command:
              seg:
                - id: "{{ segment_id }}"
                  i: >
                    [
                    {% for i in range(seg.start, flash_start_index) %}
                      {{ i }}, "{{ color1 }}",
                    {% endfor %}
                    {% for i in range(flash_start_index, seg.stop) %}
                      {{ i }}, "{{ flash_color }}",
                    {% endfor %}
                    ]
        - delay:
            milliseconds: 300
        - alias: "OFF — turn off red only"
          action: wled_liveviewproxy.send_command
          response_variable: response
          data:
            targets:
              entity_id: "{{ target_light }}"
            command:
              seg:
                - id: "{{ segment_id }}"
                  i: >
                    [
                    {% for i in range(seg.start, flash_start_index) %}
                      {{ i }}, "{{ color1 }}",
                    {% endfor %}
                    {% for i in range(flash_start_index, seg.stop) %}
                      {{ i }}, "000000",
                    {% endfor %}
                    ]
        - delay:
            milliseconds: 300

  - alias: "Reset effect"
    action: wled_liveviewproxy.send_command
    response_variable: response
    data:
      targets:
        entity_id: "{{ target_light }}"
      command:
        seg:
          - id: "{{ segment_id }}"
            frz: false


:link: Learn More and Join the Discussion

:left_speech_bubble: WLED Live View Proxy for Home Assistant – Forum Thread

Let me know what you think — and if you build something cool with it, I’d love to see it! :rocket:

2 Likes

Love to see that and it works quite straight forward. I do have a question to this: It looks like the LEDs running up with passing time. How can I revers this so that it is more like a countdown? Maybe more clear: starting with a strip fill of 100% going to 0%.

1 Like

If you invert color 1 and color 2, it will do as you want… But the flashing og the entire strip of each count is distracting…

I actually made a little change (sorry, dont mean to hijack it…)
Now, it counts without flashing, you get a few more inputs, and it will reset to default when finished.

alias: WLED Progress with Final Blink and Reset
mode: restart
fields:
  duration:
    name: Timer duration (seconds)
    description: Total time in seconds for the progress effect
    required: true
    selector:
      number:
        min: 1
        max: 600
        unit_of_measurement: sec
    default: 120
  target_light:
    name: WLED Light
    description: Select your WLED light entity
    required: true
    selector:
      entity:
        domain: light
        integration: wled_liveviewproxy
    default: light.wlvp_tvvegg
  progress_color:
    name: Progress Color
    description: Hex color for the progress effect (e.g., 00ff00 for green)
    required: false
    selector:
      text:
    default: "00ff00"
  flash_color:
    name: Flash Color
    description: Hex color for the final blink effect (e.g., ff0000 for red)
    required: false
    selector:
      text:
    default: "ff0000"
  brightness:
    name: Brightness
    description: Brightness level (0-255)
    required: false
    selector:
      number:
        min: 0
        max: 255
    default: 150
variables:
  segment_id: 0
  palette: 0
  background_color: "000000"  # Background/unfilled color
  step_count: "{{ duration | int }}"
  flash_count: 4  # Number of blinks for the final effect
  flash_delay_ms: 300  # Delay for blink effect in milliseconds
  percent_per_step: "{{ (100.0 / step_count) | float }}"  # Percent increase per second
sequence:
  # Request WLED state to get segment information
  - alias: Request WLED state
    action: wled_liveviewproxy.send_command
    data:
      targets:
        entity_id: "{{ target_light }}"
      command:
        v: true
    response_variable: wled_state

  # Validate WLED state response
  - alias: Validate WLED state
    condition: template
    value_template: "{{ wled_state is defined and wled_state.responses is defined }}"

  # Prepare variables for progress and blink effects
  - alias: Prepare variables
    variables:
      response_key: "{{ wled_state.responses.keys() | list | first }}"
      segment: "{{ wled_state.responses[response_key].state.seg[segment_id] }}"
      led_count: "{{ segment.stop - segment.start }}"
      flash_leds_count: "{{ (led_count * 0.1) | round(0, 'ceil') }}"
      flash_start_rel: "{{ led_count - flash_leds_count }}"

  # Validate segment data
  - alias: Validate segment
    condition: template
    value_template: "{{ segment is defined and led_count > 0 }}"

  # Initialize: Set entire segment to background color and solid effect
  - alias: Initialize segment to background
    action: wled_liveviewproxy.send_command
    response_variable: response
    data:
      targets:
        entity_id: "{{ target_light }}"
      command:
        seg:
          - id: "{{ segment_id }}"
            fx: 0
            bri: "{{ brightness }}"
            i:
              - 0
              - "{{ led_count }}"
              - "{{ background_color }}"

  # Run progress effect incrementally
  - alias: Run countdown timer
    repeat:
      count: "{{ step_count }}"
      sequence:
        - variables:
            previous_percent: "{{ ((repeat.index - 1) * percent_per_step) | round(0, 'floor') }}"
            current_percent: "{{ (repeat.index * percent_per_step) | round(0, 'floor') }}"
            previous_leds_lit: "{{ (previous_percent / 100 * led_count) | round(0, 'floor') }}"
            current_leds_lit: "{{ (current_percent / 100 * led_count) | round(0, 'floor') }}"
        - alias: Update delta LEDs if changed
          condition: template
          value_template: "{{ current_leds_lit > previous_leds_lit }}"
        - action: wled_liveviewproxy.send_command
          response_variable: response
          data:
            targets:
              entity_id: "{{ target_light }}"
            command:
              seg:
                - id: "{{ segment_id }}"
                  i:
                    - "{{ previous_leds_lit }}"
                    - "{{ current_leds_lit }}"
                    - "{{ progress_color }}"
        - delay:
            seconds: 1

  # Blink last 10% of LEDs
  - alias: Blink last 10% LEDs
    repeat:
      count: "{{ flash_count }}"
      sequence:
        # Turn on flash color for last 10% of LEDs (keep first as progress color)
        - alias: ON - Flash last 10% in specified color
          action: wled_liveviewproxy.send_command
          response_variable: response
          data:
            targets:
              entity_id: "{{ target_light }}"
            command:
              seg:
                - id: "{{ segment_id }}"
                  i:
                    - 0
                    - "{{ flash_start_rel }}"
                    - "{{ progress_color }}"
                    - "{{ flash_start_rel }}"
                    - "{{ led_count }}"
                    - "{{ flash_color }}"
        - delay:
            milliseconds: "{{ flash_delay_ms }}"
        # Turn off flash color (set to background, keep first as progress)
        - alias: OFF - Reset flash LEDs to background
          action: wled_liveviewproxy.send_command
          response_variable: response
          data:
            targets:
              entity_id: "{{ target_light }}"
            command:
              seg:
                - id: "{{ segment_id }}"
                  i:
                    - 0
                    - "{{ flash_start_rel }}"
                    - "{{ progress_color }}"
                    - "{{ flash_start_rel }}"
                    - "{{ led_count }}"
                    - "{{ background_color }}"
        - delay:
            milliseconds: "{{ flash_delay_ms }}"

  # Reset to original state
  - alias: Reset WLED segment
    action: wled_liveviewproxy.send_command
    response_variable: response
    data:
      targets:
        entity_id: "{{ target_light }}"
      command:
        seg:
          - id: "{{ segment_id }}"
            frz: false
            fx: "{{ segment.fx | default(0) }}"
            pal: "{{ segment.pal | default(0) }}"
            bri: "{{ segment.bri | default(255) }}"
description: Displays an incremental progress bar on a WLED light (without full redraw flicker), followed by a blinking effect on the last 10% of LEDs, and resets to the original state.
1 Like

A slight modification again.
Now the whole strip flashes red. And there is a switch to select counting up or counting down :slight_smile:

alias: WLED Progress with Direction, Full Strip Blink, and Reset
mode: restart
fields:
  duration:
    name: Timer duration (seconds)
    description: Total time in seconds for the progress effect
    required: true
    selector:
      number:
        min: 1
        max: 600
        unit_of_measurement: sec
    default: 120
  target_light:
    name: WLED Light
    description: Select your WLED light entity
    required: true
    selector:
      entity:
        domain: light
        integration: wled_liveviewproxy
    default: light.wlvp_tvvegg
  progress_color:
    name: Progress Color
    description: Hex color for the progress effect (e.g., 00ff00 for green)
    required: false
    selector:
      text: null
    default: ff0f93
  flash_color:
    name: Flash Color
    description: Hex color for the final blink effect (e.g., ff0000 for red)
    required: false
    selector:
      text: null
    default: ff0000
  brightness:
    name: Brightness
    description: Brightness level (0-255)
    required: false
    selector:
      number:
        min: 0
        max: 255
    default: 150
  direction:
    name: Count Direction
    description: True to count up (fill LEDs), False to count down (empty LEDs)
    required: false
    selector:
      boolean:
    default: true
variables:
  segment_id: 0
  palette: 0
  background_color: "000000"
  step_count: "{{ duration | int }}"
  flash_count: 4
  flash_delay_ms: 300
  percent_per_step: "{{ (100.0 / step_count) | float }}"
sequence:
  # Request WLED state to get segment information
  - alias: Request WLED state
    action: wled_liveviewproxy.send_command
    data:
      targets:
        entity_id: "{{ target_light }}"
      command:
        v: true
    response_variable: wled_state
  # Validate WLED state response
  - alias: Validate WLED state
    condition: template
    value_template: "{{ wled_state is defined and wled_state.responses is defined }}"
  # Prepare variables
  - alias: Prepare variables
    variables:
      response_key: "{{ wled_state.responses.keys() | list | first }}"
      segment: "{{ wled_state.responses[response_key].state.seg[segment_id] }}"
      led_count: "{{ segment.stop - segment.start }}"
  # Validate segment
  - alias: Validate segment
    condition: template
    value_template: "{{ segment is defined and led_count > 0 }}"
  # Initialize segment based on direction
  - alias: Initialize segment
    action: wled_liveviewproxy.send_command
    response_variable: response
    data:
      targets:
        entity_id: "{{ target_light }}"
      command:
        seg:
          - id: "{{ segment_id }}"
            fx: 0
            bri: "{{ brightness }}"
            i:
              - 0
              - "{{ led_count }}"
              - "{{ progress_color if not direction else background_color }}"
  # Run progress timer
  - alias: Run progress timer
    repeat:
      count: "{{ step_count }}"
      sequence:
        - variables:
            previous_percent: "{{ ((repeat.index - 1) * percent_per_step) | round(0, 'floor') }}"
            current_percent: "{{ (repeat.index * percent_per_step) | round(0, 'floor') }}"
            previous_leds_lit: "{{ (previous_percent / 100 * led_count) | round(0, 'floor') }}"
            current_leds_lit: "{{ (current_percent / 100 * led_count) | round(0, 'floor') }}"
            start_index: "{{ led_count - current_leds_lit if not direction else previous_leds_lit }}"
            end_index: "{{ led_count if not direction else current_leds_lit }}"
            update_color: "{{ background_color if not direction else progress_color }}"
        - alias: Update delta LEDs if changed
          condition: template
          value_template: "{{ current_leds_lit > previous_leds_lit }}"
        - action: wled_liveviewproxy.send_command
          response_variable: response
          data:
            targets:
              entity_id: "{{ target_light }}"
            command:
              seg:
                - id: "{{ segment_id }}"
                  i:
                    - "{{ start_index }}"
                    - "{{ end_index }}"
                    - "{{ update_color }}"
        - delay:
            seconds: 1
  # Blink entire strip
  - alias: Blink entire strip
    repeat:
      count: "{{ flash_count }}"
      sequence:
        - alias: ON - Flash entire strip in specified color
          action: wled_liveviewproxy.send_command
          response_variable: response
          data:
            targets:
              entity_id: "{{ target_light }}"
            command:
              seg:
                - id: "{{ segment_id }}"
                  i:
                    - 0
                    - "{{ led_count }}"
                    - "{{ flash_color }}"
        - delay:
            milliseconds: "{{ flash_delay_ms }}"
        - alias: OFF - Reset entire strip to background
          action: wled_liveviewproxy.send_command
          response_variable: response
          data:
            targets:
              entity_id: "{{ target_light }}"
            command:
              seg:
                - id: "{{ segment_id }}"
                  i:
                    - 0
                    - "{{ led_count }}"
                    - "{{ background_color }}"
        - delay:
            milliseconds: "{{ flash_delay_ms }}"
  # Reset WLED segment
  - alias: Reset WLED segment
    action: wled_liveviewproxy.send_command
    response_variable: response
    data:
      targets:
        entity_id: "{{ target_light }}"
      command:
        seg:
          - id: "{{ segment_id }}"
            frz: false
            fx: "{{ segment.fx | default(0) }}"
            pal: "{{ segment.pal | default(0) }}"
            bri: "{{ segment.bri | default(255) }}"
description: >-
  Displays an incremental progress bar on a WLED light (without full redraw
  flicker), filling up or emptying based on direction (true for up, false for down),
  followed by a blinking effect on the entire strip, and resets to the original state.
1 Like

I’ve added an extra option.
know you have “direction” and “count up”

LED Direction
true = L←R, false = L→R

Count Up
true = fill LEDs, false = empty LEDs

alias: WLED Progress
mode: restart
fields:
  duration:
    name: Timer duration (seconds)
    required: true
    selector:
      number:
        min: 1
        max: 600
        unit_of_measurement: sec
    default: 120
  target_light:
    name: WLED Light
    required: true
    selector:
      entity:
        domain: light
        integration: wled_liveviewproxy
  progress_color:
    name: Progress Color
    selector:
      text: null
    default: ff0f93
  flash_color:
    name: Flash Color
    selector:
      text: null
    default: ff0000
  brightness:
    name: Brightness
    selector:
      number:
        min: 0
        max: 255
    default: 150
  direction:
    name: LED Direction
    description: true = L←R, false = L→R
    selector:
      boolean: null
    default: true
  count_up:
    name: Count Up
    description: true = fill LEDs, false = empty LEDs
    selector:
      boolean: null
    default: true
variables:
  segment_id: 0
  background_color: "000000"
  step_count: "{{ duration | int }}"
  flash_count: 4
  flash_delay_ms: 300
  percent_per_step: "{{ (100.0 / step_count) | float }}"
sequence:
  - alias: Request WLED state
    action: wled_liveviewproxy.send_command
    response_variable: wled_state
    data:
      targets:
        entity_id: "{{ target_light }}"
      command:
        v: true
  - alias: Validate WLED state
    condition: template
    value_template: |
      {{ wled_state is defined
         and wled_state.responses is defined
         and (wled_state.responses.values() | list)[0] is not none }}
  - alias: Prepare variables
    variables:
      response_key: "{{ wled_state.responses.keys() | list | first }}"
      raw_response: "{{ wled_state.responses[response_key] }}"
      segment: "{{ raw_response.state.seg[segment_id] }}"
      led_count: "{{ segment.stop - segment.start }}"
  - alias: Validate segment
    condition: template
    value_template: "{{ led_count > 0 }}"
  - alias: Initialize segment
    action: wled_liveviewproxy.send_command
    response_variable: init_response
    data:
      targets:
        entity_id: "{{ target_light }}"
      command:
        seg:
          - id: "{{ segment_id }}"
            fx: 0
            bri: "{{ brightness }}"
            i:
              - 0
              - "{{ led_count }}"
              - "{{ background_color }}"
  - alias: Run progress timer
    repeat:
      count: "{{ step_count }}"
      sequence:
        - variables:
            prev_percent: "{{ ((repeat.index - 1) * percent_per_step) | round(0,'floor') }}"
            curr_percent: "{{ (repeat.index * percent_per_step) | round(0,'floor') }}"
            prev_leds: |
              {{ (prev_percent / 100 * led_count) | round(0,'floor')
                  if count_up
                  else (led_count - (prev_percent / 100 * led_count) | round(0,'floor')) }}
            curr_leds: |
              {{ (curr_percent / 100 * led_count) | round(0,'floor')
                  if count_up
                  else (led_count - (curr_percent / 100 * led_count) | round(0,'floor')) }}
            lit_start: |
              {{ 
                (0 if count_up else (led_count - curr_leds))
                if direction 
                else (led_count - curr_leds if count_up else 0)
              }}
            lit_end: |
              {{ 
                (curr_leds if count_up else led_count)
                if direction 
                else (led_count if count_up else curr_leds)
              }}
            off_start: |
              {{
                (curr_leds if count_up else 0)
                if direction
                else (0 if count_up else curr_leds)
              }}
            off_end: |
              {{
                (led_count if count_up else (led_count - curr_leds))
                if direction
                else ((led_count - curr_leds) if count_up else led_count)
              }}
        - alias: Update LEDs if changed
          condition: template
          value_template: "{{ curr_leds != prev_leds }}"
        - variables:
            led_update_array: |
              {% set arr = [] %} {% if off_start < off_end %}
                {% set arr = arr + [off_start, off_end, background_color] %}
              {% endif %} {% if lit_start < lit_end %}
                {% set arr = arr + [lit_start, lit_end, progress_color] %}
              {% endif %} {{ arr }}
        - alias: Send single update to WLED
          action: wled_liveviewproxy.send_command
          response_variable: update_response
          data:
            targets:
              entity_id: "{{ target_light }}"
            command:
              seg:
                - id: "{{ segment_id }}"
                  i: "{{ led_update_array }}"
        - delay:
            seconds: 1
  - alias: Blink entire strip
    repeat:
      count: "{{ flash_count }}"
      sequence:
        - alias: Flash ON
          action: wled_liveviewproxy.send_command
          response_variable: flash_on_response
          data:
            targets:
              entity_id: "{{ target_light }}"
            command:
              seg:
                - id: "{{ segment_id }}"
                  i:
                    - 0
                    - "{{ led_count }}"
                    - "{{ flash_color }}"
        - delay:
            milliseconds: "{{ flash_delay_ms }}"
        - alias: Flash OFF
          action: wled_liveviewproxy.send_command
          response_variable: flash_off_response
          data:
            targets:
              entity_id: "{{ target_light }}"
            command:
              seg:
                - id: "{{ segment_id }}"
                  i:
                    - 0
                    - "{{ led_count }}"
                    - "{{ background_color }}"
        - delay:
            milliseconds: "{{ flash_delay_ms }}"
  - alias: Reset WLED segment
    action: wled_liveviewproxy.send_command
    response_variable: reset_response
    data:
      targets:
        entity_id: "{{ target_light }}"
      command:
        seg:
          - id: "{{ segment_id }}"
            frz: false
            fx: "{{ segment.fx }}"
            pal: "{{ segment.pal }}"
            bri: "{{ segment.bri }}"

1 Like

If I set a short timer e.g. 10 seconds, it is fine. But if I increase the duration of the timer the progress bar is “faster”. This results in a 10 minute timer that has finished after 8 mins.

I can’t find the issue though. Is this a limitation of the integration since there are might some instabilities in the connection that sum up over time? My script is here:

alias: WLED Timer
mode: restart
fields:
  duration:
    name: Timer duration (seconds)
    required: true
    selector:
      number:
        min: 1
        max: 6000
        unit_of_measurement: sec
  target_light:
    name: WLED Light
    required: true
    selector:
      entity:
        domain: light
        integration: wled_liveviewproxy
    default: light.wlvp_wled
  progress_color:
    name: Progress Color
    selector:
      text: null
    default: 00ff00
  flash_color:
    name: Flash Color
    selector:
      text: null
    default: 00ff00
  brightness:
    name: Brightness
    selector:
      number:
        min: 0
        max: 255
    default: 150
  direction:
    name: LED Direction
    description: true = L←R, false = L→R
    selector:
      boolean: null
    default: false
  count_up:
    name: Count Up
    description: true = fill LEDs, false = empty LEDs
    selector:
      boolean: null
    default: true
variables:
  segment_id: 0
  background_color: "ff0000"
  step_count: "{{ duration | int }}"
  flash_count: 4
  flash_delay_ms: 300
  percent_per_step: "{{ (100.0 / step_count) | float }}"
sequence:
  - alias: Request WLED state
    action: wled_liveviewproxy.send_command
    response_variable: wled_state
    data:
      targets:
        entity_id: "{{ target_light }}"
      command:
        v: true
  - alias: Validate WLED state
    condition: template
    value_template: |
      {{ wled_state is defined
         and wled_state.responses is defined
         and (wled_state.responses.values() | list)[0] is not none }}
  - alias: Prepare variables
    variables:
      response_key: "{{ wled_state.responses.keys() | list | first }}"
      raw_response: "{{ wled_state.responses[response_key] }}"
      segment: "{{ raw_response.state.seg[segment_id] }}"
      led_count: "{{ segment.stop - segment.start }}"
      t_hold: "{{ (duration | float) / led_count }}"
  - alias: Validate segment
    condition: template
    value_template: "{{ led_count > 0 }}"
  - alias: Initialize segment
    action: wled_liveviewproxy.send_command
    response_variable: init_response
    data:
      targets:
        entity_id: "{{ target_light }}"
      command:
        seg:
          - id: "{{ segment_id }}"
            fx: 0
            bri: "{{ brightness }}"
            i:
              - 0
              - "{{ led_count }}"
              - "{{ background_color }}"
  - alias: Run progress timer
    repeat:
      count: "{{ step_count }}"
      sequence:
        - variables:
            prev_percent: "{{ ((repeat.index - 1) * percent_per_step) | round(0,'floor') }}"
            curr_percent: "{{ (repeat.index * percent_per_step) | round(0,'floor') }}"
            prev_leds: |
              {{ (prev_percent / 100 * led_count) | round(0,'floor')
                  if count_up
                  else (led_count - (prev_percent / 100 * led_count) | round(0,'floor')) }}
            curr_leds: |
              {{ (curr_percent / 100 * led_count) | round(0,'floor')
                  if count_up
                  else (led_count - (curr_percent / 100 * led_count) | round(0,'floor')) }}
            lit_start: |
              {{ 
                (0 if count_up else (led_count - curr_leds))
                if direction 
                else (led_count - curr_leds if count_up else 0)
              }}
            lit_end: |
              {{ 
                (curr_leds if count_up else led_count)
                if direction 
                else (led_count if count_up else curr_leds)
              }}
            off_start: |
              {{
                (curr_leds if count_up else 0)
                if direction
                else (0 if count_up else curr_leds)
              }}
            off_end: |
              {{
                (led_count if count_up else (led_count - curr_leds))
                if direction
                else ((led_count - curr_leds) if count_up else led_count)
              }}
        - alias: Update LEDs if changed
          condition: template
          value_template: "{{ curr_leds != prev_leds }}"
        - variables:
            led_update_array: |
              {% set arr = [] %} {% if off_start < off_end %}
                {% set arr = arr + [off_start, off_end, background_color] %}
              {% endif %} {% if lit_start < lit_end %}
                {% set arr = arr + [lit_start, lit_end, progress_color] %}
              {% endif %} {{ arr }}
        - alias: Send single update to WLED
          action: wled_liveviewproxy.send_command
          response_variable: update_response
          data:
            targets:
              entity_id: "{{ target_light }}"
            command:
              seg:
                - id: "{{ segment_id }}"
                  i: "{{ led_update_array }}"
        - delay:
            seconds: "{{ t_hold }}"
  - alias: Blink entire strip
    repeat:
      count: "{{ flash_count }}"
      sequence:
        - alias: Flash ON
          action: wled_liveviewproxy.send_command
          response_variable: flash_on_response
          data:
            targets:
              entity_id: "{{ target_light }}"
            command:
              seg:
                - id: "{{ segment_id }}"
                  i:
                    - 0
                    - "{{ led_count }}"
                    - "{{ flash_color }}"
        - delay:
            milliseconds: "{{ flash_delay_ms }}"
        - alias: Flash OFF
          action: wled_liveviewproxy.send_command
          response_variable: flash_off_response
          data:
            targets:
              entity_id: "{{ target_light }}"
            command:
              seg:
                - id: "{{ segment_id }}"
                  i:
                    - 0
                    - "{{ led_count }}"
                    - "000000"
        - delay:
            milliseconds: "{{ flash_delay_ms }}"
            
  - alias: Reset WLED segment
    action: wled_liveviewproxy.send_command
    response_variable: reset_response
    data:
      targets:
        entity_id: "{{ target_light }}"
      command:
        seg:
          - id: "{{ segment_id }}"
            frz: false
            fx: "{{ segment.fx }}"
            pal: "{{ segment.pal }}"
            bri: "{{ segment.bri }}"


  - alias: "Reset effect"
    action: wled_liveviewproxy.send_command
    response_variable: response
    data:
      targets:
        entity_id: "{{ target_light }}"
      command:
        seg:
          - id: "{{ segment_id }}"
            frz: false
type or paste code here