M5Stack Core2 Display Off Switch

Hello!

Very new to ESPHome. I just got a M5Stack Core2 and have been doing some early tinkering. I found this

And have been trying to learn. I got battery_level, uptime, and WiFi db as entities in Home Assistant, but I am looking for a way to get brightness as a slider and/or an on/off switch to control the ili9341 screen (for battery saving purposes).

I see in their code

Line 548

void AXP192Component::SetLed(uint8_t state) {

Which I believe is a reference to shutting off the LED? But kinda stuck getting it from the cpp to yaml.
I also see in M5Core2/AXP192.cpp at master · m5stack/M5Core2 (github.com)

Line 156 appears to have code for screen brightness. Is there a simple way to get codes like that into YAML form? Or am I missing something? Thanks!

Here’s my YAML.

substitutions:
  name: esphome-web-92b784
  hassname: esphomeweb92b784

esphome:
  name: esphome-web-92b784
  platform: ESP32
  board: m5stack-core-esp32

external_components:
  - source:
      type: git
      url: https://gitlab.com/geiseri/esphome_extras.git
    refresh: 0s
  - source:
      type: git
      url: https://github.com/JensGuckenbiehl/esphome-m5core2
    refresh: 0s 
    

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

text_sensor:
  - platform: homeassistant
    name: "House Mode"
    id: house_mode
    entity_id: input_select.house_mode
  - platform: homeassistant
    name: "Front Door Lock"
    id: front_door_lock
    entity_id: lock.front_door_lock
  - platform: homeassistant
    name: "Party Mode Sign Text"
    id: party_mode_sign_text
    entity_id: input_text.party_mode_sign_text

i2c:
   - id: bus_a
     sda: GPIO21
     scl: GPIO22
     scan: True

sensor:
  - platform: axp192
    model: M5CORE2
    address: 0x34
    i2c_id: bus_a
    update_interval: 30s
    battery_level:
      name: "${hassname} Battery Level"
      id: "${hassname}_batterylevel"
  - platform: wifi_signal
    name: ${hassname} WiFi Signal
    id: wifi_dbm
  - platform: uptime
    name: ${hassname} Uptime

spi:
  clk_pin: GPIO18
  mosi_pin: GPIO23
  miso_pin: GPIO38
  
time:
  - platform: homeassistant
    id: esptime

font:
  - file: 'calibri.ttf'
    id: font1
    size: 48

# # builtin 80x160 TFT
display:
  - platform: ili9341
    model: M5STACK
    cs_pin: GPIO5
    dc_pin: GPIO15
    rotation: 0
    id: core2_display
    pages:
      - id: page1
        lambda: |-
          std::string val = id(house_mode).state;
          if(id(house_mode).state == "Home") {        
              std::string val = id(house_mode).state;
              it.printf(20, 20, id(font1), Color(70,130,180), "%s Mode", val.c_str());
          } else {
              it.fill(COLOR_OFF);
          }

2 Likes

hi, @alex3m3ti8 have you ever solved this?

I haven’t and fallen off my radar for a while.

I’m using the following AXP192 with the M5Stack Core2 and it has a Light component that you can use to manage the Display (On/Off and Brightness)
components/axp192 · main · Ian Geiser / esphome_extras · GitLab

Cool, conceptually I understand what that means, but not as sure about the details. Could you post the relevant yaml for us? I’m guessing you have an external_components to reference it, and then a light: section to get it right? Thanks!

Here is the configuration example from the same site:
axp192_test.yaml · main · Ian Geiser / esphome_extras · GitLab

1 Like

Ok, I must be being very dim here. I just cannot get the AXP192 component to turn the light on my my M5Core2. It does all the debug stuff etc. But display is off, if I flash the display demo code via Ardunio IDE it works and then all the other display stuff work also when I reflask esphome until a powerdown, then its blank again.

Is there a light.on() I need to call somewhere?

Tearing my hair out (and I cant spare too much)

Having spent a week getting everything except the LCD backlight to work on a M5Stack Core3 have given up. I cant understand how something as simple as turning a light on can be made so difficult, you now need to access 4 seperate subsystems some via I2C to talk to the display. A definite misstep as it renders an otherwise superb device practically useless.