airy10 / esphome-m5stickC

esphome components for the M5StickC
82 stars 78 forks source link

Upgrade to change the brightness from HA #19

Open casamarbar opened 2 years ago

casamarbar commented 2 years ago

Thanks for your job It would be possible to add a sensor to be able to change the brightness from HA of the screen?

c99koder commented 1 year ago

Create an input_number helper entity in Home Assistant called lcd_brightness that stores a value between 0 and 100, and then add the following to your esphome config to set the backlight level when the value changes:

sensor:
  - platform: axp192
    id: backlight
    …

  - platform: homeassistant
    id: brightness
    entity_id: input_number.lcd_brightness
    internal: true
    on_value:
      then:
        lambda: |-
          id(backlight).set_brightness(id(brightness).state/100.0);
          id(backlight).update();