MQTT based sprinkler control

It uses seven input_boolean entities, one for each day of the week. You have to create them.

You can create an input_boolean via the UI using the menu (Configuration > Helpers) or by defining them in the configuration.yaml file.

For more information: Input Boolean

THANK YOU!!! you saved my day!

Thanks @123 to clarify
it is exactly what i should have write at startā€¦ :slight_smile:

@johnsnow0 you will need also 1 input_datetime and 1 input_number according to your errors

Hello,
please help once again. Home assistant show no errors, automation starting at given time, but ā€œtime remainingā€ always become ā€œunavailableā€ then spinkler is ON and it cause that sprinkler wonā€™t stop :frowning:

Configuration.yaml

sensor:
- platform: template
    sensors:
        zone_1_time_remaining:
          friendly_name: 'Time remaining'
          #Check if the zone switch is on or off before providing the number
          value_template: >
            {% if is_state("switch.laistymo_sistema", "off") %} 0
            {% else %}
            {% set countdown_timer = [ (states('input_number.zone_1_run_time') | int - (as_timestamp(now()) - as_timestamp(states.switch.laistymo_sistema_zone_1.last_changed)) / 60) | round(0) ,0 ] | max %} {{ countdown_timer }}
            {% endif %}
          unit_of_measurement: "sec"

binary_sensor:
- platform: template
      sensors:
        zone_1_day_active:
          friendly_name: Irrigation Day Active
          unique_id: IDA1
          value_template: >-
            {{ (is_state('automation.irrigation_zone_1_am_2', 'on')
            or is_state('automation.irrigation_zone_1_pm_2', 'on'))
            and (( is_state('input_boolean.zone_1_mon', 'on') and now().weekday() == 0 )
            or ( is_state('input_boolean.zone_1_tue', 'on') and now().weekday() == 1 )
            or ( is_state('input_boolean.zone_1_wed', 'on') and now().weekday() == 2 )
            or ( is_state('input_boolean.zone_1_thu', 'on') and now().weekday() == 3 )
            or ( is_state('input_boolean.zone_1_fri', 'on') and now().weekday() == 4 )
            or ( is_state('input_boolean.zone_1_sat', 'on') and now().weekday() == 5 )
            or ( is_state('input_boolean.zone_1_sun', 'on') and now().weekday() == 6 )) }}

remove what i put , since i need to read betterā€¦ :slight_smile:

Not sure, i understood you wellā€¦

Hi tom_I. What do I need to do if I want to change the uptime from minutes to seconds. Thank you very much!

Uptime?

Did you mean run time?

If so, remove the / 60 from the time remaining template sensors and increase the size of the input booleans.

Thanks. Yes, it mean runtime. I removed the / 60 from the time remaining template sensors. But I do not understand how to increase the size of the input booleans? My need is that the pump works for less than 60s. Can you guide me in more detail?

Sorry, meant input numbers.

Hi you. I fixed it, however time remaining doesnā€™t decrease by seconds. It drops to zero after running time. Help me fix this!

input
zone_1_run_time:
    name: Run Time
    min: 1
    max: 120
    step: 1
    unit_of_measurement: "sec"
    icon: mdi:clock

- platform: template
  sensors:
    zone_1_time_remaining:
      friendly_name: "Time Remaining"
      entity_id:
        - input_number.zone_1_time_remaining
        - sensor.time
        - switch.zone_1
      value_template: >
        {% if is_state('switch.zone_1', 'on') %}
          {{ [ (states('input_number.zone_1_run_time')|int - (as_timestamp(now()) - as_timestamp(states.switch.zone_1.last_changed)))|round(0) ,0 ] | max }}
        {% else %}
          0
        {% endif %}
      unit_of_measurement: "sec"

Are you willing to share the lovelace cards? The day toggles look nice.

They are custom button cards.

Card config:

card_mod:
  class: top-level-card
