Wled Random effects

Hi,

I have been trying to create an automation to select a random Wled effect each time it is called.

This is my current automation (non-random)

- id: '1575326339804'
  alias: CarPresence_ON
  description: ''
  trigger:
  - entity_id: binary_sensor.carpresence
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
   - data:
       effect: '[FX=44] Merry Christmas'
       entity_id: light.wled_lights
     service: light.turn_on

To generate the random number effect I used this code

sensor:
  - platform: random
    name: Random Effect
    minimum: 0
    maximum: 82

Then I updated my automation to add the random effect

- id: '1575326339804'
  alias: CarPresence_ON
  description: ''
  trigger:
  - entity_id: binary_sensor.carpresence
    from: 'off'
    platform: state
    to: 'on'
  condition: []
 action:
  - service: mqtt.publish
    data_template:
      topic: wled/all/api
      payload: FX={{ states("sensor.random_effect") }}

But it doesn’t work! From what I can work out Wled likes the effect formatted like this effect: ‘[FX=00] Solid’ instead of FX=00
I have googled but I cannot find an example of this, can anyone help?

Regards
James

Try this:

 action:
  - service: mqtt.publish
    data_template:
      topic: wled/all/api
      payload: "{{ ['[FX=00] Solid','[FX=01] Blink','[FX=02] Breathe','[FX=03] Wipe','[FX=04] Wipe Random','[FX=05] Random Colors','[FX=06] Sweep','[FX=07] Dynamic','[FX=08] Colorloop','[FX=09] Rainbow','[FX=10] Scan','[FX=11] Dual Scan','[FX=12] Fade','[FX=13] Chase','[FX=14] Chase Rainbow','[FX=15] Running','[FX=16] Saw','[FX=17] Twinkle','[FX=18] Dissolve','[FX=19] Dissolve Rnd','[FX=20] Sparkle','[FX=21] Dark Sparkle','[FX=22] Sparkle+','[FX=23] Strobe','[FX=24] Strobe Rainbow','[FX=25] Mega Strobe','[FX=26] Blink Rainbow','[FX=27] Android','[FX=28] Chase','[FX=29] Chase Random','[FX=30] Chase Rainbow','[FX=31] Chase Flash','[FX=32] Chase Flash Rnd','[FX=33] Rainbow Runner','[FX=34] Colorful','[FX=35] Traffic Light','[FX=36] Sweep Random','[FX=37] Running 2','[FX=38] Red & Blue','[FX=39] Stream','[FX=40] Scanner','[FX=41] Lighthouse','[FX=42] Fireworks','[FX=43] Rain','[FX=44] Merry Christmas','[FX=45] Fire Flicker','[FX=46] Gradient','[FX=47] Loading','[FX=48] In Out','[FX=49] In In','[FX=50] Out Out','[FX=51] Out In','[FX=52] Circus','[FX=53] Halloween','[FX=54] Tri Chase','[FX=55] Tri Wipe','[FX=56] Tri Fade','[FX=57] Lightning','[FX=58] ICU','[FX=59] Multi Comet','[FX=60] Dual Scanner','[FX=61] Stream 2','[FX=62] Oscillate','[FX=63] Pride 2015','[FX=64] Juggle','[FX=65] Palette','[FX=66] Fire 2012','[FX=67] Colorwaves','[FX=68] BPM','[FX=69] Fill Noise','[FX=70] Noise 1','[FX=71] Noise 2','[FX=72] Noise 3','[FX=73] Noise 4','[FX=74] Colortwinkle','[FX=75] Lake','[FX=76] Meteor','[FX=77] Smooth Meteor','[FX=78] Railway','[FX=79] Ripple','[FX=80] Twinklefox','[FX=81] Twinklecat','[FX=82] Halloween Eyes']|random }}"

If it works you can delete your random sensor.

This is my random effect script, it randomises the effect, pallet and speed:

