WLED Script to alternate between effects every 5 minutes

tl;dr
I broke my HA setup by updating, switched to WLED and need help converting one of my automations:

  - alias: Swap led effects 
    initial_state: on 
    trigger:
      platform: time 
      seconds: '/5'
    condition:
      condition: state
      entity_id: light.holiday_lights
      state: 'on' 
    action:
      service: input_select.select_option
      data_template:
        entity_id: input_select.holiday_led_effect
        option: >
          {% if is_state('input_select.holiday_led_effect' , 'Halloween') %} Halloween_Eyes
          {% else %} Halloween {% endif %}

A few years ago, I got my HA all set up and running using this guide:

With help from some of the folks here, I created an automation to alternate between a specific set of effects every 5 minutes when activated and light state was on.

My original post here:

My raw script here:
https://gist.githubusercontent.com/mf-social/a3914701aa2344f78edc8f956a7bc864/raw/50750752b0c614b9f8d021ad78df1682d26591c7/automations.yaml

About a week ago, I finally pulled the trigger on my HA update and it broke everything. I was unable to recover any of my previous scripts. Since I lost my previous setup, I decided to start fresh with WLED. Thankfully, the script above was preserved on this site. However, it doesnā€™t seem to work with WLED.

Hoping for some guidance on adapting it to work with WLED. Iā€™m finding the UI of HA to be confusing, but if a UI solution for this exists, Iā€™m happy to use it. Otherwise, yaml.

Hereā€™s the piece I need help converting:

  - alias: Swap led effects 
    initial_state: on 
    trigger:
      platform: time 
      seconds: '/5'
    condition:
      condition: state
      entity_id: light.holiday_lights
      state: 'on' 
    action:
      service: input_select.select_option
      data_template:
        entity_id: input_select.holiday_led_effect
        option: >
          {% if is_state('input_select.holiday_led_effect' , 'Halloween') %} Halloween_Eyes
          {% else %} Halloween {% endif %}

As I understand it, ā€œinitial_stateā€ is no longer a thing in the latest version of HA, so Iā€™ll remove that, ā€œentity_idā€ becomes light.wled

So, factoring in those changes:

  - alias: Swap led effects 
    trigger:
      platform: time 
      seconds: '/5'
    condition:
      condition: state
      entity_id: light.wled
      state: 'on' 
    action:
      service: input_select.select_option
      data_template:
        entity_id: light.wled
        option: >
          {% if is_state('input_select.holiday_led_effect' , 'Halloween') %} Halloween_Eyes
          {% else %} Halloween {% endif %}

However, still not working. Guessing thereā€™s probably an issue with indentation. Also, seems like the method for triggering WLED effects may be different as well. Using this doc as a guide: WLED - Home Assistant. Looks like ā€œeffectā€ is what I need, but it doesnā€™t seem to give any examples of what Iā€™m trying to doā€¦orā€¦at all.

Itā€™s probably an easy fix, but all I keep getting is safe modeā€¦ Thanks in advance.

Do the effects still work when you change the input_select manually? I suspect that the scripts that run on that change are what will need to be converted, all the automations from the other thread did was change the input select every 5 minutes and turn things off at midnight.

I can manually change like this, if thatā€™s what you mean:

There may be other stuff in this script thatā€™s no longer needed, out of place, etc. I just donā€™t know the syntax for controlling WLED effects programmatically.

By the way, felt a sense of relief when I saw that youā€™re still around. haha

1 Like

No, I guess there was previously a ā€˜packageā€™ on your system that contained other pre-built automations. One of these automations will have been monitoring the input_select so that when you changed the name of the effect, it forwarded the new data to your led strips and they changed what they were doing.

Nothing we did in the last thread spoke to the leds, all we did was change the input_select so that the other automations you had would update the leds.

Iā€™m thinking that it is the package that needs updating to reflect the new hardware / new entity_id etc.

Iā€™m not sure Iā€™m following. Home assistant can already control turning the lights on and off via automation, so communication is working ok. Iā€™ve excluded those on/off scripts from this script, so theyā€™re separate scripts. I think my issue is not knowing the wled syntax for controlling effects programmatically.

