I am trying to write a script to turn my HTPC off automatically and turn it back on again at a specified interval.

I've got the turn on off bit sorted using /sys/class/rtc/rtc0/wakealarm but I want the script to not turn the machine off if say something is downloading, I am currently watching something etc and i dont think I will have any trouble with that.

But what I would really like to be able to do is tell if my TV is currently on. I dont think anything x11 related would work here and this may not even be possible. Does Ubuntu "know" if it's display device is powered on or not? if so can I interrogate this somehow?