How to turn on WLED via automation

Team

I would like to simply turn ON and OFF my WLED strip in automation calling for specific effect.
turn on Rainbow for 1 min for example

9 Rainbow Displays rainbow colors along the whole strip

So to turn ON Rainbow

action:
    service: mqtt.publish
    data_template:
      topic: [Device Topic.. XYZ ]/Segment/switch/set
      payload: on
      topic: [Device Topic.. XYZ ]/Segment/fx/set
      payload: 9

and to turn OFF

action:
    service: mqtt.publish
    data_template:
      topic: [Device Topic.. XYZ ]/Segment/switch/set
      payload: off

Do I have it right?

How would you setup “RANDOM” effect to be turned ON?

It goes a little something like this:

Turn ON

action:
  - service: mqtt.publish
    data_template:
      topic: wled/all/api
      payload: T=1

Turn OFF

action:
  - service: mqtt.publish
    data_template:
      topic: wled/all/api
      payload: T=0

Change Effects

action:
  - service: mqtt.publish
    data_template:
      topic: wled/all/api
      payload: FX=?

Replace ? with 0 thur 82

And, for random, you need to create a random sensor like this:

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

Once you have that created, now you need an automation

alias: Random WLED Effect
trigger:
  - platform: time_pattern
    minutes: "/10"
action:
  - service: mqtt.publish
    data_template:
      topic: wled/all/api
      payload: FX={{ states("sensor.random_effect") }}

This will change the Effect every 10 mins. I hope this clears things up.

2 Likes

Thank you million time Sir.!!!

Sure thing, glad I could help.

DrZzzs has some automations and input selects to do this posted on github:

I used them to create this and can post the Lovelace config if you want it.

Note that the PR has been merged so the ones on github are correct now too.

EDIT: also note that Home Assistant can now control WLED natively via a core integration.

1 Like

I’m trying to implement this but don’t seem to be able to pass the effect through MQTT… any ideas. Thanks.

- id: taskLightTest
  trigger:
  - at: '23:44'
    platform: time
  action:
  - service: light.turn_on
    entity_id: light.wled
  - service: mqtt.publish
    data_template:
      topic: wled/all/api
      payload: FX=10

Hi Paul, I think yu are close,but we have to change the way that you are turning the wled light strip on, give this a try:

- id: taskLightTest
  trigger:
  - at: '23:44'
    platform: time
  action:
  - service: mqtt.publish
    data_template:
      topic: wled/all/api
      payload: T=1
  - service: mqtt.publish
    data_template:
      topic: wled/all/api
      payload: FX=10

And the next question would be how do I turn them off:

action:
  - service: mqtt.publish
    data_template:
      topic: wled/all/api
      payload: T=0

I hope this helps.

3 Likes

Hey, thanks for the response on this. I tried what you mentioned but didn’t seem to work. Hmm…

this worked but I suppose I need to use mqtt to send the payload?

- id: 123989797
  alias: Sample Time Automation on
  description:
  trigger:
  - at: '00:35:00'
    platform: time
  action:
  - service: light.turn_on
    entity_id: light.wled

@paulfecht, if your Homeassistant is up to date, then you can integrate Wled as an integration and you would not have to use MQTT at all .

I had it with mqtt before but I have changed it for integration, much more comfortable, I only use mqtt to change the effects with a random sensor

thanks I’ll check it out.

Someone have it working with Nodered?

@Bas_Fpv, check out @tom_l post above, Snipercaine has a Node-Red config there.

I’d like to add something since I’m not seeing it anywhere else. Doing this doesn’t require any custom cards. Just vanilla HA, HA helpers, HA automations and official wled integration.

You can use the state of an input select helper or input select integration (in config.yaml) then add helper to a card in lovelace to easily change the effect. Helpers can be used via automations on all wled attribute states that are available with service calls. Also input select helper state can be set from wled attribute state when effect is changed by some other means such as changing a preset or changing the effect in wled web ui. Again this can be done for all wled attributes exposed in home assistant.