wled_random:
  alias: 'Randomise'
  sequence:
  - service: mqtt.publish
    data_template:
      topic: wled/bar_led/api
      payload: "{{ ['[FX=00] Solid','[FX=01] Blink','[FX=02] Breathe','[FX=03] Wipe','[FX=04] Wipe Random','[FX=05] Random Colors','[FX=06] Sweep','[FX=07] Dynamic','[FX=08] Colorloop','[FX=09] Rainbow','[FX=10] Scan','[FX=11] Dual Scan','[FX=12] Fade','[FX=13] Chase','[FX=14] Chase Rainbow','[FX=15] Running','[FX=16] Saw','[FX=17] Twinkle','[FX=18] Dissolve','[FX=19] Dissolve Rnd','[FX=20] Sparkle','[FX=21] Dark Sparkle','[FX=22] Sparkle+','[FX=23] Strobe','[FX=24] Strobe Rainbow','[FX=25] Mega Strobe','[FX=26] Blink Rainbow','[FX=27] Android','[FX=28] Chase','[FX=29] Chase Random','[FX=30] Chase Rainbow','[FX=31] Chase Flash','[FX=32] Chase Flash Rnd','[FX=33] Rainbow Runner','[FX=34] Colorful','[FX=35] Traffic Light','[FX=36] Sweep Random','[FX=37] Running 2','[FX=38] Red & Blue','[FX=39] Stream','[FX=40] Scanner','[FX=41] Lighthouse','[FX=42] Fireworks','[FX=43] Rain','[FX=44] Merry Christmas','[FX=45] Fire Flicker','[FX=46] Gradient','[FX=47] Loading','[FX=48] In Out','[FX=49] In In','[FX=50] Out Out','[FX=51] Out In','[FX=52] Circus','[FX=53] Halloween','[FX=54] Tri Chase','[FX=55] Tri Wipe','[FX=56] Tri Fade','[FX=57] Lightning','[FX=58] ICU','[FX=59] Multi Comet','[FX=60] Dual Scanner','[FX=61] Stream 2','[FX=62] Oscillate','[FX=63] Pride 2015','[FX=64] Juggle','[FX=65] Palette','[FX=66] Fire 2012','[FX=67] Colorwaves','[FX=68] BPM','[FX=69] Fill Noise','[FX=70] Noise 1','[FX=71] Noise 2','[FX=72] Noise 3','[FX=73] Noise 4','[FX=74] Colortwinkle','[FX=75] Lake','[FX=76] Meteor','[FX=77] Smooth Meteor','[FX=78] Railway','[FX=79] Ripple','[FX=80] Twinklefox','[FX=81] Twinklecat','[FX=82] Halloween Eyes']|random }}"
  - service: mqtt.publish
    data_template:
      topic: wled/bar_led/api
      payload: "{{ ['[FP=00] Default','[FP=01] Random Cycle','[FP=02] Primary color','[FP=03] Based on primary','[FP=04] Set colors','[FP=05] Based on set','[FP=06] Party','[FP=07] Cloud','[FP=08] Lava','[FP=09] Ocean','[FP=10] Forest','[FP=11] Rainbow','[FP=12] Rainbow bands','[FP=13] Sunset','[FP=14] Rivendell','[FP=15] Breeze','[FP=16] Red & Blue','[FP=17] Yellowout','[FP=18] Analoguous','[FP=19] Splash','[FP=20] Pastel','[FP=21] Sunset 2','[FP=22] Beech','[FP=23] Vintage','[FP=24] Departure','[FP=25] Landscape','[FP=26] Beach','[FP=27] Sherbet','[FP=28] Hult','[FP=29] Hult 64','[FP=30] Drywet','[FP=31] Jul','[FP=32] Grintage','[FP=33] Rewhi','[FP=34] Tertiary','[FP=35] Fire','[FP=36] Icefire','[FP=37] Cyane','[FP=38] Light Pink','[FP=39] Autumn','[FP=40] Magenta']|random }}"
  - service: mqtt.publish
    data_template:
      topic: wled/bar_led/api
      payload: "SX={{ (range(0, 255)|random) }}"
3 Likes

Thanks for the code, I tried it but it didn’t work I don’t know if I have some incorrect syntax

