No need to do that, if your device runs at least Android 4.0:
- From your homescreen, go to Settings → Data Usage
- tick the checkbox to enable data limit
- in the graph, move the bars to some level suiting you (can be imaginary high, to not toggle your mobile data off altogether when reached)
- scroll down until you find the Spotify app, tap its entry to open details
- scroll to the end of that screen, tick the checkbox to "limit background data"
Done. Now, unless Spotify is running in foreground, it should no longer automatically use mobile data.
This setting has no effect to WiFi, so it would perfectly fit your needs: while on WiFi, Spotify feels no restriction. As soon as you switch to mobile data, the app is no longer allowed to automatically transfer anything in background – but should still permit actions you trigger when the app is in foreground.