19 Sept 2016, 16:51

Here is an example with GPIO pin 14 for controlling the fan. The indents might not be correct πŸ˜‰ I had a little trouble with copy/paste the code πŸ˜„
Hope I can help you with this

#!/usr/bin/env python

import os
import time
import RPi.GPIO as GPIO

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
#Set max. temperature of CPU
TEMP_MAX = 67
ON_TIME = 200
#Set pin 14 as transistor gate
GATE = 14
#Set pin 14 as an output and shut down
GPIO.setup(GATE, GPIO.OUT)
GPIO.output(GATE, False)

def getCPUtemperature():
	 res = os.popen('vcgencmd measure_temp').readline()
	return(res.replace("temp=","").replace("'C\n",""))

while True:

		temp_float = float(getCPUtemperature())

	try:
		if (temp_float > TEMP_MAX):
			# ein
			GPIO.output(GATE, True)
			time.sleep(ON_TIME)
			# aus
			GPIO.output(GATE, False)
		else:
			GPIO.output(GATE, False)
		
except KeyboardInterrupt:
	print float(getCPUtemperature())
	print "power off fan..."
	GPIO.output(GATE, False)
	print "cancelling..."

Here you will also find a small drawing for the transistor etc πŸ™‚
https://forum.recalbox.com/topic/3704/push-button-on-off-script-problems/11