Just an idea for you :-) https://www.quartoknows.com/page/raspberry-pi-shutdown-button It needs a little less resources and is another way of implementation.