I use Event context Logcat Entry to determine that I have disconnected from my home wifi.
Component is: GnssNetworkConnectivityHandler
Filter is: ~R *connected=false,*
For the connect I use another Logcat Entry Event context.
Component is : WifiConnectivityMonitor.WCMCallbacks
Fillter is: ~R *"what ever the name of your wifi is":true*
Both of these work flawlessly except that you can have temporary home wifi dropouts that can be annoying.
You might want to add a denounce routine to your disconnect task. I got these components and filters on a Samsung S9
but when I upgraded to a new Motorola they still worked. Still not
guaranteed to work for all phones.
Hope this helps.