entities:
  - entity: switch.zone_2
    name: Sprinkler Valve
    type: custom:multiple-entity-row
    toggle: true
    state_color: true
    entities:
      - entity: binary_sensor.zone_2_day_active
        name: Day Active
      - entity: sensor.zone_2_time_remaining
        name: Remaining
  - entity: automation.irrigation_zone_2_am
    name: Enable AM Schedule
    type: custom:multiple-entity-row
    toggle: true
    state_color: true
    entities:
      - entity: input_datetime.zone_2_am_on_time
      - entity: input_number.zone_2_run_time
  - entity: automation.irrigation_zone_2_pm
    name: Enable PM Schedule
    type: custom:multiple-entity-row
    toggle: true
    state_color: true
    entities:
      - entity: input_datetime.zone_2_pm_on_time
      - entity: input_number.zone_2_run_time
  - card_type: horizontal-stack
    cards:
      - entity: input_boolean.zone_2_mon
        name: Mon
        template: day_button
        type: custom:button-card
      - entity: input_boolean.zone_2_tue
        name: Tue
        template: day_button
        type: custom:button-card
      - entity: input_boolean.zone_2_wed
        name: Wed
        template: day_button
        type: custom:button-card
      - entity: input_boolean.zone_2_thu
        name: Thu
        template: day_button
        type: custom:button-card
      - entity: input_boolean.zone_2_fri
        name: Fri
        template: day_button
        type: custom:button-card
      - entity: input_boolean.zone_2_sat
        name: Sat
        template: day_button
        type: custom:button-card
      - entity: input_boolean.zone_2_sun
        name: Sun
        template: day_button
        type: custom:button-card
    type: custom:hui-element
show_header_toggle: false
title: West Lawn
type: entities

Button card template:

button_card_templates:
  day_button:
    color_type: icon
    hold_action:
      action: none
    show_label: false
    show_name: true
    show_state: false
    state:
      - icon: mdi:checkbox-marked-circle
        styles:
          card:
            - border: solid 1px var(--paper-item-icon-active-color)
            - box-shadow: 0px 0px 10px 3px var(--paper-item-icon-active-color)
          name:
            - color: var(--primary-text-color)
        value: 'on'
      - icon: mdi:cancel
        styles: null
        value: 'off'
    styles:
      card:
        - border-radius: 10px
        - border: solid 1px var(--primary-color)
        - box-shadow: none
        - padding: 6px 0px
        - margin: 0px 0px
        - '--ha-card-background': rgba(0, 0, 0, 0)
      grid:
        - grid-template-areas: '"i" "n"'
        - grid-template-rows: 33% auto
        - grid-template-columns: auto
      icon:
        - width: 28px
      name:
        - justify-self: middle
        - align-self: end
        - font-size: 14px
        - padding: 0px 0px
        - color: var(--secondary-text-color)
    tap_action:
      action: toggle

Thanks a lot!

ESPHome now has a specific sprinkler controller component that makes most of the programming very simple (after i spent a week writing esphome code to do the same). I just converted over to that integration and it is working great. Hereā€™s a shot of what iā€™ve come up with for my dashboard:

I chose to use a lot of ā€œfold-entity-rowsā€ to make it nice and compact on mobile.

2 Likes

I have switch to Tasmota now and itā€™s been rock solidā€¦

Hi @tom_l , your config and lovelace ui is perfect. Im banging my head for one week now until i stumble upon this thread, i was trying to do all the automations from espHome directly to work without homeassitant (in case the server is down) but i gave up.

Can you please share all the files for your irrigation system, i see on page 8 separate sections for automations binary sensors etcā€¦ are they all in homeassistant as separate .yaml files or are they programed in espHome device?

I want to be able to add hours to wait, let say 48hours and run for x minutes.

Any help is much appriciated

Thanks in advance

Edit: I figured out how to implement the code.

Can anyone please help on how can i add 48h timer to this configuration that is on page 8.

Not using MQTT but esphome sprinkler controlerā€¦
as itā€™s garden bed Iā€™m not using days settingsā€¦ they need to water every day
Iā€™ll add the moisture sensors later this week.

I love how clean that is