Here is my snippet for checking time left on buffs (on yourself).
_, _, _, _, _, duration, expirationTime, _, _, _, _ = UnitBuff("player","Inquisition");
t = GetTime();
timeRemaining = expirationTime - t;
if (timeRemaining <= 6) then retV = "1";
else retV = "0";
end
This will cast Inquisition when there is 6 seconds left on the buffs life. Great for spells that you want up 100% of the time. To get this to work, you might have to remove the line breaks, so it would actually look like..
_, _, _, _, _, duration, expirationTime, _, _, _, _ = UnitBuff("player","Inquisition");t = GetTime();timeRemaining = expirationTime - t;if (timeRemaining <= 6) hen retV = "1";else retV = "0";end