Du’a for Insomnia and How to Treat It
Question

I am suffering from a lack of sleep; I have insomnia. What is the solution? Is there any way to help me sleep?
Praise be to Allah.Facing difficulties with patience
We ask Allah to grant us and you well being, protection from all problems and healing from every disease. 
We advise you to be patient and seek reward with Allah, may He be glorified and exalted, for He loves those who are patient and rewards those who are grateful. Trials and tests are the divine decree for this world and that is a mercy for the believers and a punishment for the disbelievers. The Prophet (blessings and peace of Allah be upon him) said: “How wonderful is the situation of the believer, for all his affairs are good. This does not apply to anyone but the believer. If something good happens to him, he gives thanks for it and that is good for him; if something bad happens to him, he bears it with patience , and that is good for him.” (Narrated by Muslim, 2999)
It should also be noted that the matter requires some degree of effort and perseverance, as is the case with all psychological or social problems. It takes some gradual training to make oneself get used to something new or to keep away from something reprehensible. Each person knows his own self best and can devise the best approach to achieve the success and wellbeing he wants. 
What is insomnia?
Sleeplessness is a psychological problem which causes difficulty in sleeping, or interrupted sleep or light sleep. It is a modern disease that affects many people for various reasons, including psychological reasons such as pressure, worry, anxiety, waswas (whispers from the Shaytan) and so on. 
And some of its causes are physical because of problems in the function of some organs or the effects of some stimulant substances such as nicotine which is found in tobacco and caffeine which is found in coffee and tea, and other stimulants. 
Remedies for insomnia 
Depending on the reason that has led to this sickness, we can divide the types of remedies into three types: 

Shar‘i remedies

What is meant here is attaining the peace of mind that wards off all worries, anxieties and waswas. The hearts and minds that are filled with love of Allah, hope for His reward, fear of His punishment and focusing on Him are more steadfast than those which are preoccupied with matters of this world and ignore the Hereafter. 
Attaining this peace of mind is done by adhering to obligatory duties and avoiding sins which continue to eat away at the heart until a person finds himself lost in dark valleys, not knowing how he got there; then by showing kindness towards people by means of a good attitude and kind treatment; by being keen to read the Noble Quran and feel an attachment to the Book of Allah, may He be glorified and exalted, which He described in the following verse (interpretation of the meaning): “O mankind! There has come to you a good advice from your Lord (i.e. the Quran, enjoining all that is good and forbidding all that is evil), and a healing for that which is in your breasts, — a guidance and a mercy (explaining lawful and unlawful things) for the believers” [Yunus 10:57]. 
Other means include regularly reciting the adhkar (dhikr) and awrad (wird) narrated in shari‘ah, such as the adhkar for morning and evening , the adhkar to be recited when going to sleep and waking up and when eating and so on. Allah, may He be glorified and exalted, says (interpretation of the meaning): “Those who believed (in the Oneness of Allaah — Islamic Monotheism), and whose hearts find rest in the remembrance of Allah verily, in the remembrance of Allah do hearts find rest.” [al-Ra ‘d 13:28]
Moreover, all of that must be accompanied with humility in the heart towards Allah and feeling a sense of His love and closeness, along with sincerity towards Him in public and in private, hoping to attain the state of true servitude towards Him (‘ubudiyyah) which is the basis of success on the Day of Resurrection. 
On our website you will find a number of answers which will help you – in sha Allah – to implement the shar‘i remedy. Please see these answers: 45847 , 20130 , 21515 , 21677 , 21843 , 22704  and 30901 . 

Psychological remedies

This means trying to rid oneself of worries and anxiety. That can never be achieved except by believing sincerely in the transient and insignificant nature of this world, and that “If it were equal to a gnat’s wing before Allah He would never give a disbeliever a drink of water in it.” It is too insignificant for a Muslim to worry about what he has lost of it or to fear what may happen to him in it. That should also be accompanied by complete contentment with what Allah has decreed and acceptance of His will and decree. These are the means of the believer attaining honour and happiness. Taking these ideas on board requires some effort, repeatedly telling oneself of them, reading books that affirm them and studying and pondering the verses of the Noble Quran which mention them, until they take root in one's heart and become second nature. 

