Thanks to Franco's help, we found a silly bug in the code: the condition in an if statement was checking for a string that didn’t exactly match the actual socket label, so the command to switch the socket ON/OFF was never executed. The bug has now been fixed.