I want to make something that has a black glossy shader when a light hits it, e.g. the sun, but when no light hits it at all it turns into an emission shader. I can't figure out how to actually do this, I've tried using the Light Ray inputs but it didn't work.
I am sure Rich Sedman can figure out a mathematical way with nodes.
However I think I would just use drivers for this.
For your material have your glossy shader mixed in with an emission shader.
Right click on the fac of the mix node and choose single driver "set up later"
Make sure you have auto run python in the user pref.
In the graph editor make sure you have it set up like I did. You will need to set up your variable and name it correctly. Choose the spot light and rotation as the object to link the driver to.
When you move the spot light it changes the fac amount on your mix node.