A device for use with a flow generator that generates a supply of pressurized air to be provided at an outlet to a patient for treatment, wherein the device comprises: a sensor to receive a first signal generated from an emitter and a second signal reflected from a patient interface; and a controller that is configured to process the first signal and reflected second signal, and being configured to detect the connection of the patient interface based on the processed reflected second signal.