Do you know the syntax for controlling WLED effects? In the script above itā€™s got: service: input_select.select_option. I donā€™t know if thatā€™s available to WLED or not. Itā€™s also got input_select.holiday_led_effect, which Iā€™m thinking should be changed to input_select.wled, maybe?

Yes, home assistant can control the led strips, but in the other thread we only referenced the led strips when they were switching them off.

With regards to setting the ā€˜effectsā€™ all we did was change the value of an input_select (which is basically a drop down menu).

That means that elsewhere in your configuration you must have had another automation that reacted to the selected option in the input_select and forwarded it appropriate commands in your led strip. It is that automation (and any associated scripts/automations/helpers) that would need to be updated.

Looking at the description for the YouTube video you posted in the OP there is literally thousands of lines of yaml automations that he used to create those effects, so you must have copy-pasted it previously otherwise you wouldnā€™t have had anything working.

Unfortunately Iā€™m not in a position to pick through it and work out which parts are relevant to you now that you have changed hardware, work out what commands need changing to accommodate the new hardware, which bits are irrelevant for the new hardware etc.

Iā€™m certain this is all doable, but the code referred to in the description of the YouTube video looks very specific to the hardware you had originally and it will take some reviewing to convert it.

Maybe I confused things by including that video. Thought the context might help. Iā€™m using NONE of the code from the video. The only changes Iā€™ve made are wiping HA and installing the latest version, installing the wled add on in HA, wiping the previous install of whatever holiday effects .ino the video above provided and replacing it with the wled software. No hardware changes. The video above is irrelevant to this effort. :slight_smile:

Wled is integrated into HA. Hope that helps. :slight_smile:

OK, so what do you want the automation to do?

Just move between the prebuilt (included with wled) Halloween wled effects every 5 minutes

But you donā€™t have any pre-built halloween effects, because youā€™re not using the code from the video which ā€˜pre-builtā€™ them :man_shrugging:

Hang on (itā€™s been a long day :see_no_evil:)

Are you just wanting to randomly change the effect on the leds every 5 minutes using the built-in ones that homeassistant provides?

If so, youā€™ll need the exact names of the effects from that drop down box you screenshot above and do something like thisā€¦

  - alias: Swap led effects 
    trigger:
      platform: time 
      minutes: '/5'
    condition:
      condition: state
      entity_id: light.wled
      state: 'on' 
    action:
      service: light.turn_on
      data_template:
        entity_id: light.wled
        effect: >
          {{
            [ 
              "colorloop",
              "strobe",
              "police"
            ] | random
          }}

(obviously changing ā€œcolorloopā€, ā€œstrobeā€, ā€œpoliceā€ to the list of the actual effects that you made)

Wled has MANY prebuilt in effects:

In case itā€™s not clear, wled is the software that goes on the board. Itā€™s integrated in HA via add on so you can control it. Iā€™m not clear if you have experience with wled automation in HA or not, but Iā€™m grateful for the responses. I have none. :slight_smile:

Right, but how do you change those effects when you want to manually? Is it in the drop down box that you screenshot above?

Yes, effects are in the drop down box. Iā€™m attempting to apply your example now. Iā€™ll report back.

Copied and pasted your code into my automations.yaml. Literally the only code in there. Got this error when running config check. Maybe ā€œminutesā€ is another thing removed from newer HA?
config

Change

platform: time

To

platform: time_pattern 

No errors. Rebooting now.

1 Like

No errors reporting using config check, but this shows in the UI:

Either way - itā€™s working! Thank you!

What is that | random at the end?

1 Like

So every 5 minutes the service will run and randomly pick either colorloop, strobe or police to send to the leds as the effect (of course it could pick the one itā€™s already on so there would be no change at that interval).

Make sure that the effects exactly match the ones you want to use from the drop down box that you have for your led, I just plucked those three out of thin air.

Changed and working beautifully. If I wanted them to change in succession and not randomly, is that possible? If itā€™s too difficult, Iā€™m perfectly satisfied with this.

1 Like