You are going to need four things:
PREMINILARY. Install Tasker and AutoInput, and open them both at least once. Also, ensure you downloaded the script. Also, Go settings -> accessibility and grant access to both Tasker and AutoInput.
Go into tasker, and tap the house, then 'import' then the script I gave you (should be AirplaneToggle.prf.xml) to import it.
Close Tasker while connected to WiFi, and watch to see if it works. It should!
What is that script doing?
Simply put, the script starts up the wireless and networks settings, creates a fake tap to enable airplane mode, waits a little, then returns to your homescreen, and also disables tasker to finish.
Keep in mind:
If you want to have this only apply to Home WiFi, you need to configure the WiFi bit. In tasker, tap the stuff on the left of the green arrow, and add the SSID (The name) of your WiFi hub. For example, I have a sky Hub, so it would be 'SKYXXXXX6' (X's replaced with random characters) that I put into the SSID field.
This task disables Tasker when finished to avoid it looping constantly. You can re-enable it by holding your finger on the grey lightning cog in taskers main menu (top left) OR by adding a widget that let's you toggle it from the homescreen!*
Delays are in place to allow for animations and Lag to finish safely. Also, the script will take you to your home screen when done.
You can still enable your WiFi in airplane mode- just don't enable tasker when on your Home WiFi! (I already said that, right?)
Tweak the task if you want. Not stopping you at all.
Tasker is woring paying for, but free alternatives are available! (Or be an ass, and just trial Hop (backup the scripts before the trial expires, then uninstall and reinstall said trial version)
*Just found out there is no Widget to enable tasker. You will have to do it via opening Tasker itself.
All links are legitimate, including the trial (it links to the official site, as a direct download) if you feel links are illegitimate, say so in the comments