Changing the e61 tailgate glass switch
This is just a supplementary guide to the one already posted by user: kwempe.
LINK -> e61 faulty tailgate switch replace.pdf
tailgate pops open when starting car (can prevent this short term by locking doors before you start engine)
Tailgate pops open randomly at other times.
Slight battery drain and some strange things going on with electronics (probably due to battery drain and fault with tailgate switch)
Cause (in this case):
Water ingress into the tailgate switch either through the rubber gasket between the switch and the glass or through plastic welds in the switch itself.
The switch is permanently on, as the water is completing the switch circuit (as if someone is holding the switch down continuously)