Here are my automations for controlling wled. I made a separate one for each but I’m sure this could be done more elegantly.

alias: Set Effect
description: ''
trigger:
  - platform: state
    entity_id: input_select.effect
condition: []
action:
  - service: wled.effect
    data:
      effect: '{{ states("input_select.effect") }}'
    entity_id: light.wled
mode: single

alias: Set effect to dropdown
description: ''
trigger:
  - platform: state
    entity_id: light.wled
    attribute: effect
condition: []
action:
  - service: input_select.select_option
    data:
      option: '{{ state_attr("light.wled", "effect") }}'
    entity_id: input_select.effect
mode: single
alias: Set Intensity
description: ''
trigger:
  - platform: state
    entity_id: input_number.intensity
    for: '00:00:00'
condition: []
action:
  - service: wled.effect
    data:
      intensity: '{{ states("input_number.intensity") }}'
    entity_id: light.wled
mode: single
max: 10

alias: Set intensity to slider
description: ''
trigger:
  - platform: state
    entity_id: light.wled
    attribute: intensity
condition: []
action:
  - service: input_number.set_value
    entity_id: input_number.intensity
    data:
      value: '{{ state_attr("light.wled", "intensity") }}'
mode: single
alias: Set palette
description: ''
trigger:
  - platform: state
    entity_id: input_select.palette_list
    for: '00:00:00'
condition: []
action:
  - service: wled.effect
    data:
      palette: '{{ states("input_select.palette_list") }}'
    entity_id: light.wled
mode: single
alias: Set palette to dropdown
description: ''
trigger:
  - platform: state
    entity_id: light.wled
    attribute: palette
condition: []
action:
  - service: input_select.select_option
    data:
      option: '{{ state_attr("light.wled", "palette") }}'
    entity_id: input_select.palette_list
mode: single
alias: Set Preset
description: ''
trigger:
  - platform: state
    entity_id: input_select.preset
    for: '00:00:00'
condition: []
action:
  - service: wled.preset
    data:
      preset: '{{ states("input_select.preset") }}'
    entity_id: light.wled
mode: single
alias: Set preset to dropdown
description: ''
trigger:
  - platform: state
    entity_id: light.wled
    attribute: preset
condition: []
action:
  - service: input_select.select_option
    data:
      option: '{{ state_attr("light.wled", "preset") }}'
    entity_id: input_select.preset
mode: single
alias: Set Reverse
description: ''
trigger:
  - platform: state
    entity_id: input_boolean.reverse
    for: '00:00:00'
condition: []
action:
  - service: wled.effect
    data:
      reverse: '{{ states("input_boolean.reverse") }}'
    entity_id: light.wled
mode: single
alias: Set Speed
description: ''
trigger:
  - platform: state
    entity_id: input_number.speed
    for: '00:00:00'
condition: []
action:
  - service: wled.effect
    data:
      speed: '{{ states("input_number.speed") }}'
    entity_id: light.wled
mode: single
alias: Set speed to slider
description: ''
trigger:
  - platform: state
    entity_id: light.wled
    attribute: speed
condition: []
action:
  - service: input_number.set_value
    data:
      value: '{{ state_attr("light.wled", "speed") }}'
    entity_id: input_number.speed
mode: single
alias: Set Brightness
description: ''
trigger:
  - platform: state
    entity_id: input_number.brightness
condition: []
action:
  - service: light.turn_on
    data:
      brightness: '{{ states("input_number.brightness") }}'
    entity_id: light.wled
mode: single
alias: Set brightness to slider
description: ''
trigger:
  - platform: state
    entity_id: light.wled
condition: []
action:
  - service: input_number.set_value
    data:
      value: '{{ state_attr("light.wled", "brightness") }}'
    entity_id: input_number.brightness
mode: single
7 Likes