Water Tank Level Sensor ESPHome reducing energy consumption

Hi
i m using an ESP8266 with an HC-SR04 Ultrasonic Distance Sensor. I run this with a small Battery an a solar cell for power. actually i try to reduce the power consumption of the HC-SR04 during deep sleep. I connected ground to pin D5. if i switch of this pin the power drops down to 0.000 Amps. But if the ESP goes to deep sleep the pin is low and then the Sensor consumes 0.003 Amps. how can i fix this?
Here is my esphome yaml file.

any other suggestions to improve power consumption? normal deep sleep time is 5min.

substitutions:
  device_name: wassertank
  device_description: Fuellstand des Wassertank
  friendly_name: Wassertank Füllstand

esphome:
  name: ${device_name}
  comment: ${device_description}
  platform: ESP8266
  board: d1_mini
  on_boot:
    then:
      - delay: 1s
      - switch.turn_on: relay1
      - delay: 25s
      - switch.turn_off: relay1
      - delay: 3s
      - deep_sleep.enter: Deepsleep1

wifi:
  ssid: "SSID"
  password: "PW"
  use_address: 192.168.1.183
  fast_connect: on #we only have one WiFi AP so just use the first one that matches
  ap: #since we listed an SSID above, this AP mode will only enable if no WiFi connection could be made
    ssid: ${friendly_name}_AP
    password: ap_pw

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

web_server:
  port: 80

# Sync time with Home Assistant
time:
  - platform: homeassistant
    id: homeassistant_time


text_sensor:
  - platform: wifi_info
    ip_address:
      name: "Wassertank IP"
    ssid:
      name: "Wassertank SSID"
switch:
  - platform: restart
    name: "Wassertanksensor restart"
  - platform: gpio
    pin: D5
    id: relay1
    inverted: true
sensor:
  # Uptime sensor
  - platform: uptime
    name: "Uptime"
  # WiFi Signal sensor
  - platform: wifi_signal
    name: "WIFI Signal"
    update_interval: 5s
#Tanksensor
  - platform: ultrasonic
    trigger_pin: D1
    echo_pin: D2
    name: "Wassertank Füllstand %"
    unit_of_measurement: "%"
    accuracy_decimals: 0
    update_interval: 5s
    filters:
      - lambda: return ((((x*100)-20)-(123-20))/(123-20))*-100;
      - filter_out: nan
      
  - platform: ultrasonic
    trigger_pin: D1
    echo_pin: D2
    update_interval: 5s
    name: "Wassertank Füllstand l"
    unit_of_measurement: "l"
    accuracy_decimals: 0
    filters:
      - lambda: return ((((x*100)-20)-(123-20))/(123-20))*-3000;
      - filter_out: nan
deep_sleep:
  id: Deepsleep1
  run_duration: 30s
  sleep_duration: 10s

The ESP should have just enough current available to power the HC-SR04 from a GPIO pin. Depending on your other GPIO loads.

Set the pin low before going to sleep.

hi
i don’t get your point. the sensor needs 5V so i can’t power it over the gpio.

Some of them work from 3.3v (e.g. https://www.adafruit.com/product/4007 ) I assumed that since you were using an ESP board with 3.3v logic you would have chosen the 3.3v version.