I do think data in NV flash would be changed whenever power is unplugged and plugged. I would suggest you to check the return value of osal_nv_write(LIGHT_STATE, 0, 1, &lightState). Check if it return success. I would suggest to use the following code.
do
{
} while (osal_nv_write(LIGHT_STATE, 0, 1, &lightState)!=SUCCESS)