But not how to start write code
You start with JUST reading, and printing, the state of the sensor, as fast as possible. If you see that the state does indeed change as the magnet approaches and leaves, then you look at the state change detecting example to print a message only when the state changes.
Then, you expand on that to note when the state changed. Then, you expand on that to print a message when the state has not changed in a while.
You do all this testing turning the device slowly, by hand.
When it is working the way that you think it should, then you test with the real setup. When you get the "no change has occurred for xxx milliseconds" message appearing properly, with the real setup, then you can replace printing the message with sounding the alarm.
One does not build a house by having all the materials, the furniture, the plumbers, the electricians, the framers, the foundation guys, the roofers, the insulation guys, etc. all arrive at the same time, and expect anything but mass confusion and wasted time and effort.
One build a house by creating a foundation, and adding one wall at a time. One builds the wall one stud (or brick) at a time.
Programming is no different. You seem afraid to get started because the materials, the furniture, the plumbers, the electricians, the framers, the foundation guys, the roofers, the insulation guys, etc. all arrived at the same time. Ignore most of them. Get the foundation in first.