Here is the code I and others have used to put the Electron into deepsleep once the battery SOC hits 20%.
The code wakes up every hour to check if the solar panel has charged the battery above 20% and starts running normally once this happens and keeps sleeping if the SOC is still 20% or below.
The SOC% sleep number is adjustable so you can change it if desired.