Components ➔ Sprinkler Controller - Can I start a selected sprinkler with a selected duration?

I can select the valve and start it. A button (tap action) calls a script that calls the esphome service defined in the api configuration. I can select the valve number or I can select a duration, but I can’t do both.

Any tips here would be appreciated.

Here is the esphome api:

api:
  services:
    - service: start_single_valve
      variables:
        valve: int
      then:
        - sprinkler.start_single_valve:
            id: lawn_sprinkler_ctrlr
            valve_number: !lambda 'return valve - 1;'

    - service: start_valve_with_duration
      variables:
        duration: int
      then:
        - sprinkler.start_single_valve:
            id: lawn_sprinkler_ctrlr
            valve_number: 0
            run_duration: !lambda 'return duration;'

Here are my Lovelace cards:

type: vertical-stack
cards:
  - type: entities
    entities:
      - entity: input_number.sprinkler_valve_number
      - entity: input_number.sprinkler_zone1_run_duration
    title: Valve Number
  - type: button
    show_name: true
    show_icon: true
    tap_action:
      action: call-service
      service: script.start_sprinkler_valve
    name: Start selected valve
  - type: button
    show_name: true
    show_icon: true
    tap_action:
      action: call-service
      service: script.start_sprinkler_valve_with_duration
    name: Start Valve 1 for selected seconds

Here is the script that calls the esphome service to run a selected valve number:

alias: Start Sprinkler Valve
sequence:
  - service: esphome.sprinkler_controller_1_start_single_valve
    data:
      valve: "{{ states('input_number.sprinkler_valve_number') | int }}"
mode: single
icon: mdi:sprinkler

And finally the script that calls the esphome service to set the duration for a hard-coded valve number:

alias: Start Sprinkler Valve with Duration
sequence:
  - service: esphome.sprinkler_controller_1_start_valve_with_duration
    data:
      duration: "{{ states('input_number.sprinkler_zone1_run_duration') | int }}"
mode: single

As I said, either function works alone, but I can’t find a way to combine them.

Can You publish combined service, which not working ?
Checked sprinkler component code - start_single_valve have valve_number & duration as parameters. See nothing can prevent using such a code:

api:
  services:
    - service: start_valve
      variables:
        valve: int
        duration: int
      then:
        - sprinkler.start_single_valve:
            id: lawn_sprinkler_ctrlr
            valve_number: !lambda 'return valve - 1;'
            run_duration: !lambda 'return duration;'

And call it by providing both parameters in data.

Actually, your questions led me to find my error. I was calling the wrong ESPHome API.

I was chasing the wrong cause of the error:

Failed to call service script/start_selected_sprinkler_valve_with_duration. extra keys not allowed @ data['valve']

… thinking that something was wrong with my script that calls the ESPHome API.

To close this out, here is the working stuff:

The name of the ESPHome device is:

sprinkler_controller_1

Button card:

  - type: button
    show_name: true
    show_icon: true
    tap_action:
      action: call-service
      service: script.start_sprinkler_test
    name: Sprinkler Test

The button calls this Home Assistant script:

alias: Start Sprinkler test
sequence:
  - service: >-
      esphome.sprinkler_controller_1_start_selected_sprinkler_valve_with_duration
    data:
      valve: "{{ states('input_number.sprinkler_valve_number') | int }}"
      duration: "{{ states('input_number.sprinkler_zone1_run_duration') | int }}"
mode: single

Finally, the ESPHome API called by the Home Assistant script:

api:
  services:
    - service: start_selected_sprinkler_valve_with_duration
      variables:
        valve: int
        duration: int
      then:
        - sprinkler.start_single_valve:
            id: lawn_sprinkler_ctrlr
            valve_number: !lambda 'return valve - 1;'
            run_duration: !lambda 'return duration;'

It is amazing what a couple of hours of sleep can do to the diagnostic process.