- id: '1575326339804'
  alias: CarPresence_ON
  description: ''
  trigger:
  - entity_id: binary_sensor.carpresence
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data_template:
        payload: '{{ [''[FX=00] Solid'',''[FX=01] Blink'',''[FX=02] Breathe'',''[FX=03]
          Wipe'',''[FX=04] Wipe Random'',''[FX=05] Random Colors'',''[FX=06] Sweep'',''[FX=07]
          Dynamic'',''[FX=08] Colorloop'',''[FX=09] Rainbow'',''[FX=10] Scan'',''[FX=11]
          Dual Scan'',''[FX=12] Fade'',''[FX=13] Chase'',''[FX=14] Chase Rainbow'',''[FX=15]
          Running'',''[FX=16] Saw'',''[FX=17] Twinkle'',''[FX=18] Dissolve'',''[FX=19]
          Dissolve Rnd'',''[FX=20] Sparkle'',''[FX=21] Dark Sparkle'',''[FX=22] Sparkle+'',''[FX=23]
          Strobe'',''[FX=24] Strobe Rainbow'',''[FX=25] Mega Strobe'',''[FX=26] Blink
          Rainbow'',''[FX=27] Android'',''[FX=28] Chase'',''[FX=29] Chase Random'',''[FX=30]
          Chase Rainbow'',''[FX=31] Chase Flash'',''[FX=32] Chase Flash Rnd'',''[FX=33]
          Rainbow Runner'',''[FX=34] Colorful'',''[FX=35] Traffic Light'',''[FX=36]
          Sweep Random'',''[FX=37] Running 2'',''[FX=38] Red & Blue'',''[FX=39] Stream'',''[FX=40]
          Scanner'',''[FX=41] Lighthouse'',''[FX=42] Fireworks'',''[FX=43] Rain'',''[FX=44]
          Merry Christmas'',''[FX=45] Fire Flicker'',''[FX=46] Gradient'',''[FX=47]
          Loading'',''[FX=48] In Out'',''[FX=49] In In'',''[FX=50] Out Out'',''[FX=51]
          Out In'',''[FX=52] Circus'',''[FX=53] Halloween'',''[FX=54] Tri Chase'',''[FX=55]
          Tri Wipe'',''[FX=56] Tri Fade'',''[FX=57] Lightning'',''[FX=58] ICU'',''[FX=59]
          Multi Comet'',''[FX=60] Dual Scanner'',''[FX=61] Stream 2'',''[FX=62] Oscillate'',''[FX=63]
          Pride 2015'',''[FX=64] Juggle'',''[FX=65] Palette'',''[FX=66] Fire 2012'',''[FX=67]
          Colorwaves'',''[FX=68] BPM'',''[FX=69] Fill Noise'',''[FX=70] Noise 1'',''[FX=71]
          Noise 2'',''[FX=72] Noise 3'',''[FX=73] Noise 4'',''[FX=74] Colortwinkle'',''[FX=75]
          Lake'',''[FX=76] Meteor'',''[FX=77] Smooth Meteor'',''[FX=78] Railway'',''[FX=79]
          Ripple'',''[FX=80] Twinklefox'',''[FX=81] Twinklecat'',''[FX=82] Halloween
          Eyes'']|random }}'
        topic: wled/all/api
    service: mqtt.publish

Regards

Copy my payload template code. It has double quotes outside the template and single quotes inside. It is tested and works.

Yours has single quotes outside the template and escaped single quotes inside. Probably what is causing the issue.

Hay bro

I just ran @tom_l wled_random script work a great

question did you change his topic in the script.

 topic: wled/bar_led/api

to you topic

I had to change mine to

topic: wled/xtree/api

and it worked

Hi,

Thanks to everyone for helping.

The code did work when I retried it, the LEDs changed to a different pattern each time the trigger happened. Last night I had been looking at the wled card on Lovelace which doesn’t update when the pattern is chosen. I don’t know if this is my code or just how it works. :face_with_raised_eyebrow:

Thanks

Yes that is correct the random script just send the commands to mqtt not loveace

I added a looping script that changes every hour will post when I get home if you want it

this is some script I found just made to meat my needs

first we call the script script.wled_random_xtree

ramdom_xtree_lights:
  alias: Ramdom_Xtree_lights
  sequence:
    - service: script.turn_on
      data:
        entity_id: script.wled_random_xtree
    - delay: '01:00'
    - service: script.turn_off
      data:
        entity_id: script.wled_random_xtree
    - service: script.turn_on
      data:
        entity_id: script.flash_loop_xtree

