Saving State on ESPHOME and wemos d1 mini

Hello Community, i’m just started to play around with esphome and i have a issue during saving state of my project. When i remove power to my wemos all global variables are cleaned without restore state after reboot.

for references i leave here my code thx.

esphome 2025.3.1
wemos d1 mini usbc
8x led matrix max7219

my purpose was to control led matrix via Web Server and via Home Assistant.

ESPHOME Basic Stuff

esphome:
  name: d1-mini-dev-board
  friendly_name: d1-mini-dev-board
  on_boot:
    priority: 600
    then:
      - lambda: |-
          id(display_line_1) = id(display_line_1);
          id(display_line_2) = id(display_line_2);

esp8266:
  board: d1_mini

logger:
api:
  encryption:
    key: "e5T/X+qQlmp1WjOH/Qz3JT6GuMC3awlAD3em3T7pMMI="
ota:
  - platform: esphome
    password: "590034a7ff80704d91a10e94cab491b8"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap:
    ssid: "D1-Mini-Dev-Board"
    password: ""
captive_portal:

# PINOUT AND MAX7219 SETTING
spi:
  clk_pin: D5
  mosi_pin: D7
  id: spi_bus

display:
  - platform: max7219digit
    id: max7219_display
    cs_pin: D8
    spi_id: spi_bus
    scroll_mode : STOP
    scroll_enable: True
    intensity : 5
    num_chips: 8
    num_chip_lines: 2
    chip_lines_style: SNAKE
    lambda: |-
      it.intensity(id(brightness));
      it.print(0, 0, id(myfont), id(display_line_1).c_str());
      it.print(0, 8, id(myfont), id(display_line_2).c_str());

# UTILITIES FOR SETTING STUFF
globals:
  - id: display_line_1
    type: std::string
    restore_value: yes
    max_restore_data_length: 64

  - id: display_line_2
    type: std::string
    restore_value: yes
    max_restore_data_length: 30
  
  - id: brightness
    type: int
    restore_value: yes

number:
  - platform: template
    name: "Brightness Ddjustment"
    optimistic: true
    id: display_brightness
    icon: mdi:led-variant-on
    min_value: 0
    max_value: 15
    restore_value: True
    step: 1
    on_value:
      then:
        - globals.set:
            id: brightness
            value: !lambda |-
              return id(display_brightness).state;

text:
  - platform: template
    optimistic: true
    id: display_line_1_label
    name: "Display Line 1 Text"
    mode: text
    restore_value: true

    on_value:
      then:
        - globals.set:
            id: display_line_1
            value: !lambda |-
              return id(display_line_1_label).state;

            
  - platform: template
    optimistic: true
    id: display_line_2_label
    name: "Display Line 2 Text"
    mode: text
    restore_value: true
    on_value:
      then:
        - globals.set:
            id: display_line_2
            value: !lambda |-
              return id(display_line_2_label).state;

font:
  - file: "pixelmix.ttf"
    id: myfont
    size: 7

web_server:
  port: 80
  version: 2
  include_internal : True
  ota: False

Umm… yes?
It’s boolean. true/false

EDIT…
I was wrong… it is yes/no. Sorry.

But usually it can take up to a minute for it to get saved

Interesting how the documentation is for this.

boolean.

Defaults to no

restore_value option is using RTC-memory by default. It doesn’t survive power down.
If that’s what you are looking for, you need to set:

esp8266:
  restore_from_flash: true
2 Likes

Worked! thx so much

You are welcome.
You might want to adjust the flash_write_interval to best fit your setup.