Get run_duration from ESPHome Sprinkler

Hi, I would display the next run_duration from my esp_home sprinkler valve in the Frontend, but can not find any attribute or entity.

Does anybody has an Idea to get this Information?

As in the value you have set ready to go the next time it runs…?

I have these:

image

Which come from code like this in my ESPhome config:

  - platform: template
    id: retic_front_garden_time
    name: Retic Front Garden Time
    min_value: 1
    max_value: 30
    step: 1
    unit_of_measurement: Min
    icon: "mdi:timer-outline"
    mode: box # Defines how the number should be displayed in the UI
    lambda: "return id(retic_controller).valve_run_duration(0);"
    set_action:
      - sprinkler.set_valve_run_duration:
          id: retic_controller
          valve_number: 0
          run_duration: !lambda 'return x;'

I set the run_duration with an automation script, using HASmartIrrigation.

This is working fine. But I can not see in the Frontend, how long the valvue has to run on the next Duration.

So you mean while the duration is counting down?

No i mean, before i start the sprinkler process. I want have to see, how long the sprinkler has to run on the next duration.

Well that is exactly what I posted above… you haven’t shown any of your code so it’s impossible to know why you don’t have entities the same as mine.

You did not read the duration from esphome. You only write you prefered duration by submit a value to set_valve_run_duration action.

But I want only read the next duration. I did not want to set the duration.

Here you can see my script, but I think this can not solve my question :wink:

esphome:
  name: gartenbewaesserung
  friendly_name: Gartenbewässerung

esp8266:
  board: d1_mini

wifi:
  ssid: !secret wifi_ssid_smarthome
  password: !secret wifi_password_smarthome
  # Optional manual IP
  manual_ip:
    static_ip: xxx.xxx.xxx.xxx
    gateway: xxx.xxx.xxx.xxx
    subnet: xxx.xxx.xxx.xxx

api:  
  services:
    - service: set_valve_run_duration 
      variables: 
        duration: int 
        valve: int 
      then: 
        - sprinkler.set_valve_run_duration: 
            id: lawn_sprinkler_ctrlr 
            run_duration: !lambda 'return duration;' 
            valve_number: !lambda 'return valve;'
    - service: start_full_cycle
      then:
        - sprinkler.start_full_cycle: lawn_sprinkler_ctrlr
    - service: start_single_valve
      variables:
        valve: int
      then:
        - sprinkler.start_single_valve:
            id: lawn_sprinkler_ctrlr
            valve_number: !lambda 'return valve;'
    - service: next_valve
      then:
        - sprinkler.next_valve: lawn_sprinkler_ctrlr
    - service: previous_valve
      then:
        - sprinkler.previous_valve: lawn_sprinkler_ctrlr
    - service: shutdown
      then:
        - sprinkler.shutdown: lawn_sprinkler_ctrlr
    - service: pause
      then:
        - sprinkler.pause: lawn_sprinkler_ctrlr
    - service: resume
      then:
        - sprinkler.resume: lawn_sprinkler_ctrlr
    - service: resume_or_full_cycle
      then:
        - sprinkler.resume_or_start_full_cycle: lawn_sprinkler_ctrlr
    - service: repeat_2
      then:
        - sprinkler.set_repeat:
            id: lawn_sprinkler_ctrlr
            repeat: 2  # would run two cycles
    - service: repeat_3
      then:
        - sprinkler.set_repeat:
            id: lawn_sprinkler_ctrlr
            repeat: 3  # would run three cycles

ota:
  - platform: esphome

# define i2c device
# for an ESP8266 SDA is D2 and goes to Arduino's A4
#                SCL is D1 and goes to Arduino's A5
i2c:
  id: i2c_component

logger:
  level: DEBUG

external_components:
  - source: github://glmnet/esphome@ape-external-component
    components: [arduino_port_expander]

arduino_port_expander:
  id: ape
  address: 0x08
  analog_reference: DEFAULT

