Hi Manuel,
Assuming you are using codebase 3.1.1, in the case of the Ha Dimmable Light demo application, with the default configuration, it should be enough to set the gNvStorageIncluded_d define to TRUE for an existing project, or check the option "Non-Volatile Memory" when creating the project in BeeKit.
After a device joins a network the stack will automatically save all the required network information into NVM. At startup the Ha Dimmable Light demo application will check if the device was previously on a network and, if that is the case, use the NVM information to silently rejoin the network. This way the device should automatically resume normal operation once the power is back on.
In the demo application the code for rejoining the network with NVM is located at the end of the BeeAppInit() function in BeeApp.c, where the ZDO_Start() function is called.
Best Regards,
Cosmin.