Check the status of the lamp with LDR( replacing chain sensor)

This, and the linked topics within it, are a good starting point:

Pete.