then we call script.flash_loop_xtree this is the looping bit

flash_loop_xtree:
  alias: flash loop xtree
  sequence:
    - delay:
        # time for flash light off
        seconds: 1
    - service: script.turn_on
      data:
        entity_id: script.ramdom_xtree_lights

now to stop the script run this script

stop_flash_xtree_lights:
  alias: Stop Flash xtree Lights
  sequence:
  - service: script.turn_off
    data:
      entity_id: script.ramdom_xtree_lights
  - service: light.turn_off
    data:
      entity_id: light.wled_xtree_lights

by the way it turn off the wled lights also.

see what been pick

still getting head around the templateing

got node-red to look at the mqtt messages

my case wled/xtree/api

image

the switch uses the contains and put them into there own mqtt message

  - platform: mqtt
    name: "wled fx"
    state_topic: "wled/fx"
    qos: 1

  - platform: mqtt
    name: "wled fp"
    state_topic: "wled/fp"
    qos: 1

  - platform: mqtt
    name: "wled sx"
    state_topic: "wled/sx"
    qos: 1

this is about my templateing i understand

  - platform: template
    sensors:
      wled_ramdom_pick:
        value_template: >
         {{ states.sensor.wled_fx.state.split(' ')[1] + ' ' + states.sensor.wled_fp.state.split(' ')[1] }}

did some thing reading the above only read the first word
my thing find the first bit which we dont want and replace with a space

so mark 2 verson

  - platform: template
    sensors:
      wled_ramdom_pick:
        value_template: >
         {{ states.sensor.wled_fx.state | replace(states.sensor.wled_fx.state.split(' ')[0],'') + ' ' + states.sensor.wled_fp.state | replace(states.sensor.wled_fp.state.split(' ')[0],'') }}

bit long in the tooth but it works for me.

someone in here mite rewrite and take out the node-red bit.

image

1 Like

Very encourage but not able to emulate the success of others here. I need my JSON to have double quotes to match with OpenMQTTGateway.

{ “value” :16712445 }

I would like to create a random selection from a series…

‘{ “value” : 16716525 }’,’{ “value” :16718565 }’, ‘{ “value” : 16751205 }’

I would like to place this in part of my script, first turn on the lights & then randomly select a color.

‘1575869305160’:
alias: MoodLights
sequence:

  • data:
    entity_id: switch.masterbedmoodlamp
    service: switch.turn_on
  • service: mqtt.publish
    data_template:
    topic: home/OpenMQTTGateway_ESP8266_IR/commands/MQTTtoIR
    payload: ‘{ “value” :16718565 }’

Any insight appreciated!

base on @tom_l reply i would try something like this

action:
  - service: mqtt.publish
    data_template:
      topic: home/OpenMQTTGateway_ESP8266_IR/commands/MQTTtoIR
      payload: "{{ ['{ "value" : 16716525 }','{ "value" : 16716525 }','{ "value" : 16751205 }']|random }}"

note the Quotes mite need fixing
on smoko break

So I’ve made some progress and this works, but the trick now is it only will use the first 3 values in the script?

  alias: MoodLights
  sequence:
  - service: mqtt.publish
    data_template:
      topic: home/OpenMQTTGateway_ESP8266_IR/commands/MQTTtoIR
      payload: '{ "value": {{ [ "16718565" , "16751205" , "16767015" , "16734375" , "16750695" , "16718055" , "16726215" , "16758855" , "16742535" , "16775175" , "16714485" , "16747125" , "16757325" , "16724685" , "16716525" , "16749165" , "16755285" , "16722645" , "16720605" , "16753245"‬‬‬‬‬‬‬‬‬‬‬‬‬ ] |random }} }'

So apparently the length of my payload entry was causing funnies, I removed some of the spaces and it seems to work now…

  sequence:
  - service: mqtt.publish
    data_template:
      topic: home/OpenMQTTGateway_ESP8266_IR/commands/MQTTtoIR
      payload_template: '{ "value": {{ [ "16718565","16751205","16767015","16734375","16750695","16718055","16726215","16758855","16742535","16775175","16714485","16747125","16757325","16724685","16716525","16749165","16755285","16722645","16720605","16753245"]|random}} }'