output:
  - platform: gpio
    pin:
      arduino_port_expander: ape
      number: 9
      mode:
        output: True
    id: relay_1
    inverted: true
  - platform: gpio
    pin:
      arduino_port_expander: ape
      number: 8
      mode:
        output: True
    id: relay_2
    inverted: true
  - platform: gpio
    pin:
      arduino_port_expander: ape
      number: 7
      mode:
        output: True
    id: relay_3
    inverted: true
  - platform: gpio
    pin:
      arduino_port_expander: ape
      number: 6
      mode:
        output: True
    id: relay_4
    inverted: true
  - platform: gpio
    pin:
      arduino_port_expander: ape
      number: 5
      mode:
        output: True
    id: relay_5
    inverted: true
  - platform: gpio
    pin:
      arduino_port_expander: ape
      number: 4
      mode:
        output: True
    id: relay_6
    inverted: true
  - platform: gpio
    pin:
      arduino_port_expander: ape
      number: 3
      mode:
        output: True
    id: relay_7
    inverted: true
  - platform: gpio
    pin:
      arduino_port_expander: ape
      number: 2
      mode:
        output: True
    id: relay_8
    inverted: true

switch:
  - platform: output
    name: Rasen Kinder
    id: relais_rasen_kinder
    output: relay_1
  - platform: output
    name: Relais 2
    id: relais02
    output: relay_2
  - platform: output
    name: Rasen vor Pool
    id: relais_rasen_vor_pool
    output: relay_3
  - platform: output
    name: Beet Gross Terrasse
    id: relais_beet_terrasse_gross
    output: relay_4
  - platform: output
    name: Beet Klein Terrasse
    id: relais_beet_terrasse_klein
    output: relay_5
  - platform: output
    name: Relais 6
    id: relais06
    output: relay_6
  - platform: output
    name: Relais 7
    id: relais07
    output: relay_7
  - platform: output
    name: Relais 8
    id: relais08
    output: relay_8

sprinkler:
  - id: lawn_sprinkler_ctrlr
    main_switch: "Rasensprenger"
    auto_advance_switch: "Rasensprenger Auto Advance"
    reverse_switch: "Rasensprenger Umkehren"
    valve_open_delay: 5s
    valves:
      - valve_switch: "Rasen vor Pool 1"
        enable_switch: "Rasen vor Pool aktivieren"
        run_duration: 1800s
        valve_switch_id: relais_rasen_vor_pool
      - valve_switch: "Rasen Kinder 2"
        enable_switch: "Rasen Kinder aktivieren"
        run_duration: 900s
        valve_switch_id: relais_rasen_kinder
  - id: garden_sprinkler_ctrlr
    main_switch: "Beet Bewässerung"
    auto_advance_switch: "Beet Bewässerung Auto Advance"
    valves:
      - valve_switch: "Beet Terrasse Gross 3"
        run_duration: 9000s
        valve_switch_id: relais_beet_terrasse_gross
      - valve_switch: "Beet Terrasse Gross 4"
        run_duration: 9000s
        valve_switch_id: relais_beet_terrasse_klein

    
sensor:
  - platform: template
    id: lawn_sprinkler_ctrlr_time_remaining_active_valve
    name: "Rasenbewässerung läuft noch"
    accuracy_decimals: 0
    unit_of_measurement: Sek
    lambda: "return round(id(lawn_sprinkler_ctrlr).time_remaining_active_valve().value_or(0));"
  - platform: template
    id: lawn_sprinkler_ctrlr_time_enabled_incomplete_valves
    name: "Rasenbewässerung Laufzeit gesamt"
    accuracy_decimals: 0
    unit_of_measurement: Sek
    lambda: "return round(id(lawn_sprinkler_ctrlr).total_cycle_time_enabled_incomplete_valves());"

  # - platform: arduino_port_expander
  #   id: analog_input_1_humidity
  #   pin: A6
  #   name: Rasen vor Pool (Bodenfeuchtigkeit)
  #   unit_of_measurement: "%"
  #   device_class: humidity
  #   state_class: measurement
  #   accuracy_decimals: 0
  #   #update_interval: 10s
  #   update_interval: never
  #   filters:
  #     - multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
  #     - calibrate_linear:
  #         - 0.95 -> 100
  #         - 2.5 -> 0
  #     - lambda: |
  #         if (x < 0) return 0; 
  #         else if (x > 100) return 100;
  #         else return (x);
  - platform: arduino_port_expander
    id: analog_input_1_voltage
    pin: A6
    name: Rasen vor Pool (Spannung)
    update_interval: never
    filters:
      - multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
  - platform: copy
    source_id: analog_input_1_voltage
    id: analog_input_1_humidity
    name: Rasen vor Pool (Bodenfeuchtigkeit)
    unit_of_measurement: "%"
    device_class: humidity
    state_class: measurement
    accuracy_decimals: 0
    filters:
      - calibrate_linear:
          - 0.95 -> 100
          - 2.5 -> 0
      - lambda: |
          if (x < 0) return 0; 
          else if (x > 100) return 100;
          else return (x);

