"Mitzvah gedola le'heyos be'simcha..." many of us have heard this. I am wondering if there is an actual mitzvah to be be'simcha? (I am looking for sourced comments and not just idea's). I know that simcha is not counted as a mitzvah by the Rishonim, but I think the question still stands. I have heard that the Chasam Sofer (in parshas VaYechi) says that it is a mitzvah deoraysah and explains why the Rishonim don't count it, but I couldn't find it.
The teachings of the Lubavitcher Rebbe on the topic of Simcha are collected in a sefer called "Simcha Ubitachon B'Hashem" published by Heichel Menachem. The entire first chapter (some 60 pages) deals with the obligation of being happy.
"The happiness with which a person should rejoice in the fulfillment of the mitzvot and the love of God who commanded them is a great service. Whoever holds himself back from this rejoicing is worthy of retribution, as states: "...because you did not serve God, your Lord, with happiness and a glad heart."
"A person should direct his heart and the totality of his behavior to one goal, becoming aware of God, blessed be He. The [way] he rests, rises, and speaks should all be directed to this end." That is, every action a person performs must be for the sake of Hashem.
The Rebbe comments that in order to act in accordance to both rulings one is obligated to be happy constantly.
Commentaries on Likutey Moharan (I think it's Parparos Lechochma but I'm not sure, as I'm looking in the English edition - b'n I'll try and look it up) bring the following sources for an actual mitzva of simcha:
David Hamelech says "serve G-d with simcha", which Rabbenu Bachya connects to the previous verse in Dvarim.
Apart from this, Rebbe Nachman cites Yad Ramah on Sanhedrin 17b that there is an obligation to be happy in "Guard your self and guard your soul diligently...", as depression leads to poor health and sin, chas veshalom.
Rabbenu Bahya writes in Kad HaQemah (Simha) that we don't find any sources which praise joy except for joy in serving God:
אין השמחה ראויה בעוה"ז כי אם בעבודת הש"י ולא תמצא בכל ספרי הקדש שישבח השמחה אלא בענין העבודה וההשגה בהקב"ה
Rambam writes in Hilkhot De'ot (1:8) that one should be happy all the time:
ולא יהא מהולל ושוחק, ולא עצב ואונן, אלא שמח כל ימיו בנחת, בסבר פנים יפות
Rambam in Hilkhot Yom Tov (6:19) writes that we are only commanded in joy that that includes service of God:
ולא נצטווינו על ההוללות והסכלות, אלא על השמחה שיש בה עבודת יוצר הכול
At the end of Hilkhot Lulav (8:15) he writes that joy in serving god is a great avodah (divine service):
שהשמחה שישמח אדם בעשיית המצוות ובאהבת האל שציווה בהן, עבודה גדולה היא
So although Rambam writes that one should be happy all the time, it seems that the primary joy that one is encouraged to have is joy in the context of religious service, as Rabbenu Bahya wrote.
Source for the quote
The quote itself is found in Likkutei Moharan (Tinyana Torah 24) who phrases it in terms of Galen's humours:
מצוה גדולה להיות בשמחה תמיד, ולהתגבר להרחיק העצבות והמרה שחורה בכל כחו
Significantly, and less frequently quotes, he clarifies there that one should set aside a time of the day to be brokenhearted and pray to God:
אף שגם לב נשבר הוא טוב מאד, עכ"ז הוא רק באיזו שעה. וראוי לקבוע לו איזה שעה ביום, לשבר לבו ולפרש שיחתו לפניו
Is it a mitsvah
"I know that simcha is not counted as a mitzvah by the Rishonim":
Actually, Rabbenu Bahya writes in multiple places that joy is a mitsvah...When it is joy for mitsvot. For example, he writes in his commentary to Deuteronomy (28:47):
והשמחה במעשה המצוה מצוה בפני עצמה
The joy in doing a mitsvah is a mitsvah in and of itself.
You are correct that the vast majority of Rishonim, such as Rambam, do not count it as its own technical mitsvah. However, as we quoted from him, he nevertheless states that it constitutes a great act of divine service
This post differentiates between being happy in general and serving God in happiness. The latter of which seems to be your question. His conclusion (tl;dr) is:
As it appears to me, the Jewish attitude to simcha (happiness) is nuanced. Proper simcha, though not a mitzva, can be desirable / praiseworthy. Other simcha is undesirable, even forbidden. One should beware of overly exalting simcha and making / proclaiming 'simcha' a major thrust of one's Judaism. Let us not forget the classic Rabbinic dictum "Kol hamosif goreia" (whoever adds, actually subtracts). If Hashem did not make something a mitzvah, it is presumed to have been for good reason and we are forbidden to put it in that category.
I believe that having inner simcha (happiness) is a branch of the Mitzva to love Hashem "with all your heart, all your soul, and all your possessions (Deuteronomy 6:5)" which many Rishonim consider a Mitzvah, and some consider it a constant one (Sefer HaChinuch). If you love someone, you are naturally happy, especially, when you love the source of life itself. It's simple logic.
Further, Talmud Bavli (Brachot 60B) teaches, based on the aforementioned verse, that one has to bless Hashem for bad occurrences just like by good occurrences; and explains that you have to accept the bad with simcha (as Rashi explains לברך על מדת פורענות בלבב שלם). If the Torah expects us to do this with bad, then we certainly must be happy with everything else in life.
The Gemarah goes on to bring other verses in Tanach to back up this idea, and then brings the famous story about Rabbi Akiva, in which he remarks that "Everything the Merciful One (viz. Hashem) does is for good." How can one not always be happy if they live with such an attitude?!
(I think the confusion is centered more around how much external joy Hashem wants us to express. Different situations in life call for varying emotional displays ranging from mourning to elatedness. Also, the degree of emotional expression will be in accordance with one's level of inner happiness combined with their personality type, and ultimately should be based on their decision precisely how to express themselves (depending on how much self-control they have). However, I assure you, if you are happy within, it will naturally show on the outside.)