What I have done is attach the ground pin of the sensor to GPIO0 rather than GND. GPIO0 will be HIGH at boot time ensuring that the output pin of the sensor is also HIGH but then I pull it LOW after boot which then permits the sensor to work normally by including this code in setup():
void setup() {
...
pinMode(0, OUTPUT);
digitalWrite(0, LOW);
}
So by doing this, GPIO0 defaults to HIGH on boot, which keeps the sensor (which is therefore not connected to GND at all during boot) HIGH and so keeps GPIO2 HIGH. Then, after boot, GPIO0 is pulled LOW by the code snippet above which means the sensor then is connected to GND and therefore works normally. Now my device works as expected using the ESP-01.