Flash memory

Hi,

I am trying to create a solution to automate turning blinds for the windows and this script provided by Andrew ( @triblondon ) is working for me:

esphome:
  name: blinds-tilt3
  platform: ESP8266
  board: d1_mini
  esp8266_restore_from_flash: true
  on_boot:
    priority: -100
    then:
      - stepper.report_position:
          id: blind_stepper
          position: !lambda "return id(saved_position);"
      - stepper.set_target:
          id: blind_stepper
          target: !lambda "return id(saved_position);"
      - stepper.set_speed:
          id: blind_stepper
          speed: 200 steps/s
      - script.execute: update_cover_position

logger:

ota:
  password: "foo" # set by ESPHome - use that value!

wifi:
  ssid: "foo"
  password: "foo"
  reboot_timeout: 2min

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Blinds-Tilt3 Fallback Hotspot"
    password: "foo"

captive_portal:


# Enable Home Assistant API
api:
  services:
    - service: set_stepper_target
      variables:
        target: int
      then:
        - stepper.set_target:
            id: blind_stepper
            target: !lambda 'return target;'
        - script.execute: record_stepper_position
    - service: set_stepper_speed
      variables:
        speed: int
      then:
        - stepper.set_speed:
            id: blind_stepper
            speed: !lambda 'return speed;'
    - service: set_stepper_position
      variables:
        stepper_position: int
      then:
        - stepper.report_position:
            id: blind_stepper
            position: !lambda "return stepper_position;"
        - stepper.set_target:
            id: blind_stepper
            target: !lambda "return stepper_position;"

globals:
  - id: open_position
    type: int
    initial_value: '8000'
  - id: closed_position
    type: int
    initial_value: '1000'
  - id: saved_position
    type: int
    initial_value: '1000'
    restore_value: true

stepper:
  - platform: a4988
    id: blind_stepper
    dir_pin: D4
    step_pin: D3
    sleep_pin: D2
    max_speed: 250 steps/s
    acceleration: 200
    deceleration: 200

cover:
  - platform: template
    id: "blind_cover"
    device_class: blind
    name: "Blinds"
    has_position: true
    optimistic: false
    open_action:
      - logger.log: "Opening"
      - cover.template.publish:
          id: blind_cover
          current_operation: OPENING
      - stepper.set_target:
          id: blind_stepper
          target: !lambda "return id(open_position);"
      - while:
          condition:
            lambda: 'return id(blind_stepper).current_position < id(open_position);'
          then:
            - script.execute: update_cover_position
            - delay: 1000 ms
      - script.execute: update_cover_position
      - script.execute: record_stepper_position
      - cover.template.publish:
          id: blind_cover
          current_operation: IDLE
    close_action:
      - logger.log: "Closing"
      - cover.template.publish:
          id: blind_cover
          current_operation: CLOSING
      - stepper.set_target:
          id: blind_stepper
          target: !lambda "return id(closed_position);"
      - while:
          condition:
            lambda: 'return id(blind_stepper).current_position > id(closed_position);'
          then:
            - script.execute: update_cover_position
            - delay: 1000 ms
      - script.execute: update_cover_position
      - script.execute: record_stepper_position
      - cover.template.publish:
          id: blind_cover
          current_operation: IDLE
    position_action:
      - logger.log: "Setting position"
      - stepper.set_target:
          id: blind_stepper
          target: !lambda 'return (float(pos) * float( float(id(open_position)) - float(id(closed_position)) )) + float(id(closed_position));'
      - while:
          condition:
            lambda: 'return id(blind_stepper).current_position != ((float(pos) * float( float(id(open_position)) - float(id(closed_position)) )) + float(id(closed_position)));'
          then:
            - script.execute: update_cover_position
            - delay: 1000 ms
      - script.execute: update_cover_position
      - script.execute: record_stepper_position
      - cover.template.publish:
          id: blind_cover
          current_operation: IDLE
    stop_action:
      - logger.log: "Stopping"
      - cover.template.publish:
          id: blind_cover
          current_operation: IDLE
      - stepper.set_target:
          id: blind_stepper
          target: !lambda 'return id(blind_stepper).current_position;'
      - script.execute: update_cover_position
      - script.execute: record_stepper_position

sensor:
  - platform: template
    name: "Current stepper position"
    lambda: return id(blind_stepper).current_position;
    update_interval: 5s

script:
  - id: update_cover_position
    then:
      - cover.template.publish:
          id: blind_cover
          position: !lambda 'return float( float(id(blind_stepper).current_position) - float(id(closed_position))) / float( float(id(open_position)) - float(id(closed_position)) );'
  - id: record_stepper_position
    then:
      - globals.set:
          id: saved_position
          value: !lambda 'return id(blind_stepper).current_position;'

But this configuration is writing the current position of blinds to flash memory and I understand that D1 flash can only handle finite number of write cycles so few questions:

  1. While the write cycle may be finite, with above configuration what sort of timeline (months or years) can be expected for the D1?

  2. Instead of writing to flash, is there a work around say write to a local file or create another sensor that can tracked for the purpose?

Lastly, I intend to attach rechargeable battery pack to the unit, is there anyway to get batter level using ESPHome?

Thanks.