Question about flash write on ESP8266

Hello,

from reading the docs, I couldn’t get a definitive answer.
Are only globals stored in flash, or also any sensor data (entity states)?
Are only values stored in flash which are explicitly assigned the “restore_value: yes”, or are all values stored when “esp8266_restore_from_flash: true” is defined in the board parameters?

If I understand this correct, in the following example config, only the “global_1” is written to flash, right?

esphome:
  name: node_1
  platform: ESP8266
  board: nodemcu
  esp8266_restore_from_flash: true    #enabling storing in flash

globals:
  - id: global_1
    type: float
    restore_value: yes  #this is the only global I want to restore from flash
  - id: global_2
    type: float

sensor:
  - platform: ultrasonic
    id: sensor_1
    trigger_pin: D1
    echo_pin: D2
    update_interval: 60s

Thanks in advance to anyone who can shed some light on this.

I’m reading the docs and half the internet almost two years later and still can’t figure it out. Must be a taboo subject.

Yeah I was curious about this too after converting one of my Sonoff S31s from Tasmota to ESPHome. My searches have been inconclusive.

I would hope that it only saves the state of the afore mentioned globals and device controls (switches, lights, covers, etc). It makes no sense to me for it to save the value of a sensor

You should see the quantity of flash saves on your log.

Yeah good call. With the relay on, I am getting flash writes roughly every minute (default interval). With it off I get nothing. This pretty much confirms that in my case, it is in fact writing the values of the energy monitoring sensors to flash. That’s a shame as it’s completely unnecessary and I don’t see a way to restore the relay/switch state without also saving sensor values.

I doubt it.
Maybe you have Total Daily Energy configured ? You can set restore: false.

Good catch. I did have Total Daily Energy and didn’t realize it defaulted to restore: true. Changed to false and now it appears I only get flash writes when the relay/switch changes state, which is what I wanted. Thanks