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:
- 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?
- 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(event.name)” after executing pihole to turn off the led, but it isn’t a clean solution.
import signal import os import touchphat @touchphat.on_touch(["Back","Enter"]) def handle_touch(event): if event.name=="Back": os.system("pihole disable 10m") touchphat.led_off(event.name) elif event.name=="Enter": os.system("pihole enable") touchphat.led_off(event.name) signal.pause()
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/pihole.py” in the file /etc/rc.local, but it isn’t executed.
Are there any suggestions, how to change the code?