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: https://www.home-assistant.io/integrations/wled/. 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