You create an illusion that has the appearance of an object, a creature, or other visible phenomenon within casting distance and cause it to activate in certain situations. The illusion is undetectable until it is activated. It must be no larger than a 30-foot cubic area, and you decide how the illusion should act and what sounds it should make when you cast the spell. This scripted performance can last up to 5 minutes.
Programmed Illusion 5e
Classes: Bard, Wizard
Casting Time: 1 Action
Range: 120 feet
Components: V, S, M
Duration: Until dispelled
When the scenario you specify occurs, the illusion quickly takes shape and performs as it was intended. After the show, the illusion will disappear and remain incubated for 10 minutes. After this time, the illusion can be activated again.
The event that triggers the illusion can be as general or as detailed as you wish, but it must be visible or audible within a 30-foot radius of the target area. For example, you could create an illusion of yourself that appears and warns you when someone else tries to open a trapped door, or you could set up an illusion that triggers when the creature says the right word or phrase.
Since the illusion cannot be touched, any physical interaction with the illusion will reveal its illusionary nature. When a creature investigates an illusion with its action, it can make an Intelligence (Investigation) check against the spell immunity DC to determine whether to see through the illusion. A creature that recognizes an illusion can see through the image, and the sound it produces appears false to the creature.