Very simple stepper need to remember position on AC fail

Hi, I have this very simple stepper made to control a gas heater. I need it to remember its position when AC fails and return again. Can anybody help me?

esphome:
name: calefactor01
platform: ESP8266
board: d1_mini

wifi:
ssid: ‘XXXXX’
password: ‘XXXXX’

Enable logging

logger:

Enable Home Assistant API

api:
password: ‘XXXXX’

services:
- service: control_stepper
variables:
target: int
then:
- stepper.set_target:
id: my_stepper
target: !lambda ‘return target;’

ota:
password: ‘XXXXX’

web_server:
port: 80
auth:
username: XXXXX
password: XXXXX

stepper:

  • platform: uln2003
    id: my_stepper
    pin_a: D0
    pin_b: D1
    pin_c: D2
    pin_d: D3
    max_speed: 250 steps/s
    sleep_when_done: true

    Optional:

    acceleration: inf
    deceleration: inf

Please format your code properly. Point 11 here. How to help us help you - or How to ask a good question - #3

esphome:
  name: calefactor01
  platform: ESP8266
  board: d1_mini
  esp8266_restore_from_flash: true
  
wifi:
  ssid: XXXX
  password: XXXX

logger:

api:
  password: XXXX
  
  services:
    - service: control_stepper
      variables:
        target: int
      then:
        - stepper.set_target:
            id: my_stepper
            target: !lambda `return target;`

ota:
  password: XXXX

web_server:
  port: 80
  auth:
    username: XXXX
    password: XXXX

stepper:
  - platform: uln2003
    id: my_stepper
    pin_a: D0
    pin_b: D1
    pin_c: D2
    pin_d: D3
    max_speed: 250 steps/s
    sleep_when_done: true

    acceleration: inf
    deceleration: inf

Sorry I didn´t kow how to publish

Thanks

So when you say AC fails, are you talking about home assistant restarting, the esphome device restarting, or both.

when the esphome device restarts, on te home assistant I have an UPS

I think use a variable in home assistant to keep the current setting, and set the esphome via an on_boot setting.

I have no idea how to do it. Can you help me?