I've had this in my vimrc for a little while:
let hr = (strftime('%H'))
if hr >= 17
set background=dark
elseif hr >= 7
set background=light
elseif hr >= 0
set background=dark
endif
Using a light sensor would be cool, but I actually work from a desktop PC most of the time, so no sensor. I guess the next best thing would be something like f.lux does: query some web service for the sunset time at your current location.