Power off detection circuit to close opened latching solenoid valve
Looks like the AMS1117 is a LDO. A TPS62840 which is a switching regulator is better solution for a low power application. Below an application circuit that might be helpful. Connect V_Batt from battery to Vin. Vout from the switching regulator which is 3.3V should be wired to the microcontroller (ESP 12E)

Use a GPIO pin to enable circuit below that can be connect to the ADC (Pin 2).

Below example circuit to use to measure the V_Batt, via ADC (Pin 2).



simulate this circuit &ndash; Schematic created using CircuitLab
Finally the micro controller should not have any issue providing sufficient current the GPIO pin. Most latching solenoids currently in the market has a minimum voltage around may be 4V-5V.