Get Ground when 5V are available
Use this circuit. Provide the 5V from the charger LED at control signal terminal. Connect the terminal on/off switch in the place of your window sensor.

The window sensor will get a GND when there is 5V at the charger.