ESPhome water valve 15seconds dual relay

Hi, I have a valve: https://www.amazon.de/-/en/Forever-Engine-Shut-off-Three-Way-Diverter/dp/B01AUHNCAC

It moves in 15seconds to left and 15 seconds to right. It’s a 3-way ball valve and I want to use it to send water from 1 source to 2 targets.

I want to use a dual relay board to control the open and close via separate relais. If I would use 1 relais there would always be 230v on 1 of 2 wires and I do not want that.

I would like to have a “switch” in esphome in a way that it is on/off where on is left and off is right.

Below a simple picture of the situation:

Don’t ask but the “yellow/green” really is in use.

I want: to get 1 switch in HA able to control 2 relays in an interlock way… I prefer to do this in esphome and not HA and hide the actual relays (internal: true).

I got this so far:

switch:
  - platform: gpio
    internal: true
    icon: mdi:pipe-valve
    pin: 
      number: GPIO16
      inverted: true
    id: relay1
    interlock: [relay2]
    restore_mode: ALWAYS_OFF

  - platform: gpio
    internal: true
    icon: mdi:pipe-valve
    pin: 
      number: GPIO17
      inverted: true
    id: relay2
    interlock: [relay1]
    restore_mode: ALWAYS_OFF

  - platform: template
    name: "3-way-valve"
    turn_on_action:
      - switch.turn_on: relay2
      - delay: 15s
      - switch.turn_off: relay2
    turn_off_action:
      - switch.turn_on: relay1
      - delay: 15s
      - switch.turn_off: relay1
    restore_mode: DISABLED
    optimistic: True

I works sort of. Restart of the esp keeps both relais off. And switching on the templateswitch in HA turns on relay2 for 15secs and then off.

But if I turn on the templateswitch in HA it autoswitches to off… So I can never switch from “on” to “off”…

EDIT:

optimistic: True

does the trick.

And another question, Is this safe? Is the combi of actions/interlock safe enough?

Thanks!

Why not use one of the relays as the “main” switch and the other as intended.

So from your L to common in the lower relay.
The NO of the lower relay goes to the common in the upper relay.
The NO and NC of the upper goes to the valve.

That way you can switch of the power from one relay and use the other to change direction.

Not sure what you exactly mean.

If I want the valve to turn “left” I need to put 230v om the brown wire for 15s.
If I want the valve to turn “right” I need to put 230V on the yellow wire for 15s.

(blue is always neutral).

I think this way, of using 2 relays is most safe as it only send 230v to one of the wires (left/right).

This is what I could do on my phone

I didn’t have the correct colors, or I don’t know how to do that on the phone.
But green and yellow is what you say is brown and yellow.

So the lower relay will switch on the power to the upper relay.

That way in HA you will have a on/off switch and one that is Left/right.

Switching off the on/off will make sure nothing is sent in any of the two cables.

1 Like

Got you. Could be an option. But then I need to logically bundle both. And that makes logic more complex…

Left: relay2 on + relay1 on
Right: relay2 off + relay1 on

My esphome logic now works perfectly fine… I am happy as such.

Only thing left if to find out how to change the switch class from on/off to left/right

EDIT: some things in HA are so hard…

I tried a lot and this seems to be logic but it does not work:

      - name: "valve position"
        state: >
          {% if states('switch.3_way_valve')|float(0) = on}
            left
          {% else %}
            right
          {% endif %}
      - name: "valve position"
        state: >
          {% if states('switch.3_way_valve') == "on"}
            left
          {% else %}
            right
          {% endif %}

Invalid config for ‘template’ at configuration.yaml, line 99: invalid template (TemplateSyntaxError: unexpected ‘}’) for dictionary value ‘sensor->4->state’, got ‘{% if states('switch.3_way_valve') == “on”}\n left\n{% else %}\n right\n{% endif %}\n’

This works:

      - name: "valve position"
        unique_id: valvepos
        state: >
          {% if is_state('switch.3_way_valve', 'on') %}
            left
          {% else %}
            right
          {% endif %}

There was missing a % from your Template, didn’t see that

Thx, me neither, it’s all so “exact”