Problem with dallas ds18b20

I would like to make a sensor that turns on the vcc gpio of the ds18b20 and turns it off when it sleeps but it doesn’t work properly…

the goal is that the esp32 sleeps for 5 minutes wakes up turns on the vcc of the sensor reads the sensor turns off the vcc and sleeps again.

here is my code that does not work correctly :

esphome:
  name: lolin32-test
  on_boot:
    priority: 800
    then:
        - switch.turn_on: sensor_power

esp32:
  board: esp32dev
  framework:
    type: arduino



# Enable logging
#logger:
#  level: DEBUG
# Enable Home Assistant API
api:
  encryption:
    key: ""

ota:
  password: ""

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Lolin32-Test Fallback Hotspot"
    password: ""

captive_portal:

# power temp sensor
switch:
  - platform: gpio
    id: sensor_power
    pin:
      number: 19
      inverted: false

deep_sleep:
  run_duration: 5s
  sleep_duration: 5min
  id: "deep_sleep_1"

dallas:
  - pin: GPIO23
    id: my_dallas
    update_interval: 1s

# Individual sensors
sensor:
  - platform: dallas
    address: 0x46fdc0531f64ff28
    name: "sortie cheminée"
    id: my_sensor
    on_value:
      then:
        - switch.turn_off: sensor_power
        - deep_sleep.enter: deep_sleep_1

#status_led:
#  pin:
#    number: GPIO22
#    inverted: true

think you have to turn on the vcc switch.

add this to your switch
restore_mode: ALWAYS_ON

the default is RESTORE_DEFAULT_OFF
which restores the last state but you turn it off before deep_sleep. so I guess it restores to off as thats the restored value?

the log :

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13132
load:0x40080400,len:3036
entry 0x400805e4
[I][logger:258]: Log initialized
[C][ota:469]: There have been 0 suspected unsuccessful boot attempts.
[D][esp32.preferences:113]: Saving 1 preferences to flash...
[D][esp32.preferences:142]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[I][app:029]: Running through setup()...
[D][switch:013]: 'sensor_power' Turning ON.
[D][switch:056]: 'sensor_power': Sending state ON
[C][switch.gpio:011]: Setting up GPIO Switch 'sensor_power'...
[D][switch:013]: 'sensor_power' Turning ON.
[D][switch:013]: 'sensor_power' Turning ON.
[C][dallas.sensor:032]: Setting up DallasComponent...
[C][wifi:037]: Setting up WiFi...
[C][wifi:038]:   Local MAC: C8:C9:A3:CB:73:10
[D][wifi:386]: Starting scan...
[D][dallas.sensor:143]: 'sortie cheminée': Got Temperature=34.8°C
[D][sensor:127]: 'sortie cheminée': Sending state 34.75000 °C with 1 decimals of accuracy
[D][switch:017]: 'sensor_power' Turning OFF.
[D][switch:056]: 'sensor_power': Sending state OFF
[I][deep_sleep:116]: Beginning Deep Sleep
[I][deep_sleep:118]: Sleeping for 300000000us
[D][esp32.preferences:113]: Saving 1 preferences to flash...
[D][esp32.preferences:142]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed

it seems that it never sends the value of the sensor…
I added the ALWAYS_ON and nothing changes

ok, looks like it gets a temperature value from the dallas, but it is not connected to wifi, it looks like it start to scan for networks.

Maybe 5 seconds awake time is to short or the network information is incorrect or are you running a wifi that is “hidden”?

it is certainly that he has no time to connect to the wifi

Try if using fast_connect: true under wifi, this might help with a faster connection.