The document describes a new automatic sleep staging algorithm using state machine-controlled decision trees that is suitable for resource-constrained wearable devices. It extracts spectral features from EEG signals and classifies sleep stages using a series of small, context-specific decision trees organized by a state machine. This approach reduces computational complexity and power consumption compared to traditional classifiers. The algorithm achieved an accuracy of 82.22% on training data and 78.85% on test data from the PhysioNet Sleep EDF Expanded Database using only a subset of decision trees tailored to each sleep stage state.