Yaml problem on esphome

I’m trying to switch on a water pump when soil moisture exceeds a set value. I then wate a set time and switch off. I keep getting a errof line 47 col 19 no matter what i do .

my code

/ accuracy_decimals 1
/ on_value_range:
/ - below: 0.4
Any help would ne appreciated. Also guidance on YAML
might clearup some of the mysteries
I would include all my code but cant find instructions for <?>

esphome:
  name: 32-soil-moisture
  friendly_name: 32 soil moisture


  platform: ESP32
  board: node32s


# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "xSPemlHe3fu4SxFAh8y9EPSF7uc/xSsj46xUhov9O04="

ota:
  - platform: esphome
    password: "c1b89da70746de31040566e3a5a0053c"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "32-Soil-Moisture"
    password: "59pb65v8DhDS"

captive_portal:

switch:
  - platform: gpio
    pin: gpio22
    name: "water_pump"
    id: pel1_water1

sensor:
  - platform:gpio
    id: moisture_voltage
    name:"Soil Moisture Voltage"
    pin: gpio 36
    accuracy_decimals 1
    **on_value_range: **
**      - below: 0.4**
        then:
          - switch.turn_on: pel1_water1
          - delay: 2s
          - switch.turn_off: pel1_water1
      - above: 0.45
        then:
          - switch.turn_off: pel1_water1   
filters:      

 - sliding_window_moving_average:
   window_size: 60
   send_every: 60

    

Format it with this button:

Top of the menu when you click the gear icon.
image

The first thing to remember is that yaml is a POSITIONAL language, indentation means everything. Get the indentation wrong and your code will not work. For example, here is the correctly indented code for your sensor:

sensor:
  - platform: adc
    id: moisture_voltage
    name: "Soil Moisture Voltage"
    pin: gpio36
    accuracy_decimals: 1
    on_value_range: 
      - below: 0.4
        then:
          - switch.turn_on: pel1_water1
          - delay: 2s
          - switch.turn_off: pel1_water1
      - above: 0.45
        then:
          - switch.turn_off: pel1_water1   
    filters:      
      - sliding_window_moving_average:
          window_size: 60
          send_every: 60

You also had missing and extra spaces, missing colons - all will make a difference as to whether the code works.

Go over the rest of your code to check things, I only looked at the sensor. At a quick glance - you have logger: indented incorrectly, and stuck in the middle of the wifi: section. There may be more…

EDIT: and I think you mean adc for your sensor platform. gpio is valid for binary sensors.

Thanks for your reply. Can you send me links for learning YAML as i have not found anything useful

The Home Assistant YAML page is a good place to start, even though it’s HA specific.

There is a link in there to an external site which will give you some info, or just Google “yaml tutorial”.

Also, look at the cookbook entries in ESPHome for completed projects: