ESPHOME sprinkler component does not work with the valve component?

Hello everyone,

I have 10 motor ball valves that I want to use for my irrigation system. Those valves are “dumb” ones. They do not stop or close automatically. They open and close by reversing the voltage on the two motor connections. The valves also have one end switch each for the open and close position that needs to processed. I designed my own PCB with a MCP23017 I2C GPIO expander and 4 x DRV8870 (H-bridges), so I can control 4 valves with one MCP23017. To control the opening and closing of the valves, I used the valve-component of ESP Home as this seemed reasonable. This way, I was also able to implement the rapid braking of the motor of the valve as soon as the open- or close-end switch triggered.

Valve configuration
valve:
  - platform: template
    id: motor_valve_1
    name: "Motorventil 1"
    optimistic: false

    lambda: |-
      if (id(valve_1_opened_input).state && !id(valve_1_closed_input).state) {
        //ESP_LOGD("Lambda", "Valve seem to be open");
        return VALVE_OPEN;
      } else if (!id(valve_1_opened_input).state && id(valve_1_closed_input).state) {
        //ESP_LOGD("Lambda", "Valve seem to be closed");
        return VALVE_CLOSED;
      } else {
        return {};
      }

    open_action:
      then:
        - logger.log: "Opening Valve 1, enabling opening-output..."
        - switch.turn_off: valve_1_close_output
        - switch.turn_on: valve_1_open_output
        - logger.log: "Valve 1 opening-output enabled!"

    close_action:
      then:
        - logger.log: "Closing Valve 1, enabling closing-output..."
        - switch.turn_off: valve_1_open_output
        - switch.turn_on: valve_1_close_output
        - logger.log: "Valve 1 closing-output enabled!"

    stop_action:
      then:
        - if:
            condition:
              xor:  # XOR to prevent call of this stopping action in case braking is already active
                - switch.is_on: valve_1_open_output
                - switch.is_on: valve_1_close_output
            then:
              - logger.log: "Stopping Valve 1, enable braking..." # Will result in a HIGH on both H-bridge control signals and therefore braking
              - switch.turn_on: valve_1_open_output
              - switch.turn_on: valve_1_close_output
              - logger.log: "Valve 1 braking, wait 250 ms..."
              - delay: 250 ms
              - logger.log: "Valve 1 braked, waited 250 ms, disable outputs"
              - switch.turn_off: valve_1_open_output
              - switch.turn_off: valve_1_close_output
              - logger.log: "Valve 1 outputs disabled!"

    on_open:
      # only do this when the opening action is active
      then:
        - if:
            condition:
              and:  # AND to prevent call of this stopping action in case braking is already active (= both outputs are enabled in that case)
                - switch.is_on: valve_1_open_output
                - switch.is_off: valve_1_close_output
            then:
              - logger.log: "Valve 1 fully open, turn it off"
              - valve.stop: motor_valve_1

    on_closed:
      # only do this when the closing action is active
      then:
        - if:
            condition:
                and:  # AND to prevent call of this stopping action in case braking is already active (= both outputs are enabled in that case)
                  - switch.is_on: valve_1_close_output
                  - switch.is_off: valve_1_open_output
            then:
              - logger.log: "Valve 1 fully closed, turn it off"
              - valve.stop: motor_valve_1

Now I would like to use the awesome sprinkler component, but it seems that it can only be used with the switch component. When I use the ID of my valve (e.g. motor_valve_1), I get this error:

ID ‘motor_valve_1’ of type template_::TemplateValve doesn’t inherit from switch_::Switch. Please double check your ID is pointing to the correct value.

I looked into the switch platform: hbridge but it seems to be not what I need or at least need some significant tinkering to get the same functionality as when using the valve-component.

So my question is what is the best way to get this working? Can the sprinkler-component be modified so that it also works with valves? Or can my valves be “linked” to a theoretical switch component that can be used?

Time based h-bridge switch would be easiest way if your valves don’t mind to be powered short while beyond actual course.

No, time based control is not an option. Those valves do not have any physical end point, so they can turn the actual ball valve infinite. When opening or closing for a fixed time, nobody knows what the exact state of the valve is.

Then I think you need to bake the valves as template switch.