OBJECTIVE: There is an unmet need in epilepsy management for tools that measure sleep objectively over long timespans. Subcutaneous EEG is well-suited for the task, but it requires a reliable automatic algorithm. Here, we present and evaluate such an algorithm, and we show clinical examples of how it produces important information. METHODS: A mix of scalp EEG and subcutaneous EEG was used to develop an algorithm to output sleep stages and common sleep parameters. The algorithm was tested on unseen data from 11 healthy subject and 12 people with epilepsy (PwE). Lastly, data (>
3months) from three exemplary PwE were analyzed for sleep. RESULTS: The algorithm proved non-inferior at sleep stage segmentation on data from PwE compared to human raters using scalp EEG. It reached a Cohen's kappa score of 0.8 [CI 0.78 - 0.83] on healthy subjects and on data from PwE it got to 0.705 [CI 0.663---0.744] against rater D and 0.686 [CI 0.632---0.739] against rater E. The three examples showed that useful information can be gained from longitudinal sleep analysis. CONCLUSION: Subcutaneous EEG and a sleep algorithm can be employed to effectively review sleep in PwE at a level that is non-inferior compared to human raters. SIGNIFICANCE: This has the potential to make objective sleep parameters available in the clinic as a valuable addition to subjective sleep assessments.