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.

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

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

display:
  - 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.

sensor:
  - 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:
https://esphome.io/api/classesphome_1_1light_1_1_light_state.html

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

esphome::light::LightState::current_values_as_brightness

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++