How to invert Sensor output signal?
Why don't you just connect the lamp between output and +24 volts. When the output is high, the lamp will be off. When the output is low, the lamp will be on. I'm presuming that the output can sink lamp current as well as it can source lamp current (as implied in your first picture).