Using a GPIO as power supply for DS18B20

I have a project that has a DS18B20 connected to it (w 4.k7 resistor)

Occasionally in my experience with these sensors, they deliver nan and sometimes need to have the power disconnected from them.

Is there any reason I can’t/shouldnt use a GPIO 3.3v output as the power supply, so that when the sensor delivers nan I can essentially perform a reboot on the sensor?

I guess not, since average power consumption of Dallas is only 1mA. Perhaps i’d add a small capacitor (from gpio to gnd), though, to eliminate spikes.
Regarding showing “nan”…i have quite some of these and they never show nan. So, perhaps your sensor is faulty, or perhaps you can try with smaller pullup resistor, especially if wire from esp to sensor is long.

I was able to do this with a SHT and BMP280. I found I had to make the pin go high as early as possilbe otherwise it wouldn’t work at all if pin came up after the rest of the software loaded. In my device I was using gpio13.

  on_boot:
    priority: 1000
    then:
      - lambda: |-
          pinMode(13, OUTPUT);
          digitalWrite(13, HIGH);

Made me thinking…
If you cut the power from dallas, i wonder if it will re-initialize and start working again when you re-apply power… usually init is executed at power-on only. So perhaps module reboot is only option… i was thinking purely hardware back up…

The best approach would be to find the actual problem. What you get on log when it freezes?