Disable addressable light? Casting required?

The documentation on addressable_light as a display says that it should be possible to call set_enabled(false) to disable the display and allow using it as a light instead.

I’m getting the following error message:

<unicode string>:95:12: error: 'class esphome::display::Display' has no member named 'set_enabled'; did you mean 'set_pages'?

for the following lambda:

if (id(display_switch).state) {
        it.set_enabled(true);
        // Draw a bulls-eye pattern
        Color red = Color(0xFF0000);
        Color green = Color(0x00FF00);
        Color blue = Color(0x0000FF);
        
        it.rectangle(0, 0, 16, 16, red);
        it.rectangle(1, 1, 14, 14, red);
        it.rectangle(2, 2, 12, 12, green);
        it.rectangle(3, 3, 10, 10, green);
        it.rectangle(4, 4, 8, 8, blue);
        it.rectangle(5, 5, 6, 6, blue);
        it.rectangle(6, 6, 4, 4, red);
        it.rectangle(7, 7, 2, 2, red);
        
        
      } else {
        it.set_enabled(false);
      }

I’m assuming that I need to cast the it variable somehow, but that’s the limit of my C++ skills. Has anyone used that successfully?

Im not exactly sure about the syntax error but, this is kind of interesting. Im not sure how useful it will be though if you have limited control over the light, cant change the color and can only do dimming. That seems pretty restrictive and not very useful.

As far as I can tell, this isn’t a syntax error. And the way I understand the documentation, the whole point of the set_enabled() option is to turn off the display function and allow the use as a light (including effects etc.).

Oh maybe i got that backwards. You have very limited use of the light when display is enabled. Every error is in some way or another syntax error. Its saying set_enabled doesnt belong to the Display class. Have you set up pixel_mappet? Im just guessing here but, i wonder that is a requirement to use set-enabled

Can you post the whole config? I am genuinely curious about things im not familiar with and im happy to try and help but, seeing the config would allow me to find answers without having to ask yoi about every little thing. I went back and did a search at esphome.io for “it.set_enabled” the one and only place its mentioned is in that grey box on the addressable light page. No examples or context for using it.

The way I understood this function that if you have a light with individually addressable LEDs such as a fastled_clockless, you can turn it into a display using addressable_light. This works well, but then you cannot use the light as a light anymore (including no effects). In this case, you can only set the brightness and other limited things, as you have seen.
The set_enabled() toggle should be able to turn off the display function, except that it doesn’t work (see above).

The full configuration I tried to use looks like this (the idea was to have a toggle switch in HA that en- or disables the display function):

esphome:
  name: "led-bild"
  friendly_name: LED-Bild

esp32:
  board: esp32dev

logger:

api:
  encryption:
    key: !secret api_key

ota:
  password: !secret ota_password

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

switch:
  - platform: template
    name: "Display"
    optimistic: true
    id: display_switch

light:
  - platform: fastled_clockless
    chipset: WS2812
    name: LED
    pin: GPIO13
    num_leds: 256
    id: led
    rgb_order: GRB

display:
  - platform: addressable_light
    id: led_matrix_display
    addressable_light_id: led
    width: 16
    height: 16
    rotation: 90
    update_interval: 50ms
    lambda: |-
      if (id(display_switch).state) {
        it.set_enabled(true);
        // Draw a bulls-eye pattern
        Color red = Color(0xFF0000);
        Color green = Color(0x00FF00);
        Color blue = Color(0x0000FF);
        
        it.rectangle(0, 0, 16, 16, red);
        it.rectangle(1, 1, 14, 14, red);
        it.rectangle(2, 2, 12, 12, green);
        it.rectangle(3, 3, 10, 10, green);
        it.rectangle(4, 4, 8, 8, blue);
        it.rectangle(5, 5, 6, 6, blue);
        it.rectangle(6, 6, 4, 4, red);
        it.rectangle(7, 7, 2, 2, red);
      } else {
        it.set_enabled(false);
      }

I understood it to be different than what you described. I took it as the capability to use a an led matrix as an addressable light as well and to switch between the 2, that is what set_enable is for. I very well could be wrong, thats just how i understood it. What light or led matrix are you using? It sounds like the pixel mapping is critical for this to work.

The only 2 things id suggest is 1. Try neopixel instead. People are always having problems with FastLED and my impression is it isnt maintained or updated as well as Neopixel library.
2. Go to the Esphome Discord server and ask those people. Thats where the developers and really smart people hang out and their is always a couple of them in there helping people.

Theyll likely ask for all the details like your config, log output and what hardware or lights your using.

Was there ever an answer to this, I want to be able to go back and forth between a light and a display and could really use a little more detail based on this thread.

I never made it to Discord, but I found out that it works if you call set_enabled not on the it variable, but on id(display).

Thus, I created the following switch that allows switching the led matrix from display to light:

switch:
  - platform: template
    name: "Display"
    optimistic: true
    id: display_switch
    on_turn_on:
      - light.turn_off: led
    turn_on_action:
      - lambda: |-
          id(led_matrix_display).set_enabled(true);
    turn_off_action:
      - lambda: |-
          id(led_matrix_display).set_enabled(false);

(actually, I should mark this as a solution as well).