Since the speed at which the windows/sunroofs open varies (for example, my passenger side front window takes 2 or 3 seconds more to close than the driver's side front window), a timed relay probably isn't a good idea. Feeding power to a motor that can't turn (even for a few seconds at a time) will eventually burn it up. Also, there's a safety concern -- what if someone's hand or arm is in the opening when the sunroof is triggered to close?
Here's how the factory automatic windows work:
When you push the switch to automatically
open the driver's side window (or the sunroof in the new models) you're triggering a latching relay to continuously feed power to the sunroof or window motor until another event occurs. When the window or sunroof reaches some position inside the frame, either there's a microswitch that gets pushed or there's a sensor on the amperage draw of the motor (the power draw goes up when the motor can't turn) that de-energizes the latching relay. That opens the latching relay and stops feeding power to the motor.
Ways to change the sunroof:
Amperage draw sensor: I'm not sure whether Hyundai used microswitches or amperage-draw monitoring for the windows and sunroof, but the amperage-draw sensor would be the most elegant solution. However it would be very difficult to implement as an individual aftermarket add-on.
A microswitch/relay system would be relatively simple to build, but there are some major issues with it. You see, with
opening the sunroof (or the windows), there's "slop" where the sunroof slides back into the roof -- once it's clear of the opening, it doesn't need to be sealed against anything when open, so a microswitch could be mounted as the stopping point of the travel.
The problems with using a microswitch to monitor the
closing of a sunroof (or window) is that:
- If the switch is mounted too far in, the sunroof wouldn't fully close.
- If it's mounted too far out, the motor will continue to run, burning it out eventually.
- If something blocks it's travel, it will continue trying to close and trap whatever is in the opening.
Those are some of the reasons that relatively few cars with power windows(Nissan Maxima is one exception) have auto-closing windows / sunroofs. Some do but I believe that the law requires that they have to incorporate the automatic stop if something gets in the way of the window travel (yet another circuit and more $).
Reference:
I believe the Dodge minivans have auto-closing sunroofs, but I'll bet that they use amperage monitoring to shut them off and also include the emergency stop feature to keep from trapping things in the roof. It may be worth checking out the circuitry of a vehicle with an auto closing window to see how it's properly implemented. You could also take a look at the driver's side window circuit to see if there are any sensors at the bottom of the window travel for reference.