There must be an easier way to do a cancelable auto on and off light based on arrival

I’m in a car on mobile and can’t paste the code properly. Use the code from this link instead.