Is my understanding roughly correct?
- Melatonin is 'generated' in the absence of specific wavelengths of light.
- It accumulates and is only reduced by sleep, in particular REM sleep.
- Melatonin and sleepiness have a causal relationship.
There is an entry in the Encyclopædia Britannica on Melatonin which gives a run-down on how melatonin is produced and it's use within sleep, regulating reproductive hormones, and helping the immune system.
In humans, melatonin plays an important role in the regulation of sleep cycles (i.e., circadian rhythm). Its production is influenced by the detection of light and dark by the retina of the eye. For example, the production of melatonin is inhibited when the retina detects light and is stimulated in the absence of light. Special photoreceptor cells in the retina send signals about light status to the suprachiasmatic nucleus (SCN) in the hypothalamus of the brain. These signals are then transmitted to the pineal gland. Melatonin generation by the pineal gland, which peaks during the nighttime hours, induces physiological changes that promote sleep, such as decreased body temperature and respiration rate. During the day, melatonin levels are low because large amounts of light are detected by the retina. Light inhibition of melatonin production is central to stimulating wakefulness in the morning and to maintaining alertness throughout the day.
Therefore, to correct points 1-3 in your question...
Melatonin is produced when the retinas do not pick up any light.
Melatonin accumulates in the body during sleep and is reduced when the retinas pick up light.
Melatonin regulates sleep cycles by inducing physiological changes that promote sleep, such as decreased body temperature and respiration rate.
Because melatonin regulates sleep cycles, melatonin has a big role to play in mental wellbeing. Deregulation or misregulation of circadian rhythms can cause mood spectrum disorders, including bipolar disorder (BD), major depressive disorder (MDD), and seasonal affective disorder (SAD). (De Berardis, et al. 2015)
De Berardis, D., Orsolini, L., Serroni, N., Girinelli, G., Iasevoli, F., Tomasetti, C., Mazza, M., Valchera, A., Fornaro, M., Perna, G., Piersanti, M., Di Nicola, M., Cavuto, M., Martinotti, G. & Di Giannantonio, M., 2015. The role of melatonin in mood disorders. ChronoPhysiology and Therapy, 5, pp. 65-75
DOI: 10.2147/CPT.S41761