Memories on Home Assistant

I’ve an ESP32 device connected to HA via BLE.
The ESP32 is in deep sleep for the most of the time and , perodically, say 3 secs every minute, it is awake.
When it is awake it sends the value on a specific pin (say pin 34) tha can be low or high.
I’d like that on the HA dashboard will be an “indicator” (a sort of LED) that when the value on the pin 34 is High will be ON and remain ON even when the ESP32 goes to deep sleep.
The led must go from ON to OFF (and remain OFF) only when, in the next awake interval, the value on the ESP32 pin change from High to LOW.
In other words, I need of a sort of memory that need an high, momentary, value to set ON (and remain ON) and a low, momentary pulse to set OFF (and remain OFF).
Any idea?
Thanks in advance.

I haven’t used deep sleep, but what happens at present to the state in ha when the esp is s;eeping?

Perhaps you need to use retain in your mqtt sensor?

The sensor goes to unknow state/value

I found an accettable workaround.
Using a switch in combination with an automation solve the problem.
In fact when the value of the pin34 goes from unknown state (ESP32 in deep sleep) to high state (activation) the automation set the switch ON (action) and viceversa when the pin34 goes from unknown state to low state the automation set the switch OFF (action) .
By this way it seems to works.