Control pihole with touchphat - how?


On my raspberry zero w, I want to control pihole with touchphat. When the button back is pressed, pihole should disable blocking for 10 mins, when enter is pressed, pihole should enable blocking.

Beeing a python novice, I wrote a simple script. Started from the command line, It seems to work fine, with 2 limitations:

  1. after pressing the buttons back or enter, the led lights up and the pihole command is executed, but then the led keeps staying on. Why?
  2. after pressing buttons, which weren’t defined in the if, the corresponding leds light up (and go off again)

I would like that button presses of undefined buttons don’t provoke any led action. And I would like that after pressing the defined buttons back and enter the leds light up an go off again, after (or before) the pihole command has been processed. I put the “touchphat.led_off(” after executing pihole to turn off the led, but it isn’t a clean solution.

import signal
import os
import touchphat

def handle_touch(event):
          os.system("pihole disable 10m")
          os.system("pihole enable")

My other question is: how can I implemet the autostart of my script with pihole? I put the command “python /home/pi/Pimoroni/touchphat/examples/” in the file /etc/rc.local, but it isn’t executed.

Are there any suggestions, how to change the code?