| Algorithm A2 State determination |
| 1. Input: Pbed zone, Pleave zone, Pboundary, Bbpm, Pdepth, P’depth, pThmotion, S’state |
| 2. Output: Sstate |
| 3. If ((Pdepth − P’depth ≤ pThmotion) or S’state = ‘others’) and Pboundary = 0 and Pbed zone = 0 and Pleave zone = 0 and Bbpm > 0 |
| 4. Sstate = ‘sleep locked’ |
| 5. Else |
| 6. If Pbed zone > pThabove sleep level and Pleave zone < pTHleave zone |
| 7. Sstate = ‘sit’ |
| 8. break |
| 9. If Pleave zone > pTHleave zone and Pbed zone < pThabove sit level |
| 10. Sstate = ‘exiting bed’ |
| 11. break |
| 12. If S’state = ‘exiting bed’ and Pleave zone = 0 and Pbed zone = 0 |
| 13. Sstate = ‘leave’ |
| 14. break |
| 15. If Not (S’state = ‘leave’) and Pboundary > pThboundary |
| 16. Sstate = ‘others’ |
| 17. break |
| 18. If S’state = ‘others’ and Pleave zone = 0 and Pbed zone = 0 and Pboundary = 0 and Bbpm = 0 Sstate = ‘both leave’ Break |
| 19. endif |
| 20. S’state = SState\ |
| 21. Display status |