Trigger digital out when sensor is read

Hi, banging my head against the wall on this. Have a soil moisture reader that if i understand correctly will wear out if left on the whole time. Seeing examples on other platforms for how to use digital IO to power the sensor while its being read and then turn it of again. Cant figure out if this is possible on esphome on HA. So anyone done anything similar ?

Using a D1 mini and and YL-69.

Set the update interval of the sensor to a very long time.

Create an automation with an interval trigger for the update rate you want.

Actions would be:

Turn on the gpio that powers your sensor.
Delay ?
Update your sensor manually,
Delay ?
Turn off the gpio that powers your sensor.

See this video
#207 Why most Arduino Soil Moisture Sensors suck (incl. solution)

Thanks, seems to have it working. Will post the code for future beginners looking for examples

  - platform: adc
    pin: A0
    name: "Soil Moisture Sensor"
    #accuracy_decimals: 0
    update_interval: never
    id: soil_moisture_sensor
    #- lambda: return x * 100.0;
  - platform: gpio
    name: "Moisture Sensor Power"
    id: moisture_sensor_power
      number: D0
      mode: OUTPUT
    restore_mode: ALWAYS_ON

  - interval: 1min
      - switch.turn_on: moisture_sensor_power
      - delay: 2s
      - component.update: soil_moisture_sensor
      - delay: 2s
      - switch.turn_off: moisture_sensor_power