How to avoid input floating ports on a microcontroller?
You still need a pull-up or pull-down resistor as appropriate.  If the sensor connects between Vcc and the input pin, and if the sensor is open-circuit when off, then it would be a pull-down resistor.  If the sensor connects between ground and the input pin, you need a pull-up resistor.

The resistor needs to be chosen so that it has a substantially higher resistance than the sensor.