The page that you link to says
The regular value without movement is above 1021, upon detecting it, it goes low to 17 - 18.
so your test for greater than 1000 is a bit too close for my liking. What sort of values do you get for alarmValue using your program ?