Behavioural remedies

This is where one should seek advice from a doctor or psychologist, because some behavioural or physical causes may be unknown to people but are well known to skilled doctors with the knowledge that Allah has enabled them to acquire about the human psyche. You may find a remedy in some foods which help one to sleep properly. The doctor may also find out about some of your bad habits that lead to worry and sleeplessness. In some chronic and difficult cases of insomnia the doctor may also use some calming medicines which will reduce or ward off harm. 
Shaykh Ibn ‘Uthaymin says in Fatawa Nur ‘ala al-Darb (Fatawa Mutafarraqat/al-Waswas wa’l-Amrad al-Nafsiyyah): 
“The case mentioned by the questioner may be faced by many young people because of mental or physical exhaustion. The remedy for that is for the person to allow himself to rest and recuperate; to remember Allah a great deal and read Quran; to always seek refuge with Allah from the accursed Shaytan; to always ask for forgiveness because seeking forgiveness is one of the means of attaining good and warding off evil; to strive to keep company with good people like him, because a good companion is like the carrier of musk - he will either give you some or sell you some or you will find a good smell from him. He should try to keep away from that which he should not think about, because thinking of something may make a person move from imagining it to actually doing it, but if he tries to ignore it and forget it, then by Allah’s leave it will cease to trouble him.” 
Authenticity of hadiths about du’a for insomnia
We should not forget to point out here the weakness of the reports narrated by some scholars about adkhar to be recited just before going to sleep in order to free oneself from insomnia. Imam al-Nawawi included a chapter in his book al-Adhkar (p. 70) entitled: 
Bab ma yaqul idha qaliqa fi Firashihi fa lam yanam (What to say if one feels anxious in bed and cannot sleep): 
“We narrated in the book of Ibn al-Sunni that Zayd ibn Thabit (may Allah be pleased with him) said:
I complained to the Messenger of Allah (blessings and peace of Allah be upon him) about insomnia that I was suffering from. He said: Say: O Allah, the stars have come out and eyes have closed, and You are the Ever Living, the One Who sustains and protects all that exists; neither slumber nor sleep overtakes You. O Ever-Living, O Sustainer, bring calm to my night and let my eyes sleep. O Allah, take away from me what I am suffering. 
And we narrated from Muhammad ibn Yahya ibn Habban from Khalid ibn al-Walid (may Allah be pleased with him) that he suffered from insomnia and he complained about that to the Prophet (blessings and peace of Allah be upon him), and he told him, when going to sleep, to seek refuge in the perfect words of Allah from His anger and from the evil of His slaves and from the whisperings of the devils, lest they come near. This hadith is mursal; Muhammad ibn Yahya is a Tabi‘i. 
And we narrated in the book of al-Tirmidhi, in a da‘if report that was classed as such by al-Tirmidhi, that Buraydah (may Allah be pleased with him) said: Khalid ibn al-Walid (may Allah be pleased with him) complained to the Prophet (blessings and peace of Allah be upon him): O Messenger of Allah, I cannot sleep at night because of insomnia. The Prophet (blessings and peace of Allah be upon him) said: When you go to your bed, say: O Allah, Lord of the seven heavens and what they shade, Lord of the seven earths and what they contain, Lord of the devils and what they misguide, be a protection for me from the evil of all Your creation, lest any of them wrong me or transgress against me. The one who is under Your protection is honoured; may You be glorified and praised, there is no god beside You, there is no god but You.”
These hadiths are da‘if, as has been determined by the scholars such as Ibn Hajar in Nataij al-Afkar, 3/114 and al-Matalib al-‘Aliyah, 4/20; and by al-Albani in al-Silsilah al-Da’ifah, 2403, and others. 
And Allah knows best.