Definitely search the community because there are a few existing threads on this very topic:
I have a NAS where I detect if the connected UPS is on battery: