Beginner question using addressable_lambda for simple things

Hello,
I’m trying to use EspHome help or research on internet to understand how to use the Addressable Lambda Effect.

I think my project is easy : i’ve an ESP32 with a WS2812B led with 120 leds.

I’ve 4 air sensors connected to Homeassistant. I would like to divide my 120 leds by 4 groups of 30 leds and, when a sensor detect something wrong, color in red one of these groups.
I’m not able to find very simple example for beginners…
Thank you in advance.
Best regards, Fabien

on_...:

  - light.addressable_set:
      id: my_light
      range_from: 0
      range_to: 30
      red: 100%
      green: 0%
      blue: 0%

Thank you for your fast answer Karosm. I guess it should be very easy to do but I don’t know why it doesn’t work. It should be a detail or a stupid thing but here is my yaml :

esphome:
  name: esphome-web-e1cb8e
  friendly_name: Led Salon
  min_version: 2024.6.0
  name_add_mac_suffix: false

  platformio_options:
    board_build.flash_mode: dio
  project:
    name: esphome.web
    version: dev

esp32:
  board: esp32-s2-saola-1
  framework:
    type: arduino
    
# Enable logging
logger:

# Enable Home Assistant API
api:

debug:
  update_interval: 5s
  
ota:
  - platform: esphome


wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password


light:
  - platform: fastled_clockless
    chipset: WS2812B
    pin: GPIO04
    num_leds: 120
    rgb_order: GRB
    name: "Led Salon"

on_turn_on:
  - light.addressable_set:
      id: my_light
      range_from: 0
      range_to: 30
      red: 100%
      green: 0%
      blue: 0%

I’ve got this error message :

INFO ESPHome 2025.2.2
INFO Reading configuration /config/esphome/esphome-web-e1cb8e.yaml...
ERROR Unexpected exception while reading configuration:
Traceback (most recent call last):
  File "/usr/local/bin/esphome", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/esphome/esphome/__main__.py", line 1049, in main
    return run_esphome(sys.argv)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/esphome/esphome/__main__.py", line 1027, in run_esphome
    config = read_config(dict(args.substitution) if args.substitution else {})
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/esphome/esphome/config.py", line 1095, in read_config
    res = load_config(command_line_substitutions)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/esphome/esphome/config.py", line 949, in load_config
    return _load_config(command_line_substitutions)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/esphome/esphome/config.py", line 939, in _load_config
    return validate_config(config, command_line_substitutions)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/esphome/esphome/config.py", line 835, in validate_config
    target_platform = core_config.preload_core_config(config, result)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/esphome/esphome/core/config.py", line 222, in preload_core_config
    if _is_target_platform(domain):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/esphome/esphome/core/config.py", line 184, in _is_target_platform
    if get_component(name, True).is_target_platform:
       ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/esphome/esphome/loader.py", line 205, in get_component
    return _lookup_module(domain, exception)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/esphome/esphome/loader.py", line 181, in _lookup_module
    module = importlib.import_module(f"esphome.components.{domain}")
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'esphome.components.on_turn_on'

You got error because without indentation on_turn_on: is considered a component.
Move it in line with other light options.

Anyway, you wanted to use it for sensor output, but you don’t have sensors on your yaml.

sensor:
  - platform: dht
    # ...
    on_value_range:
      - below: 5.0
        then:
          - light.addressable_set:
              id: my_light
              range_from: 0
              range_to: 30
              red: 100%
              green: 0%
              blue: 0%

Thanks again. Ok, the indentation is very unclear to me I have to learn about that.
I have 4 devices in 4 different rooms with CO2, particles, temperature… sensors and I’m trying to find the best way to use my LED in a room for alerting me kindly when one of the sensors has a bad value. I want to divide my LED stip in 4 segments with one for each device.
For information, I’m using a ESP32 S2 mini only for this LED and I didn’t succeed to insall Wled on it.
At the moment, I divided my led using partition :

  - platform: partition
    name: "part1"
    id: part1
    segments:
      - id: strip
        from: 0
        to: 29

and i’m using a lot of automation. But I’m not sure it is the best way. I would prefer to have only one .yaml on the ESP32 S2 mini and to manage with this file.
I’ trying to search for the best way to do.
Don’t hesitate if you have an idea of the best way to do.
Best regard,

Fabien

I don’t know which is best way for you.
You can use fastled or neopixel component, then partitions or addressable_set.
Partition is practical when you need to join and divide multiple strips.

Make a working yaml for one sensor and try. When it’s working like expected, add next sensor. Post your code here for help.

Do you mean that sensors are connected to other Esp boards and you have some wireless communication between them and this LED-board?

Yes exactly ! Sorry if I was unclear. I’ve 4 differents ESP32 S2 mini with their sensors and another ESP32 S2 mini with the LED, all connected to homeassistant via wifi.
I’m looking on forum and internet for the best way to do. I will come back here after when I will have the solution or questions.

My vote for direct esphome to esphome approach…