Final version - using threshold 0.3, and comparing current and next two points to previous three points. Gives reasonable results.
minor
Changed database table to read
Trying to make a bit more robust, retry if first database connection fails