This is a good assumption you are making because this is very much in line with the thinking of the people in a simpler era who nonetheless were more intuitive than today and knew there were problems of roaming discarnate entities, the troubled spirits who were tarrying and seeking something, and that could mean trouble for the living. So the idea of having light at night to drive away the darkness is universally seen as protective, not only because it will keep animal predators at a distance, but it is uplifting and this alone confers some protection innately. This is seen intuitively by many in thinking about the dangers of being alone in the darkness. This is hard-won wisdom from many having been trapped earthbound in between prior lifetimes, so there are many sources of bad association with darkness and demonic forces and the spirit realm in particular.
This also is experienced many times because people are more vulnerable during the sleeping hours as they will stand down consciously, but the subconscious will be available if anything of a dark nature approaches them and carries out an attack to attempt penetrating the defenses. The deep subconscious will know all about it but will not be able to communicate this to the conscious level of the mind in the morning, but nonetheless deep inside there will be a hue and cry when people are once again contemplating being alone in the dark and will feel vulnerable. So this is the basic impulse here that has grown up through many practices across the globe designed to deal with these issues through ritual and acts of protection or would-be protection.