Quick update, I've revised my new version of the code to use RTC clock memory to save state in preparation for implementing deep sleep. This is hopefully the first step towards increasing battery life. Before I implement this, I need to come up with a mechanism to store and forward MQTT messages to the ESP when it wakes up, I maybe able to trick it with the MQTT retain flag, but need to investigate delivery order, and mitigate the risk of firing off IR commands after every deep sleep, even when no changes have been received. I think it is do-able.
I used Andreas Spiess Youtube video as a guide on how to use RTC memory. Check it out -