How to programmatically detect loss of power?

I have an application where reliability is super important, I need as close to 100% uptime as possible.

I have the MKR1010 powered through a 5V supply on the VIN pin, and have a LiPo battery connected that can keep it running for several hours if need be. The scenario I'm thinking about though is a longer power outage. In my sketch, I would like to be able to capture the time that the VIN pin loses power by checking when the battery charge controller chip switches to running off battery, and then send me a text message after a certain amount of time if the power continues to be out.

The problem is, I don't know of any function to check the battery charging state... does that exist?

I would like to be able to programmatically read the state of the battery charge controller, rather than having to hook up an input voltage to one of the analog pins thru a voltage divider.

For example,

if (onbatterypower()){
  //do something
}

Perhaps you can communicate with the BQ24195L charger chip over I2C which according to the schematics is connected to PA08/09 pins of the processor.