Display light brightness on display

I’m trying to display the brightness of a light: on my OLED display. However, I have having trouble finding how to pull that info. I’ve searched the docs and forums but not seeing it anywhere.

I’ve tried the following code, but no matter what I guess at it doesn’t compile. I’ve tried id(lamp).state, .value, .brightness, .get_brightness, etc.

  - platform: monochromatic
    id: lamp
    name: "Lamp"
    output: lamp_driver
    gamma_correct: 5

  - platform: ledc
    id: lamp_driver
    pin: GPIO32
    frequency: 1000Hz

  - platform: ssd1306_i2c
    id: oled
    model: "SSD1306 128x64"
    address: 0x3C
    lambda: |-
      it.printf(0, 0, id(font_status), TextAlign::TOP_LEFT, "%.1%%", id(lamp).state; 

I get the following compile error:

src/main.cpp:590:72: error: 'class esphome::light::LightState' has no member named 'state'
       it.printf(0, 0, font_status, TextAlign::TOP_LEFT, "%.1%%", lamp->state); 

Any pointers would be appreciated!

If I understand right, you need to pull that date from HA.

You do that by creating a sensor that “grabs” the info from HA and “puts” it on the node.

  - platform: homeassistant
    name: "dstemp"
    id: dstemp
    entity_id: sensor.dark_sky_temperature
  - platform: homeassistant
    name: "dshum"
    id: dshum
    entity_id: sensor.dark_sky_humidity

Hmm, I suppose could do that, but I was hoping to avoid the communication loop back to HA.

ESPHome is obviously reporting that to HA, so surely there is a way to access it directly in ESPHome?

I didn’t read carefully enough. I thought you were pulling another nodes info. You’re 100% correct that would be circular.

I think the compiler is giving you the best clue:

There is no member state and I’m not clear which method pulls the brightness but I think it might be this one:


Can you try your code with id(lamp).current_values_as_brightness ?

Like you I’ve been kinda frustrated with documentation of lambdas, but I thought I was just dumb. I’m not saying I’m not, but I’m not good at C++

Using current_values_as_brightness gives me a different error, but it still won’t compile. It looks like that is actually function that requires a pointer to a float parameter that I’m not sure what to do with.

This is what I use to get the brightness (which is 0 to 1) returned as 0 - 255 integer (which is what I needed)

return (int(id(light_main_1).remote_values.get_brightness() * 255));

or you can describe in more detail how you use this line of code. thanks in advance