I’ve searched a bunch on this topic for a couple days now and don’t have a clear idea of how to accomplish a simple float switch using esphome. Does anyone have an example of the YAML code needed?
I’m looking to use one of these float switches to see open/closed of the water level in my hydroponic bucket. If its in the open, I’ll have a pump fill the bucket till its in the closed position.
I’m not sure exactly what you’re after. If you buy the float switch you linked to, you can switch a pump directly, up to .5A. No ESP or HA needed.
But I assume you want to use the float switch as a sensor, not a switch, and let the 8266 or HA then signal to power the pump. That part is just like what I do with some sensors on my heating system. Here’s what I use, after changing the names to match your project:
binary_sensor:
- platform: gpio
id: float_switch
name: Float Switch
pin:
number: GPIO12
mode: INPUT_PULLUP
inverted: true
filters:
# Small filter, to debounce the switch
- delayed_on: 25ms
- delayed_off: 25ms
An automation in HA could then use this as input to turn on and off, say, a smart plug connected to a pump. Maybe you could even do that right in the ESP, but that’s a bit beyond where I’ve gotten with ESPHome so far.
It is exactly what you can do in ESP with binary sensor and binary switch (with relay). I am replacing float switch with pressure sensor, so I can accurately measure how deep my water tank is. And switch on top up when empty (and switch off pump)
Don’t know whether this will serve your purpose. I use this simple system with one float switch for my aquarium filter. There are no relays attached as the switching is completely managed through homeassistant
Thank you so much! I wired one to GPIO12 and the other to GND of my esp8266 and its working perfectly. I have a TPLink smart switch powering my pump. Now i plan to use NodeRed to create an automation to start and stop the pump based on the float state.
Does it require a pull-up resistor? I have tried connecting one pin to 5v of Nodemcu(ESP8266) and one to GPIO12 without any pull-up resistor, but nothing appears in the log.
On the ground side. I’ve actually tested without resistors, since according to the RPi GPIO integration, the default mode is to use the RPi internal pull-up resistor. Seems to work OK that way, too.
Thank you for your help. I am experiencing an issue where the float switch turns on unexpectedly, even when there is no water present, and then quickly turns off again. Currently, I am using two 4.7-ohm resistors, rated at 1/4 watt. Can you tell me what type of resistors you are using?
I used 22 Ohm resistors, 1/4 Watt. Apparently sizing them is more or an art than a science, and I found a range of opinions on line. I’d have to check, but I think I left them off last time I tidied up the connections. It’s in a utility closet and I don’t go in there often.
As to brief false signals, that could be due to long, unshielded wiring. If it’s very brief, you may be able to play with the bouncetime parameter in the rpi_gpio platform configuration.
The Float switch connects to HA - will show any value on the Dashboard i mean - if want to do some automation for pump ON/OFF - need some sort of value
Can we connect [FLOAT Switch] to HA ?
You should go to Google and learn what a pullup/down resistors is for if you have to ask this. These are overwhelmingly used in circuits and it’s critical you understand what they’re for and how to use them. They’re not complicated at all. When you use a pull down, your pulling the signal to ground and your switch or sensor when turned on, it receives a high logic level voltage or 3.3v. When you use a pull UP, your pulling the signal high and your switch or sensor when turned on it goes LOW to ground and has 0v. How your circuit or sensor is wired determines which one you use. Does it send a positive 3.3v when turned on? Then you use a pull down. Does the voltage go to zero when turned on? You need a pull up.