Ballistocardiography is a technique in which the mechanical activity of the heart is recorded. We present a novel algorithm for the detection of individual heart beats in ballistocardiograms (BCGs). In a training step, unsupervised learning techniques are used to identify the shape of a single heart beat in the BCG. The learned parameters are combined with so-called "heart valve components" to detect the occurrence of individual heart beats in the signal. A refinement step improves the accuracy of the estimated beat-to-beat interval lengths. Compared to other algorithms this new approach offers heart rate estimates on a beat-to-beat basis and is designed to cope with arrhythmias. The proposed algorithm has been evaluated in laboratory and home settings for its agreement with an ECG reference. A beat-to-beat interval error of 14.16 ms with a coverage of 96.87% was achieved. Averaged over 10 s long epochs, the mean heart rate error was 0.39 bpm.