ESP Home - efekt świetlny przy wyłączaniu LEDów WS2811

Cześć.
Zrobiłem sobie sterownik białej taśmy LED na WS2811 i ESP32. Stworzyłem efekt zapalania LED po kolei - od początku do końca. Następnie drugi - gaszenia LED od końca do początku. Dodałem efekt zapalania w zdarzeniu “on_turn_on” żeby wywoływać efekt przy każdym zapaleniu światła.
No i tutaj kończą się sukcesy. Chciałem zrobić to samo przy wyłączaniu światła, czyli dodać drugi efekt - gaszący LED od końca do początku, ale nie idzie tego zrobić poprzez proste dodanie do “on_turn_off”. Próbowałem również z flagami, siedziałem też z chatem GPT (ale wiadomo jakie brednie on potrafi napisać) no i finalnie się nie udało. Czy ktoś może przerabiał temat i wie jak to zrobić?
Pozdrawiam
PW

Pokaż yamla to może coś wymyślimy :wink:

esphome:
  name: living-room-locker
  friendly_name: Living room locker

esp32:
  board: esp32dev
  framework:
    type: esp-idf

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "klucz"

ota:
  - platform: esphome
    password: "pass"

wifi:
  ssid: "net"
  password: "pass"

  ap:
    ssid: "Living-Room-Locker"
    password: "pass"

captive_portal:

script:
  - id: on_effect_once
    mode: restart
    then:
      - light.turn_on:
          id: ws2811_white
          effect: on_sweep
      - delay: 1600ms
      - light.turn_on:
          id: ws2811_white
          effect: none

#  - id: off_effect_once
#    mode: restart
#    then:
#      - light.turn_on:
#          id: ws2811_white
#          effect: off_sweep
#      - delay: 1600ms
#      - light.turn_off:
#          id: ws2811_white
#          effect: none

light:
  - platform: esp32_rmt_led_strip
    rgb_order: GRB
    id: ws2811_white
    chipset: WS2811
    pin: GPIO4        
    num_leds: 60
    name: "Hall LED Strip"
    restore_mode: ALWAYS_OFF

    on_turn_on:
      then:
        - script.execute: on_effect_once

    # on_turn_off:
    #   then:
    #     - script.execute: power_off_effect

    effects:
      - addressable_lambda:
          name: on_sweep
          update_interval: 25ms
          lambda: |-
            static int pos = 0;
            if (initial_run) {
              pos = 0;
              it.all() = Color::BLACK;
            }
            if (pos < it.size()) {
              it[pos] = Color::WHITE;
              pos++;
            }

      - addressable_lambda:
          name: off_sweep
          update_interval: 25ms
          lambda: |-
            static int pos = 0;
            if (initial_run) {
              pos = it.size() - 1;
            }
            if (pos >= 0) {
              it[pos] = Color::BLACK;
              pos--;
            }

switch:
  - platform: gpio
    pin: GPIO13
    inverted: True
    name: "Locker Power"
    restore_mode: RESTORE_DEFAULT_OFF

Przywołujesz zły skrypt na stan off i po light.off usuń effect

Kombinowanie z on_turn_off w ten sposób nic nie da. To się zapętla. Z tym złym efektem to moja pomyłka, dopisywałem bez sprawdzenia, ale przerabiałem to na wiele sposobów. Niby to logiczne, że powinno wszystko działać po wywołaniu skryptu z on_turn_off, ale tak nie jest :frowning:

Wrzuce to wieczorem na swoją płytkę i popatrzę co mu tam nie pasuje

1 polubienie

Trochę to zmieniłem:

captive_portal:

script:
  - id: on_effect_once
    mode: restart
    then:
      - light.turn_on:
          id: ws2811_white
          effect: on_sweep

  - id: off_effect_once
    mode: restart
    then:
      - light.turn_on:
          id: ws2811_white
          effect: off_sweep


light:
  - platform: esp32_rmt_led_strip
    rgb_order: GRB
    id: ws2811_white
    chipset: WS2811
    pin: GPIO4        
    num_leds: 60
    name: "Hall LED Strip"
    restore_mode: ALWAYS_OFF
    effects:
      - addressable_lambda:
          name: on_sweep
          update_interval: 25ms
          lambda: |-
            static int pos = 0;
            if (initial_run) {
              pos = 0;
              it.all() = Color::BLACK;
            }
            if (pos < it.size()) {
              it[pos] = Color::WHITE;
              pos++;
            }

      - addressable_lambda:
          name: off_sweep
          update_interval: 25ms
          lambda: |-

            static int pos = 0;
            
            if (initial_run) {
              pos = it.size() - 1;
            }

            if (pos >= 0 && pos < it.size()) {
              it[pos] = Color::BLACK;
              
              if (pos == 0) {
                auto call = id(ws2811_white).turn_off();
                call.perform();
              }
              pos--;
            }

switch:
  - platform: gpio
    pin: GPIO13
    inverted: True
    name: "Locker Power"
    restore_mode: RESTORE_DEFAULT_OFF

  - platform: template
    id: fala
    name: "Efekt fali"
    restore_mode: RESTORE_DEFAULT_OFF
    on_turn_on: 
       - script.execute: on_effect_once
    on_turn_off:
       - script.execute: off_effect_once

Do efektu odpalaj switcha a nie light

3 polubienia

Działa, dzięki wielkie. Fajne obejście problemu znalazłeś. Jedyne co musiałem dodać to “optimistic”, bo nie przechodziło mi build.

  - platform: template
    optimistic: True
    id: fala
    name: "Efekt fali"
    restore_mode: RESTORE_DEFAULT_OFF
    on_turn_on: 
       - script.execute: on_effect_once
    on_turn_off:
       - script.execute: off_effect_once

Oraz podmieniłem skrypt włączania, tak aby można było regulować jasność po włączeniu.

script:
  - id: on_effect_once
    mode: restart
    then:
      - light.turn_on:
          id: ws2811_white
          effect: on_sweep
      - delay: 2500ms
      - light.turn_on:
          id: ws2811_white
          effect: none

Pozdrawiam
PW

1 polubienie