Onmy?d? (, also In'y?d?, lit. 'The Way of Yin and Yang') is a system of natural science, astronomy, almanac, divination and magic that developed independently in Japan based on the Chinese philosophies of yin and yang and wuxing (five elements). The philosophy of yin and yang and wu xing was introduced to Japan at the beginning of the 6th century, and influenced by Taoism, Buddhism, and Confucianism, evolved into the earliest system of Onmy?d? around the late 7th century. In 701, the Taiho Code established the departments and posts of onmy?ji who practiced Onmy?do in the Imperial Court, and Onmy?d? was institutionalized. From around the 9th century during the Heian period, Onmy?d? interacted with Shinto and Gory? worship (?) in Japan, and developed into a system unique to Japan. Abe no Seimei, who was active during Heian period, is the most famous onmy?ji (Onmy?d? practitioner) in Japanese history and has appeared in various Japanese literature in later years.Onmy?d? was under the control of the imperial government, and later its courtiers, the Tsuchimikado family, until the middle of the 19th century, at which point it became prohibited as superstition.
In the 5th and 6th centuries, the principles of yin-yang and the Five Elements were transmitted to Japan from China and Baekje along with Buddhism and Confucianism, particularly by the obscure Korean monk Gwalleuk. Yin-yang and the Five Elements, as well as the divisions of learning to which they were linked - astronomy, calendar-making, the reckoning of time, divination, and studies based on observation of nature - were amalgamated into fortune telling. This process of judging auspicious or harmful signs present in the natural world, was accepted into Japanese society as a technique for predicting good or bad fortune in the human world. Such techniques were known mostly by Buddhist monks from mainland Asia, who were knowledgeable in reading and writing Chinese. Over time, demand from members of the imperial court who believed that onmy?d? divination would be helpful in decision-making, made it necessary for the laity to perform the art, and onmy?ji began to appear around the middle of the 7th century. Under the Taiho Code enacted in the early 8th century, the departments of the Imperial Court to which onmy?ji belonged were defined by law.
From around the 9th century during the Heian period, Onmy?d? interacted with Shinto and Gory? worship in Japan, and developed into a system unique to Japan. Until then, Onmy?d? emphasized divination for policy decisions by high government officials, but since the Heian period, Onmy?d? has emphasized magic and religious services such as warding off evil for preventing natural disasters and epidemics and for the productiveness of grain, as well as curses against opponents. Because Shinto places importance on 'purity' Shinto priests were required to perform misogi (ritual purification) and fast before performing these religious services, so their activities were restricted. On the other hand, since onmy?ji did not have to perform misogi or fast, they were able to deal with kegare (uncleanness) more easily, and they expanded their activities beyond the support of Shinto priests. It gradually spread from the Imperial Court to the general public. In the 10th century Kamo no Tadayuki ( ) and his son Kamo no Yasunori ( ), made great advancements in onmy?d?, astronomy and calendar science. From among their students emerged Abe no Seimei (?), who displayed superior skills in the divining arts of onmy?d?, by which he gained an uncommon amount of trust from the court society. Tadayuki and Yasunori passed on their skills in astronomy to Seimei while their advances in calendar-making went to Yasunori's son. From the end of the Heian period into the Middle Ages, astronomy and calendar science were completely subsumed into onmy?d?, and the Abe and Kamo families came to dominate the art in the Imperial Court.
Onmy?ji (, also In'y?ji) was one of the classifications of civil servants belonging to the Bureau of Onmy? in ancient Japan's ritsuryo system. People with this title were professional practitioners of onmy?d?.
Onmy?ji were specialists in magic and divination. Their court responsibilities ranged from tasks such as keeping track of the calendar, to mystical duties such as divination and protection of the capital from evil spirits. They could divine auspicious or harmful influences in the earth, and were instrumental in the moving of capitals. It is said that an onmy?ji could also summon and control shikigami. During the Heian period the nobility organized their lives around practices recommended by onmy?ji. The practice of "lucky and unlucky directions" provides an example. Depending on the season, time of day, and other circumstances, a particular direction might be bad luck for an individual. If one's house was located in that direction, such an individual was advised not to go back directly to his house but had to "change direction" (katatagae), by going in a different direction and lodging there. Such a person would not dare to go in the forbidden direction, but stayed where they were, even if that resulted in absence from the court, or passing up invitations from influential people.
Onmy?ji had political clout during the Heian period, but in later times when the imperial court fell into decline, their state patronage was lost completely. In modern-day Japan onmy?ji are defined as a type of priest, and although there are many who claim to be mediums and spiritualists, the onmy?ji continues to be a hallmark occult figure.