# https://community.home-assistant.io/t/soil-moisture-sensor-output-as-a-percentage/250885/5 
  - platform: copy
    source_id: analog_input_1_voltage
    id: analog_input_1_humidity_test
    name: Rasen vor Pool Test 2 (Bodenfeuchtigkeit)
    unit_of_measurement: "%"
    device_class: humidity
    state_class: measurement
    accuracy_decimals: 0
    filters:
      - median:
          window_size: 7
          send_every: 4
          send_first_at: 1
      - calibrate_linear:
          - 0.95 -> 100
          - 2.5 -> 0
      - lambda: |
          if (x < 0) return 0; 
          else if (x > 100) return 100;
          else return (x);


  # - platform: arduino_port_expander
  #   id: analog_input_2_humidity
  #   pin: A7
  #   name: Rasen Kinder (Bodenfeuchtigkeit)
  #   unit_of_measurement: "%"
  #   device_class: humidity
  #   state_class: measurement
  #   accuracy_decimals: 0
  #   #update_interval: 10s
  #   update_interval: never
  #   filters:
  #     - multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
  #     - calibrate_linear:
  #         - 0.95 -> 100
  #         - 2.5 -> 0
  #     - lambda: |
  #         if (x < 0) return 0; 
  #         else if (x > 100) return 100;
  #         else return (x);
  - platform: arduino_port_expander
    id: analog_input_2_voltage
    pin: A7
    name: Rasen Kinder (Spannung)
    #update_interval: 10s
    update_interval: never
    filters:
      - multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
  - platform: copy
    source_id: analog_input_2_voltage
    id: analog_input_2_humidity
    name: Rasen Kinder (Bodenfeuchtigkeit)
    unit_of_measurement: "%"
    device_class: humidity
    state_class: measurement
    accuracy_decimals: 0
    filters:
      - calibrate_linear:
          - 0.95 -> 100
          - 2.5 -> 0
      - lambda: |
          if (x < 0) return 0; 
          else if (x > 100) return 100;
          else return (x);


  # - platform: arduino_port_expander
  #   id: analog_input_3_humidity
  #   pin: A0
  #   name: Eingang 3 Bodenfeuchtigkeit
  #   unit_of_measurement: "%"
  #   device_class: humidity
  #   state_class: measurement
  #   accuracy_decimals: 0
  #   #update_interval: 10s
  #   update_interval: never
  #   filters:
  #     - multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
  #     - calibrate_linear:
  #         - 0.95 -> 100
  #         - 2.5 -> 0
  #     - lambda: |
  #         if (x < 0) return 0; 
  #         else if (x > 100) return 100;
  #         else return (x);
  - platform: arduino_port_expander
    id: analog_input_3_voltage
    pin: A0
    name: Eingang 3 Spannung
    #update_interval: 10s
    update_interval: never
    filters:
      - multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
  - platform: copy
    source_id: analog_input_3_voltage
    id: analog_input_3_humidity
    name: Eingang 3 Bodenfeuchtigkeit
    unit_of_measurement: "%"
    device_class: humidity
    state_class: measurement
    accuracy_decimals: 0
    filters:
      - calibrate_linear:
          - 0.95 -> 100
          - 2.5 -> 0
      - lambda: |
          if (x < 0) return 0; 
          else if (x > 100) return 100;
          else return (x);


  # - platform: arduino_port_expander
  #   id: analog_input_4_humidity
  #   pin: A1
  #   name: Eingang 4 Bodenfeuchtigkeit
  #   unit_of_measurement: "%"
  #   device_class: humidity
  #   state_class: measurement
  #   accuracy_decimals: 0
  #   #update_interval: 10s
  #   update_interval: never
  #   filters:
  #     - multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
  #     - calibrate_linear:
  #         - 0.95 -> 100
  #         - 2.5 -> 0
  #     - lambda: |
  #         if (x < 0) return 0; 
  #         else if (x > 100) return 100;
  #         else return (x);
  - platform: arduino_port_expander
    id: analog_input_4_voltage
    pin: A1
    name: Eingang 4 Spannung
    #update_interval: 10s
    update_interval: never
    filters:
      - multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
  - platform: copy
    source_id: analog_input_4_voltage
    id: analog_input_4_humidity
    name: Eingang 4 Bodenfeuchtigkeit
    unit_of_measurement: "%"
    device_class: humidity
    state_class: measurement
    accuracy_decimals: 0
    filters:
      - calibrate_linear:
          - 0.95 -> 100
          - 2.5 -> 0
      - lambda: |
          if (x < 0) return 0; 
          else if (x > 100) return 100;
          else return (x);


  # - platform: arduino_port_expander
  #   id: analog_input_5_humidity
  #   pin: A2
  #   name: Eingang 5 Bodenfeuchtigkeit
  #   unit_of_measurement: "%"
  #   device_class: humidity
  #   state_class: measurement
  #   accuracy_decimals: 0
  #   #update_interval: 10s
  #   update_interval: never
  #   filters:
  #     - multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
  #     - calibrate_linear:
  #         - 0.95 -> 100
  #         - 2.5 -> 0
  #     - lambda: |
  #         if (x < 0) return 0; 
  #         else if (x > 100) return 100;
  #         else return (x);
  - platform: arduino_port_expander
    id: analog_input_5_voltage
    pin: A2
    name: Eingang 5 Spannung
    #update_interval: 10s
    update_interval: never
    filters:
      - multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
  - platform: copy
    source_id: analog_input_5_voltage
    id: analog_input_5_humidity
    name: Eingang 5 Bodenfeuchtigkeit
    unit_of_measurement: "%"
    device_class: humidity
    state_class: measurement
    accuracy_decimals: 0
    filters:
      - calibrate_linear:
          - 0.95 -> 100
          - 2.5 -> 0
      - lambda: |
          if (x < 0) return 0; 
          else if (x > 100) return 100;
          else return (x);


  # - platform: arduino_port_expander
  #   id: analog_input_6_humidity
  #   pin: A3
  #   name: Eingang 6 Bodenfeuchtigkeit
  #   unit_of_measurement: "%"
  #   device_class: humidity
  #   state_class: measurement
  #   accuracy_decimals: 0
  #   #update_interval: 10s
  #   update_interval: never
  #   filters:
  #     - multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
  #     - calibrate_linear:
  #         - 0.95 -> 100
  #         - 2.5 -> 0
  #     - lambda: |
  #         if (x < 0) return 0; 
  #         else if (x > 100) return 100;
  #         else return (x);
  - platform: arduino_port_expander
    id: analog_input_6_voltage
    pin: A3
    name: Eingang 6 Spannung
    #update_interval: 10s
    update_interval: never
    filters:
      - multiply: 0.004887585532746823069403714565 # x * 1023.0 / 5.0 v
  - platform: copy
    source_id: analog_input_6_voltage
    id: analog_input_6_humidity
    name: Eingang 6 Bodenfeuchtigkeit
    unit_of_measurement: "%"
    device_class: humidity
    state_class: measurement
    accuracy_decimals: 0
    filters:
      - calibrate_linear:
          - 0.95 -> 100
          - 2.5 -> 0
      - lambda: |
          if (x < 0) return 0; 
          else if (x > 100) return 100;
          else return (x);

interval:
  - interval: 60s
    then:
      # - component.update: analog_input_3_humidity
      # - delay: 1s
      - component.update: analog_input_3_voltage
      - delay: 5s
      # - component.update: analog_input_4_humidity
      # - delay: 1s
      - component.update: analog_input_4_voltage
      - delay: 5s
      # - component.update: analog_input_5_humidity
      # - delay: 1s
      - component.update: analog_input_5_voltage
      - delay: 5s
      # - component.update: analog_input_6_humidity
      # - delay: 1s
      - component.update: analog_input_6_voltage
      - delay: 5s
      # - component.update: analog_input_1_humidity
      # - delay: 1s
      - component.update: analog_input_1_voltage
      - delay: 5s
      # - component.update: analog_input_2_humidity
      # - delay: 1s
      - component.update: analog_input_2_voltage

Sure, but whatever I set it to, will be the next duration.

You could always create template sensors in ESPhome to calculate the time based on your station time and multiplier, then get HA to read that.