AC restore last mode, fan and temperature

So it seems that the last setpoint temperatures are stored. Same as the fan. So if I use rule machine to send a "cool" mode command it'll turn the ac on with the previous settings.

I was thinking that in rule machine I can assign a variable value based on the mode change. Store that and them use a virtual switch to turn the ac on, it checks the value of the variable I stored the last mode change in and send the cool/heat/auto command based on the last mode I had..

Uo until now I have used the outside temperature as what determines the mode.. But when a battery goes flat occasionally the mode will be issued as heat instead of cool because the battery in the temperature sensor went flat overnight.. And I'm not too good at replacing batteries in a hurry...

Or do I set all values in a virtual thermostat when the real ac changes mode? I'm thinking that storing the last state in a variable and then using rule machine if statement to send the last node only is better, as it'll remember the last temperature for that mode, and remember fan speeds based on last state as well..

I am looking at using virtual switches to turn the AC on as Google home works well with switches and turning all ac on at once plus it's simpler to click a switch than a thermostat tile.