Defining a switch with input pin?

Not sure how to approach this - I am sure it is easy for most.
I have defined a switch to control a pump (pin5). I need to read input on a pin (pin4) to get a value and determine if and how long I turn my pump on.
Question - can you define an input pin on a switch or do you define a sensor and a switch on the same node using different pins? Or is this done a different way?

Well say you were measuring soil moisture from a sensor and wanted to water a plant if it needed it.

A typical approach would be to have a moisture level sensor on one pin, and put a “on_value_range” automation attached to that sensor which turns on the pump/switch if required (and probably also subject to a few conditions). The pump is on another pin.

There’s lots of examples of this and similar around.

yea that is pretty much what i am wanting to do. ph control but same concept. so use sensor rather than switch?

ok i found some useful information.
thanks

One thing about the esphome docs, the link to this page is almost hidden at the top of the main page. It is not as “sexy” as the links to the components and doesn’t have a fancy schmancy icon. I think that people miss it, but it is one of the more important pages full of key concepts. Automations and Templates — ESPHome

yes! that is where i found my info.