Need a little help please

so i have a few XKC-Y25-PNP sensors on a ESP32s, so there is one sensor to one board. i have tried to hook up 2 sensors to 1 board and it works… kind of. so when NOT inverted they both work changing back and forth to “Dry” & “Wet” every second no problem. the issue is when i set “inverted” to True they change to dry, but don’t change state when there is actually something there i.e… my finger (testing purposes can anyone help? I’m really only started to dip my toes into this kind of as i did just use off the shelf items so bear with me. this is the code:-

PS once i get this sorted i plan on changing the other 2 into 1 board

binary_sensor:

  • platform: gpio
    pin:
    number: GPIO13
    inverted: true
    mode:
    input: true
    pullup: true
    name: “1/4 Full”
    device_class: moisture
    filters:

    • delayed_on: 1s
    • delayed_off: 1s
  • platform: gpio
    pin:
    number: GPIO12
    inverted: true
    mode:
    input: true
    pullup: true
    name: “1/2 Full”
    device_class: moisture
    filters:

    • delayed_on: 1s
    • delayed_off: 1s

Please format your code correctly as per this.

That way others can read and check your code.

1 Like

thank you, for the answer but i did take the code directly from ESPHome as i don’t really know how to format it correctly

That’s why @Arh linked to the post that explains how to format it correctly :raised_hands:

1 Like

When posting a reply use the formatting symbol above the reply which looks like this
</> it then puts the dots in and tells you where to put your code.

i see, now i get ya.

binary_sensor:

  • platform: gpio
    pin:
    number: GPIO13
    inverted: true
    name: “1/4 Full”
    device_class: moisture
    filters:

    • delayed_on: 10s
    • delayed_off: 10s
  • platform: gpio
    pin:
    number: GPIO14
    inverted: true
    name: “1/2 Full”
    device_class: moisture
    filters:

    • delayed_on: 10s
    • delayed_off: 10s

i hope this is better

No

When you hit that button above. It says “type or paste code here” this is where you paste your text. You will then end up with it looking something like this. This can then be checked for indentation or syntax issues.

captive_portal:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode:
        input: true
        pullup: true
      inverted: true
    name: "3D Printer Button"
    on_press:
      - switch.toggle: relay

sensor:  
  - platform: wifi_signal
    name: "Greenhouse Signal Sensor"
    update_interval: 60s

The link to the forum guidelines is good, but it doesn’t explain why and how to format code as good as our Cookbook entry:

@darrenmonk87
It’s not that we don’t want to, but we need to see, if there are indentation or white space errors in the code. :slight_smile:

That being said, as you took the code from the ESPHome page, it should be correct. Please keep in mind, you need to copy it exactly - no changes in white space and/or indentation. :slight_smile:

What are you trying to achieve by setting “invert: true”? Maybe it would help, if you’d describe what you’re trying to achieve, and not what’s not working for you.

Anyway, it would make sense, if you’d post your complete YAML code from ESPHome, so we get a better feeling, what you’re trying to do. :slight_smile:

esphome:
  name: rodi-x2-sensors
  friendly_name: RoDi X2 Sensors

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "SHHHHHHHHHHHHHPreformatted text"

ota:
  - platform: esphome
    password: "BLABLABLA"

wifi:
  ssid: !secret 2_wifi_ssid
  password: !secret 2_wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Rodi-X2-Sensors Fallback Hotspot"
    password: "d9yOhOhmxDil"

captive_portal:
    
binary_sensor:
  - platform: gpio
    pin: 
      number: GPIO13
      inverted: true
    name: "1/4 Full"
    device_class: moisture
    filters:
      - delayed_on: 10s
      - delayed_off: 10s

  - platform: gpio
    pin: 
      number: GPIO14
      inverted: true
    name: "1/4 Full"
    device_class: moisture
    filters:
      - delayed_on: 10s
      - delayed_off: 10s

if this worked thank you “paddy0174”

so i have a 250 l water barrel that contains RO/Di water and im trying to use 2 XKC-Y25-NPN sensors on 1 ESP32. the end goal is to have 4 esnosrs on 2 ESP32s rather than 4-4.

Thanks for taking the time to format it! :+1:

So, let’s see, where this goes sideways. :smiley: You posted the name of the sensors you’re using, but even after looking these up, I couldn’t find out, if this is what I assume it is: an analogue sensor.

If these sensors in fact are ADC (analogue to digital), you need to use other GPIO pins. ADC is only available on the “standard” ESP boards on GPIO 32 to 39, where you’re using 12 and 13. :slight_smile:

The next thing is, why are you using the platform: gpio? Is there any specific reason? The standard way would be (still assuming your sensor is ADC) to use platform: adc. Please let me know why you chose this platform in the first place, as you said, the sensors are working.

And, as I said above, why do you use invert: true? What’s the reason for that? :slight_smile:

I took the platform i think from ESPHome or ChatGTP. They detect water (even my finger) it gives a output od “dry” or “wet” im guessing because of the moisture class. The boards im using only have 30pins. As for the ADC i jave no idea. So by defult when there is nothing next to the sensor it says “wet” it needs to be “Dry” and vice versa here is a picure of the sensor if i can



can anyone help with this?

So… its working correctly orher than wet/dry being backwards? It switches to Dry when in contact with water?

I would have never guessed!

Without a product link or better pics, its hard to say 100% but, those things are 99% digital sensors not analog.

We all started at the bottom too… If you dont know what those are how they work differently, its important you do. You’ll run into these two a lot. Sometimes analog may be best or your only option and other times you may have a choice to buy sensors in either analog or digital. Very very important to know.

Heres a guide to explain these two things. They have lots of good learning material too. Hint Hint…

ok thank you, ill give that a read. so i have got bot sensors into home assistant via esphome and they work. they change but incredibly fast back and forth, so i have added the “filter” and that is when it seems to go down the toilet. it no longer changes at all

Im not sure what you mean by “bot sensors” but, if its not working and you need help, you gotta give me something to work with. I lost my psychic skills and cant see what you’ve got going on unless you post things like your esphome config.

well its all in the post. that is meant to say “both”. when i apply the “Filter” to stop the sensor changing back and forth from “wet” to “dry” nothing happens at all, no change what so ever. i have been looking online to try and find a answer but have no luck finding anything

i tried to do what you suggested about the “ADC” but i’m getting nowhere


esphome:
  name: rodi-x2-sensors
  friendly_name: RoDi X2 Sensors

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: ""

ota:
  - platform: esphome
    password: ""

wifi:
  ssid: !secret 2_wifi_ssid
  password: !secret 2_wifi_password

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

captive_portal:
    
sensor:
  - platform: adc
    pin: 
      number: GPIO13
      mode: INPUT
      inverted: true
    name: "1/2 Full"
    device_class: moisture

  - platform: adc
    pin: 
      number: GPIO14
      mode: INPUT
      inverted: true
    name: "1/4 Full"
    device_class: moisture

Are you sure they’re even analog? Theyre much more common as digital sensors.

No one can tell which sensors you have. Theres no model #, no product link, data sheet?

They’re digital sensors…

You need binary_sensor not adc

did you figure it out? If you do an online search for that sensor, “XKC-Y25-PNP” I had no problems finding specifications and user manual. It very clearly sais…

Output - On/Off High level is On

If a sensor is On/Off or High/Low this is a Digital Sensor not Analog.

https://www.naukri.com/code360/library/analog-vs-digital-sensors

You need to configure it as a binary_sensor just like I said earlier.

You should end up with something just like this…

binary_sensor:
  - platform: gpio
    pin: 
      number: GPIO13
      mode: INPUT
      inverted: true
    name: "1/2 Full"
    device_class: moisture