All the above examples arr assuming WLED is integrated using MQTT. How can this be achieved using the WLED integration part avoiding MQTT all together.

This is which works for me:

  action:
  - entity_id: light.living_windows_led
    service: light.turn_on
    data_template:
      effect: >-
        {{ ['Blink','Breathe','Wipe','Wipe Random','Random Colors','Sweep','Dynamic','Colorloop','Rainbow','Scan','Dual Scan','Fade','Theater','Theater Rainbow','Running','Saw','Twinkle','Dissolve','Dissolve Rnd','Sparkle','Dark Sparkle','Sparkle+','Strobe','Strobe Rainbow','Mega Strobe','Blink Rainbow','Android','Chase','Chase Random','Chase Rainbow','Chase Flash','Chase Flash Rnd','Rainbow Runner','Colorful','Traffic Light','Sweep Random','Running 2','Red & Blue','Stream','Scanner','Lighthouse','Fireworks','Rain','Merry Christmas','Fire Flicker','Gradient','Loading','Police','Police All','Two Dots','Two Areas','Circus','Halloween','Tri Chase','Tri Wipe','Tri Fade','Lightning','ICU','Multi Comet','Dual Scanner','Stream 2','Oscillate','Pride 2015','Juggle','Palette','Fire 2012','Colorwaves','BPM','Fill Noise','Noise 1','Noise 2','Noise 3','Noise 4','Colortwinkle','Lake','Meteor','Smooth Meteor','Railway','Ripple','Twinklefox','Twinklecat','Halloween Eyes','Solid Pattern','Solid Pattern Tri','Spots','Spots Fade','Glitter','Candle','Fireworks Starburst','Fireworks 1D','Bouncing Balls','Sinelon','Sinelon Dual','Sinelon Rainbow','Popcorn','Drip','Plasma','Percent','Ripple    Rainbow','Heartbeat','Solid']|random }}

The effect template can be simplified:

'{{ state_attr("light.nachttafel_febe", "effect_list") | random }}'

3 Likes

I can see that works in the template developer tool, but it’s ignored in the script. Probably because of the formatting. Just don’t have the hang of templating yet. Here’s my code, be grateful if someone could spot the error:

'1588664129034':
  alias: Balcony Sunset
  sequence:
  - data: {}
    entity_id: light.wled_living_room
    service: light.turn_on
  - data_template:
      effect: '{{ state_attr("light.wled_living_room", "effect_list") | random }}'
    entity_id: light.wled_living_room
    service: wled.effect
  - delay: 00:05:00
  - data: {}
    entity_id: switch.wled_living_room_nightlight
    service: switch.turn_on

Try putting the entity id inside the data template:

  - service: wled.effect
    data_template:
      entity_id: light.wled_living_room
      effect: '{{ state_attr("light.wled_living_room", "effect_list") | random }}'
1 Like

Thanks Tom,

I fiddled here and there and found this to be working:

'1589012205801':
  alias: Balcony Sunset
  sequence:
  - data:
      entity_id: light.wled_living_room
      brightness: 150
    service: light.turn_on
  - data_template:
      effect: '{{ state_attr("light.wled_living_room", "effect_list") | random }}'
    entity_id: light.wled_living_room
    service: wled.effect
  - delay: 00:15:00
  - data:
      entity_id: switch.wled_living_room_nightlight
    service: switch.turn_on
1 Like

This works great for randomizing the effects but how would you do the speed and intensity using the integration and HA automation, also new in 0.117.0 is the ability to call palettes how would that be randomized?

If there is a list of palettes, you can do the same as the effect list. For the speed and intensity you could use {{ (range(0, 255)|random) }}

 - service: wled.effect
    data_template:
      entity_id: light.wled_living_room
      effect: '{{ state_attr("light.wled_living_room", "effect_list") | random }}'
      speed: '{{ (range(0, 255)|random) }}'
      intensity: '{{ (range(0, 255)|random) }}'
1 Like