The ‘fail_safe_set_to’ parameter did the trick but only after I updated the firmware to the latest edge version. Before that an M112 event was not triggering this parameter.
What is occurring now is the startup_state is not being correctly set. In this case the fan does not initialise as on when the smoothieboard starts up.
Here is the code I am using: