I've only just had the chance to get back to this. The original battery died not long after my last comment - definitely need these power saving tweaks.
I'm not using setTimeout, just the original code. Your scale suggestion has fixed the points of which the flap is considered: in, out and closed but I'm still getting consistently strange readings - especially when it shuts - it does the Hokey Cokey.
I've set it to log: in (+12,000), out (-12,000) and closed (+/- 4,000) and the z axis of which it triggered.
This was one motion:
OUT: -12602 -> I moved it very slowly until it crossed the out threshold
CLOSED: 682 -> I released it, and it dropped to the shut position, with very little rebound.
IN: 32764 -> This would suggest it practically flew in the opposite direction which it did not.
CLOSED: -1413 -> It's apparently shut again.
OUT: -26331 -> Again, moved gently to the out position yet it reads more than twice the required out position.
CLOSED: -988 -> Closed. No register of in.
IN: 29674 -> Pulled in, very gently. Again measures very high.
CLOSED: 3010 -> Closed.
OUT: -31476 -> Again, you would assume it flew back some way in the opposite direction; it did not.
CLOSED: -1246 -> Closed, again.
@allObjects - Thanks for your thoughts! Actually he's microchipped and when we first got him I looked into reading that but never found the time to put anything into action.
The flap actually has some kind of magnetic mechanism to attach a magnet to a collar, but it doesn't work anymore. It's difficult to get open to find out why without breaking it to pieces. I want to replace the flap entirely to be honest, but it's been so poorly fitted it's a bit of a nightmare to fit a new one. It does have magnets though, so definitely an avenue I could investigate.
Having said that, the accelerometer seems like an elegant solution and would seem to work perfectly well if I'm able to sort the power issues. He hasn't ever stuck his head through and changed his mind - he has to go through a tunnel (through the brickwork) and it's always a committed motion - but appreciate the point you make.
I'll put the glue away, for now ;)