ESPhomes Sprinkler Controller component - Sprinkler entities not showing up

I’m trying out the new Sprinkler Controller component and having an issue right off. After writing to the ESP32 board (nodeMCU-32) for testing I’m finding that the entities created under sprinkler: are not being reported (showing up) in either the ESPhome Integration GUI or in HA’s own entities list. Only the GPIO platform switch entity is visible.

Solved: Deleted the new ESPhome device and restarted HA then recreated the ESPhome device with a new name. This time around I get the entities associated with the device appearing.
Additionally a ‘number: component’ is needed for each valve duration control and an overall run time multiplier if you want one.

Still looking for some help with the sprinkler component.
I have a front end GUI number slider working for the watering time multiplier fine, but I’m not sure how to use a similar thing for the individual valve run duration’s. I added a template number for the first valve run duration but it throws compiler errors due to me not really knowing how to load a value via the lambda (or at least that’s where I think I go wrong). If somebody can point out what I should be doing in the last code block to set the valve run duration it would be great…

  name: irrigation-test2

esp32:
  board: nodemcu-32s
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:


ota:
  password: ""

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Irrigation-Test2"
    password: ""

captive_portal:
    
sprinkler:
  - id: lawn_sprinkler_ctrlr
    main_switch: "Lawn Sprinklers"
    auto_advance_switch: "Lawn Sprinklers Auto Advance"
    reverse_switch: "Lawn Sprinklers Reverse"
    valve_overlap: 5s
    valves:
      - valve_switch: "Front Lawn"
        enable_switch: "Enable Front Lawn"
        run_duration: 900s
        valve_switch_id: lawn_sprinkler_valve_sw0
      - valve_switch: "Side Lawn"
        enable_switch: "Enable Side Lawn"
        run_duration: 900s
        valve_switch_id: lawn_sprinkler_valve_sw1
      - valve_switch: "Back Lawn"
        enable_switch: "Enable Back Lawn"
        run_duration: 900s
        valve_switch_id: lawn_sprinkler_valve_sw2

switch:
  - platform: gpio
    id: lawn_sprinkler_valve_sw0
    pin: 0
    internal: true
  - platform: gpio
    id: lawn_sprinkler_valve_sw1
    pin: 2
    internal: true
  - platform: gpio
    id: lawn_sprinkler_valve_sw2
    pin: 4
    internal: true

# Example configuration to set multiplier via number
number:
  - platform: template
    id: sprinkler_ctrlr_multiplier
    name: "Sprinkler Controller Multiplier"
    min_value: 0.1
    max_value: 3.0
    step: 0.1
    lambda: "return id(lawn_sprinkler_ctrlr).multiplier();"
    set_action:
      - sprinkler.set_multiplier:
          id: lawn_sprinkler_ctrlr
          multiplier: !lambda 'return x;'  
          
# Hacking of configuration to set duration via number
  - platform: template
    id: sprinkler_valve_0_duration
    name: "Front Lawn Duration"
    min_value: 1
    max_value: 120
    step: 1.0
    lambda: "return id(sprinkler_valve_0_duration)();"
    set_action:
      - sprinkler.set_valve_run_duration:
          id: lawn_sprinkler_ctrlr
          valve_number: 0
          run_duration: !lambda 'return x;' 

try like this

- platform: template
    id: sprinkler_valve_0_duration
    name: "Front Lawn Duration"
    min_value: 1
    max_value: 120
    step: 1.0
    
    set_action:
      - sprinkler.set_valve_run_duration:
          id: lawn_sprinkler_ctrlr
          valve_number: 0
          run_duration: !lambda 'return x;' 





Here is my code

  - platform: template
    id: valve_sw0
    #name: "Valve sw0 Multiplier"
    min_value: 1
    max_value: 4
    step: 1
    mode: box    
    restore_value: true
    update_interval: 1s
    optimistic: true
    unit_of_measurement: min
    set_action:
      - sprinkler.set_valve_run_duration:
          id: lawn_sprinkler_ctrlr
          valve_number: 0
          run_duration: !lambda 'return x;'
1 Like

I believe what you are looking for is:

"return id(sprinkler_ctrlr).valve_run_duration(0) / 60;"

  - platform: template
    id: sprinkler_valve_0_duration
    name: "Front Lawn Duration"
    min_value: 1
    max_value: 120
    step: 1.0
    lambda: "return id(sprinkler_ctrlr).valve_run_duration(0) / 60;"
    set_action:
      - sprinkler.set_valve_run_duration:
          id: lawn_sprinkler_ctrlr
          valve_number: 0
          run_duration: !lambda "return x * 60;"

Quick edit: I suspect since you have it as 1->120 that you are using minutes. The controller is expecting the value in seconds; you need the run_duration: to be !lambda “return x * 60;” to get the proper result.

1 Like

Thanks guys, both of your code suggestions work and I have grabbed a bit of both. I didn’t understand how the lambda could access the x value without doing something to write it first. Shows that I don’t know much about the way lambdas work inside yaml, it’s all a bit abstract for an old dog like me.

This below is what will do the job. Now too work out a neat way to set the watering days via the frontend GUI and expand to eight valves.

CS80 you are right, I was trying to achieve minute increments not seconds in the run duration.

# Example configuration to set multiplier via number
number:
  - platform: template
    id: sprinkler_ctrlr_multiplier
    name: "Sprinkler Controller Multiplier"
    min_value: 1.0
    max_value: 3.0
    step: 0.1
    mode: box
    lambda: "return id(lawn_sprinkler_ctrlr).multiplier();"
    set_action:
      - sprinkler.set_multiplier:
          id: lawn_sprinkler_ctrlr
          multiplier: !lambda 'return x;'  
          
# Example configuration to set valve run duration via number
  - platform: template
    id: sprinkler_valve_0_duration
    name: "Front Lawn Duration"
    min_value: 1
    max_value: 120
    step: 1.0
    mode: box
    lambda: "return id(lawn_sprinkler_ctrlr).valve_run_duration(0) / 60;"
    set_action:
      - sprinkler.set_valve_run_duration:
          id: lawn_sprinkler_ctrlr
          valve_number: 0
          run_duration: !lambda "return x * 60;"