Fan Shim Button to turn Pi on and off FYI post

I have a Fan Shim on my Pi 4B. I chose to not install the Daemon and just let the fan run continuously. My temps are consistently right around 40c.
Anyway, I use the Fan Shim button to boot my Pi up, and do a proper shutdown. The boot up is easy, by default momentarily grounding GPIO 3 will boot your pi up. Assuming you left it powered after shutting it down. The Fan Shim Button grounds GPIO 3 when, and while pressed. Its listed as Wake in the Pinout

To get that same button to do a proper shut down you add the following to config.txt
If the Pi is running pressing the button will do a shutdown just like it does from the shutdown menu.

That is until you enable i2c? Once I did that the shut down via the button stopped working. Disable i2c and reboot and it works again. i2c uses GPIO 3 is I guess why this happens? Boot up was fine just no shutdown from the button. Then I noticed the Button also uses GPIO 17 so I changed my code to thei
Shut now works even if i2c is enabled. =)

Name:   gpio-shutdown
Info:   Initiates a shutdown when GPIO pin changes. The given GPIO pin
        is configured as an input key that generates KEY_POWER events.
        This event is handled by systemd-logind by initiating a
        shutdown. Systemd versions older than 225 need an udev rule
        enable listening to the input device:

                ACTION!="REMOVE", SUBSYSTEM=="input", KERNEL=="event*", \
                        SUBSYSTEMS=="platform", DRIVERS=="gpio-keys", \
                        ATTRS{keys}=="116", TAG+="power-switch"

        This overlay only handles shutdown. After shutdown, the system
        can be powered up again by driving GPIO3 low. The default
        configuration uses GPIO3 with a pullup, so if you connect a
        button between GPIO3 and GND (pin 5 and 6 on the 40-pin header),
        you get a shutdown and power-up button.
Load:   dtoverlay=gpio-shutdown,<param>=<val>

Params: gpio_pin                GPIO pin to trigger on (default 3)

        active_low              When this is 1 (active low), a falling
                                edge generates a key down event and a
                                rising edge generates a key up event.
                                When this is 0 (active high), this is
                                reversed. The default is 1 (active low).

        gpio_pull               Desired pull-up/down state (off, down, up)
                                Default is "up".

                                Note that the default pin (GPIO3) has an
                                external pullup.

        debounce                Specify the debounce interval in milliseconds
                                (default 100)

One wrinkle I’d like to work out is that the fan keeps running after the Pi shuts down. This happens even if you have installed the Fan Shim software and the Daemon. Any solution I have found breaks the GPIO startup function. You would have to ground the Global_En pin or Reset pin to boot up. Bummer.
Like doing this for example. Putting a low / ground on the fan control pin will turn the fan off.

 Name:   gpio-poweroff
Info:   Drives a GPIO high or low on poweroff (including halt). Enabling this
        overlay will prevent the ability to boot by driving GPIO3 low.
Load:   dtoverlay=gpio-poweroff,<param>=<val>
Params: gpiopin                 GPIO for signalling (default 26)

        active_low              Set if the power control device requires a
                                high->low transition to trigger a power-down.
                                Note that this will require the support of a
                                custom dt-blob.bin to prevent a power-down
                                during the boot process, and that a reboot
                                will also cause the pin to go low.
        input                   Set if the gpio pin should be configured as
                                an input.
        export                  Set to export the configured pin to sysfs

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 right away. 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