Updating lvgl slider with display backlight brightness (on the device itself)

My display has a backlight which is configured as a LEDC output

output:
  # Backlight LED
  - platform: ledc
    pin: GPIO38
    id: GPIO38
    frequency: 100Hz
    min_power: 0.03
    zero_means_zero: true

with a monochromatic light entity

light:
  - platform: monochromatic
    output: GPIO38
    name: Backlight
    id: backlight
    restore_mode: RESTORE_DEFAULT_ON

There is also a slider on the display of the device

- slider:
  x: 55
  y: 135
  id: settings_display_brightness
  min_value: 1
  max_value: 100
  #internal: false
  on_value:
    - light.turn_on:
        id: backlight
        brightness: !lambda |-
          return x / 100.0; // output value must be in range 0 - 1.0
    - lvgl.label.update:
        id: settings_display_brightness_label
        text:
          format: "%.0f%%"
          args: [ x ]
- label:
  x: 330
  y: 125
  text_font: roboto24
  text_color: 0xCCCCCC
  text: "N/A"
  id: settings_display_brightness_label

Dragging the slider here will set the display’s backlight brightness without issue but how would I go about updating the slider if the backlight brightness has been adjusted from Home Assistant?

I think you should adjust the slider instead of output from HA .
Example from documentation:

sensor:
  - platform: homeassistant
    id: light_brightness
    entity_id: light.your_dimmer
    attribute: brightness
    on_value:
      - lvgl.slider.update:
          id: dimmer_slider
          value: !lambda return x;

Ideally I wouldn’t do that as local data needs to make a round trip across the air.

However, I’ve actually tried that but it still doesn’t seem to work.

  - platform: homeassistant
    name: "Master Bedroom - Display Brightness"
    id: sensor_master_bedroom_brightness
    internal: false
    entity_id: light.master_bedroom_square_panel_backlight
    on_value:
    - lvgl.slider.update:
        id: settings_display_brightness
        value: !lambda return x;

Exposing the sensor to HA shows that the sensor is “Unknown” so the slider never updates.

Seems I’m a bit of an idiot.

I missed the attributes: brightness which you had included in yours.

That sorta fixes it now, except I can’t adjust the slider now because I have the update on_value and not on_release for responsiveness. But I’m sure I can sort that out somehow. (One updates the other and the other updates the original and it goes round and round and round)

If anyone has a way to access these values directly instead of making a round trip through HA though I’d still be interested in hearing it. But at least it works now (or shortly).

And sorted with:

    on_value:
    - lvgl.slider.update:
        id: settings_display_brightness
        value: !lambda |-
          if (isnan(x)) { return 0; } else { return round(x/255*100); }

But again, this goes to HA then back to the device :slight_smile:

I’m not sure if I follow you anymore…
Anyway, if you need to keep two sliders (and the output) in synch, some traffic there will be.
It’s just a question what is the path.

So in this case I’m trying to control the brightness of a display running esphome. This brightness should be controllable from HA as well as on the device itself via a slider.

If the brightness is set from HA, the slider should be updated to display the new brightness level. Instead, as at now, the brightness is set from HA, then the sensor pulls the brightness data a 2nd time to update the slider.

Ideally, this slider would follow the actual brightness of the light component, as opposed to having to call back to HA to get a value.

The method you proposed (to make that 2nd call to HA) is a method I tried previously with no luck but that was due to my error. But I am still looking for a more direct method :slight_smile:

That’s how it goes. Only way to guarantee that everything is synch.