Steps lighting with WLED integration

Good morning,

I would like to illuminate the steps of the staircase based on two proximity sensors (initial tests are with input boolean simulating PIRs), for this I am relying on the integration of WLED.

I know WLED has a usermod for this, but it doesn’t offer the ability to run multiple effects in each step.

The configuration shown below works fine the first time it runs, from that moment on it can be said that it works but it only runs the last effect until I restart the controller where WLED runs (wemos D1 mini).

Do you know what could cause this?

I have created the following automation:

- alias: "Segment effects up based on PIR sensor"
  trigger:
    - platform: state
      entity_id: input_boolean.bottom_pir
      to: 'on'
  condition:
    - condition: state
      entity_id: input_boolean.top_pir
      state: 'off'
  action:
    - service: script.turn_on
      entity_id: script.segment_effects_bottom


- alias: "Segment effects down based on PIR sensor"
  trigger:
    - platform: state
      entity_id: input_boolean.top_pir
      to: 'on'
  condition:
    - condition: state
      entity_id: input_boolean.bottom_pir
      state: 'off'
  action:
    - service: script.turn_on
      entity_id: script.segment_effects_top

And these are the scripts that are called from the automation

segment_effects_bottom:
  sequence:
  - service: light.turn_on
    entity_id: light.wled_segment_1
    data:
      effect: "dual_scan"
      transition: 2
  - delay:
      seconds: 2
  - service: light.turn_on
    entity_id: light.wled_segment_1
    data:
      effect: "solid"
      transition: 1
  - delay:
      seconds: 1
  - service: light.turn_on
    entity_id: light.wled_segment_2
    data:
      effect: "dual_scan"
      transition: 2
  - delay:
      seconds: 2
  - service: light.turn_on
    entity_id: light.wled_segment_2
    data:
      effect: "solid"
      transition: 1
  - delay:
      seconds: 1
  - service: light.turn_on
    entity_id: light.wled_segment_3
    data:
      effect: "dual_scan"
      transition: 2
  - delay:
      seconds: 2
  - service: light.turn_on
    entity_id: light.wled_segment_3
    data:
      effect: "solid"
      transition: 1
  - delay:
      seconds: 1
  - service: light.turn_on
    entity_id: light.wled_segment_4
    data:
      effect: "dual_scan"
      transition: 2
  - delay:
      seconds: 2
  - service: light.turn_on
    entity_id: light.wled_segment_4
    data:
      effect: "solid"
      transition: 1
  - delay:
      seconds: 1
  - delay:
      seconds: 5
  - service: light.turn_off
    entity_id: light.group_lights


segment_effects_top:
  sequence:
  - service: light.turn_on
    entity_id: light.wled_segment_4
    data:
      effect: "dual_scan"
      transition: 2
  - delay:
      seconds: 2
  - service: light.turn_on
    entity_id: light.wled_segment_4
    data:
      effect: "solid"
      transition: 1
  - delay:
      seconds: 1
  - service: light.turn_on
    entity_id: light.wled_segment_3
    data:
      effect: "dual_scan"
      transition: 2
  - delay:
      seconds: 2
  - service: light.turn_on
    entity_id: light.wled_segment_3
    data:
      effect: "solid"
      transition: 1
  - delay:
      seconds: 1
  - service: light.turn_on
    entity_id: light.wled_segment_2
    data:
      effect: "dual_scan"
      transition: 2
  - delay:
      seconds: 2
  - service: light.turn_on
    entity_id: light.wled_segment_2
    data:
      effect: "solid"
      transition: 1
  - delay:
      seconds: 1
  - service: light.turn_on
    entity_id: light.wled_segment_1
    data:
      effect: "dual_scan"
      transition: 2
  - delay:
      seconds: 2
  - service: light.turn_on
    entity_id: light.wled_segment_1
    data:
      effect: "solid"
      transition: 1
  - delay:
      seconds: 5
  - service: light.turn_off
    entity_id: light.group_lights

Check your logs, WLED is temperamental. The API that’s used to talk to WLED cannot handle fast asynchronous calls. Home assistant usually causes WLED devices to crash, frequently. Personally, I found it’s best to simply use presets only. Any fast calls to separate segments usually end up with WLED crashing. From what I can tell, the WLED developers have no interesting in fixing this either.

Indeed, the WLED API does not behave well with the previous code, apart from the fact that it does not work as expected, it causes the controller to restart frequently.

I have tried the following code and it seems to look better

- id: wled_segment_effects_top
  alias: Control de efectos de segmentos WLED
  trigger:
  - platform: state
    entity_id: input_boolean.top_pir
    to: 'on'
  condition:
  - condition: state
    entity_id: input_boolean.bottom_pir
    state: 'off'
  action:
  - repeat:
      count: 5
      sequence:
      - service: mqtt.publish
        data:
          topic: wled/arbol/api
          payload: '{"seg":[{"id":{{ 5 - repeat.index }},"on":true, "fx":60}]}'
      - delay:
          hours: 0
          minutes: 0
          seconds: 1
          milliseconds: 0
      - service: mqtt.publish
        data:
          topic: wled/arbol/api
          payload: '{"seg":[{"id":{{ 5 - repeat.index }},"on":true, "fx":0, "transition":10}]}'
      - delay:
          hours: 0
          minutes: 0
          seconds: 0
          milliseconds: 500
  - delay:
      seconds: 5
  - service: mqtt.publish
    data:
      topic: wled/arbol/api
      payload: '{"ps":2 ,"on":true}'
      qos: 0
      retain: false

- id: wled_segment_effects_bottom
  alias: Control de efectos de segmentos WLED bottom
  trigger:
  - platform: state
    entity_id: input_boolean.bottom_pir
    to: 'on'
  condition:
  - condition: state
    entity_id: input_boolean.top_pir
    state: 'off'
  action:
  - repeat:
      count: 5
      sequence:
      - service: mqtt.publish
        data:
          topic: wled/arbol/api
          payload: '{"seg":[{"id":{{ repeat.index }},"on":true, "fx":60}]}'
      - delay:
          hours: 0
          minutes: 0
          seconds: 1
          milliseconds: 0
      - service: mqtt.publish
        data:
          topic: wled/arbol/api
          payload: '{"seg":[{"id":{{ repeat.index }},"on":true, "fx":0, "transition":10}]}'
      - delay:
          hours: 0
          minutes: 0
          seconds: 0
          milliseconds: 500
  - delay:
      seconds: 5
  - service: mqtt.publish
    data:
      topic: wled/arbol/api
      payload: '{"ps":2 ,"on":true}'
      qos: 0
      retain: false

Does the mqtt work better? I haven’t looked into that comm method for wled.

Well at least that code does what I want and does not cause wled controller hangs as it did with the previous code

Excellent, I’ll have to give that a try. I don’t know why MQTT never crossed my mind