Basically it's tricky because to really know you need to take account of twist, and we don't have a gyro. But because we know that when the total G=1g we're stationary, we can use that to set a baseline - code in that link above
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
This has been asked a few times - including in a forum message that got surfaced today! https://forum.espruino.com/conversations/386551/#16980121
Basically it's tricky because to really know you need to take account of twist, and we don't have a gyro. But because we know that when the total G=1g we're stationary, we can use that to set a baseline - code in that link above