Valve template with two sensors

Hey there.

I am working first time with ESP32 in HA. I have problem which I am not able to solve.

I have following application. I have valve with two coils ( open / close ) and two sensors ( opened / closed ). I used template for valve, but in template is expecting only one sensor for monitoring of position. If sensor has value 1 then it’s open and if value is zero then is expected that is closed. In my case zero value for sensor don’t mean that valve is closed because it can be in middle position. can somebody help me hot to modify valve template for two sensors evaluation? I tried to add some code in lambda, but template is not changed.

Thx.

valve:
  - platform: template
    name: "Zaluzie"
    lambda: |-
      if (id(sensor_open).state && !id(sensor_close).state) {
        return VALVE_OPEN;
      } else if (!id(sensor_open).state && id(sensor_close).state) {
        return VALVE_CLOSED;
      }

    open_action:
      - switch.turn_on: open_relay
      - switch.turn_off: close_relay
    close_action:
      - switch.turn_on: close_relay
      - switch.turn_off: open_relay
    stop_action:
      - switch.turn_off: open_relay
      - switch.turn_off: close_relay
    assumed_state: true

How are you using this valve? I has 3 states. If you need all 3 states, I expect you need to have 2 valve components.

in reality it is small DC motor, which rotate shaft and opening or closing water valve It is continuous regulation. These two coils are two relays for changing of polarity on the DC motor

if it’s continous regulation, how you get feedback?

I have DC motor connected with clutch to the valve. ( I am sorry, I don’t have picture ). On the wheel connected on the shaft I have two sensors. If you are rotating to the right you are closing valve and when it’s closed then one of sensor is on. If you are rotating to the left, then valse is opening and when is completely open second sensor is on. I will try to draw some picture.

Yep I got it, but you wrote that is in continuous regulation, so I expect that you drive it partially open to regulate…?

I made picture

I can stop the motor in any position between open and close state

Yep but how you get feedback of your position when it’s somewhere between endstops?

For example you want it 70% open

between is no feedback. I am counting time, because speed is known and also position of sensors is known.

Only problem is that, if go out from open sensor, then in valve template I have immediately information “CLOSED”

try time_based cover or endstop cover

basically you have linear actuator without encoder…

you mean this? https://esphome.io/components/cover/endstop

Yep, I have never used, but more close to your setup than solenoid valve…

I made quick a look, and seems to be solution.

On the picture I see that two sensors can be configured.
Now I must play with my son, but when I do that, I’ll let you know.

For now, thank you very much

or maybe Feedback Cover is better

Have a nice play!

I made feedback cover. It’s working exactly according to my expectations. Thank you very much for your help.

You’re welcome. Next time you ask help, describe your actual hardware