esp32 powered by Solarpower and main power

I am working on a project in school but I have a problem, I need to power a esp32 with a solarpannel and with main power. I want to charge a battery with the solarpannel and then power the esp with the battery. If the battery is low then I want to charge it with main power from the house. I also want that the esp32 can measure the percentage of the battery. For the project I need a solenoid lock, I need to power that with 12v 1A. I have a flowchart of the problem attached. I wanted to know if this is possible and what I need to use to accomplish it. Can someone help me?

Since the solenoid requires 12V, it would be easiest to use a 12V lead acid battery for the entire system, for example a gel cell or motorcycle battery. There are lots of projects on line that show how to charge such batteries with a solar panel.

Measuring percentage battery charge is not particularly easy, and is a detail that can be left for later. Leave the 230VAC charging for later, too.

A lead acid battery should NEVER be discharged below about 11V, and that voltage is easy to monitor.

Perhaps?

Perhaps not?