How to turn Fan Shim Fan off on shutdown

One minor annoyance for me is that the Fan on the Fan shim keeps running when I do a shutdown from Raspbian on my Pi 4B. This isn’t a complaint, more of an observation type deal.
Why it does this is I believe a failsafe mode. If you install the Fan Shim and don’t install any software the fan will run and cool your Pi. Thats what you want to happen. You have to pull the fan control pin low to turn it off. Thats what the control Daemon does.
When you do a shut down the Daemon stops running and the control pin (GPIO pin) goes to a floating state and the fan runs. You have to unplug the power supply to stop it. Not a big deal for most people. I like to use the Fan Shim button to do the shut down, and boot the Pi up again when pressed again. That works fine, I just don’t want the fan running when its off.

I found a really easy solution that works for me. I just wired a 10k resistor from the Fan Shim, Fan Control pin, GPIO 18 physical pin 12 to ground. A pull down resistor that will make the default state of the fan off. You will have to command it on, with either the dtoverlay=gpio-fan config.tx entry, or via the Pimoroni software Daemon. I tested both and it worked as I wanted. The Fan turned on and off when it should with the Daemon, and turned on as it should with the dtovery entry. Pressing the button on the Fan Shim to do a shutdown had the fan stop. And stay off even with the power supply plugged into the Pi. Pressing the button again on boot up the fan was off if the temp was below the on threshold. :D

I like to just leave the fan running continuously while the Pi is on, just my personal preference, my temps hover right around 40c. I added this entry to my config.txt to turn the fan on at 30c. I don’t use the Daemon. You can with my mod but I don’t.
For the shutdown function I added this line to config.txt
You could just add dtoverlay=gpio-shutdown and it will work via GPIO 3, thats the pin used to do the boot up when the button is pressed. If you turn i2c on though the shutdown via GPIO 3 stops working which is why I went with the GPIO 17 entry.
Disclaimer, my mod breaks the fail safe auto on function. You will have to command the fan to run to have it turn on. Failing to do that will have your Pi potentially running Hot, it won’t overheat though, it will just down clock and you’ll lose performance. Install the Pimoroni daemon and thats not an issue, the fan will turn on when needed and off when things are cool.