Save previous target temperature of thermostats for each presets

I came across a seemingly trivial problem, but solving it turned out to be difficult for me.

There are several thermostats in the configuration.
Each thermostat has several presets - auto, away, eco, home…
When the user changes the temperature in any preset it will saved, the system must remember it, and when the user returns back to this preset, thermostat must return to previous temperature, not target temperature from YAML configuration.

I tried to automate it:

alias: Temperature change
  - platform: state
      - climate.1_thermostat
    attribute: temperature
condition: []
action: []
mode: single

But it also start when changing a preset, because when you change the preset, the temperature also changes.

I tried use scene, but for ESPHome Thermostat it doesn’t work → scene first change target temperature, and THEN change preset. System react on change preset, and take target temperature for preset from YAML config at end.

Of course I can use last triggered state - but, Isn’t there an easier way?

The second part of the problem is organizing the storage of values.
I thought about using a global array, but so far I’ve only found a global list. But even in it I cannot change a specific row; when recording the temperature of one preset, I will need to overwrite the entire all data array.

{% set array[0].temp = 30 %}

It doesn’t work, need to replace all data - copy all array with replace row in loop.
If I have few thermostats work in loop more easy, then write manually all states in automation…

And now - easy theme transform to more global for me.

PS. I use EPSHome Thermostat because it will work without link to server - In case of loss of connection, this will help keep the system from freezing.