How To Install OpenSprinkler in Home Assistant

by Danny
0 comment

In this tutorial, I am going to show you how to integrate your OpenSprinker smart sprinkler system into Home Assistant. By the end of this guide, you will be able to turn on individual stations, run your “Run Once” programs, check last run time, and much more – all from your Lovelace dashboard.

For reference, I am using the preassembled OpenSprinkler unit. My Home Assistant instance is configured on a raspberry pi 3B+.

This guide assumes that you already have OpenSprinkler installed and working. If you don’t, I recently wrote a an OpenSprinkler installation guide you can reference.

Let’s get started!


Step 1: Install HACS

HACS is the Home Assistant Community Store. Once installed, it lets you install custom Github projects with the click of a button, rather than manually editing custom_components.yaml file and importing files. I had some trouble installing HACS, so I apologize that I can’t give you a step-by-step guide here, but a lot of the installation was trial and error until I got it working correctly. Here’s a guide you can reference: https://hacs.xyz/docs/installation/installation/

If you go the HACS route, just make sure to generate a Github personal token and add it to your configuration.yaml file like this:

hacs:
token: 123123123123123123123123


A few tips I remember needing to do are:

  • When it says reboot Home Assistant, I had to reboot my raspberry pi, not just the Home Assistant UI.
  • Clear your browser cache after installing and rebooting.
  • Go To Configuration > Integrations > install HACS.

After installing from bullet #3, it said HACS was already installed, but at that point it finally showed up in my sidebar, so I’m not sure if it was even necessary to do that step.

You don’t necessary HAVE to have HACS installed. You can import the OpenSprinkler files manually as well. Since I wanted to start using HACS anyway, I decided to bite the bullet and use this project as a starting point.


Step 2: Add the OpenSprinkler Integration

Once HACS is installed or you’ve manually copied the files in, add the OpenSprinkler integration by following these steps.

Note: If you JUST installed HACS, it may take a bit for all the github repositories to show up. This is because Github limits the amount of API calls within a certain time. Check back in an hour or so and it should show up.

Part 1: Install OpenSprinkler via HACS

Navigate to HACS > Explore & Add Repositories. Search for the OpenSprinkler integration for Home Assistant.

Then, click Install this repository in Hacs. Keep the “Show beta versions” turned off.

Once complete, you will need to restart Home Assistant from Supervisor > System > Reboot Host.


Part 2: Add OpenSprinkler Integration

Navigate to Configuration > Integrations > Add Integration. Search for OpenSprinkler.

Next, add your OpenSprinkler IP address, login password, and controller name. MAC address can be left blank.

Then, click Submit. Assign it to an area like your garage and click Finish.


Step 2: Check Entity Names

After installing, you’ll see a ton of different entities created. You’ll need to know what these are called for later, so head over to Configuration > Entities > search for “Open” to ensure they show up. I recommend copying the binary sensors and names down somewhere for quick reference.

For this example, I am going to create 2 lovelace dashboard cards: One to manually trigger each zone, and one to run my “Run Once” program (which was already configured in OpenSprinkler to run each zone for 7 minutes on specific days. ) The Run Once program is just a schedule to run each zone at a specific time for a certain number of minutes.

To find your zone sensor names, search for binary_sensor.zone.

To find your Run Once program name, search for for your Run Once by program name. Mine is called 3-Day Morning.


Step 3: Configure Lovelace Sprinkler Switches

Single Switch

To configure a switch for a single zone, go to File Editor > Configuration.yaml and add the code below. You will need to replaced the 3 bolded binary sensors with your own entity ID’s from step 3.

This switch below run Zone 1 for 1 minute.

switch:
  - platform: template
    switches:
      zone_one:
        value_template: "{{ is_state('binary_sensor.zone1_front_fence_station_running', 'on') }}"
        turn_on:
          service: opensprinkler.run
          data_template:
            entity_id: binary_sensor.zone3_front_fence_station_running
            # Run seconds uses the input_number below.
            run_seconds: "{{ ((states('input_number.station_minutes') | float) * 60) | int }}"
        turn_off:
          service: opensprinkler.stop
          data:
            entity_id: binary_sensor.zone3_front_fence_station_running
input_number:
  station_minutes:
    initial: 1
    min: 1
    max: 10
    step: 1

Save your configuration and then reboot again.

On your Lovelace dashboard, you can now add a new Entities Card. Search for switch.zone_two. Here’s what it looks like:

Multiple Switches

If you have multiple zones like I do (I have 6), then you’ll probably want to configure multiple switches.

To configure a switch to individually turn on all six of stations, go to File Editor > Configuration.yaml and add the code below. You will notice that I manually changed the switch names (zone_one, zone_two, zone_three, etc). Also, all 6 of these switches, when toggled, will run for the same amount of time (in this example, it’s 1 minute)

For example, I clicked Zone 2 first, then 4, then 5. In Open Sprinkler, it has those scheduled but since they are not currently running, it’s not toggled in Home Assistant.

Here’s the code. Just remember to replace the entity ID’s and set the minimum length of time you want to run for.

switch:
  - platform: template
    switches:
      zone_one:
        value_template: "{{ is_state('binary_sensor.zone1_front_yard_station_running', 'on') }}"
        turn_on:
          service: opensprinkler.run
          data_template:
            entity_id: binary_sensor.zone1_front_yard_station_running
            # Run seconds uses the input_number below.
            run_seconds: "{{ ((states('input_number.station_minutes') | float) * 60) | int }}"
        turn_off:
          service: opensprinkler.stop
          data:
            entity_id: binary_sensor.zone1_front_yard_station_running
      zone_two:
        value_template: "{{ is_state('binary_sensor.zone2_front_yard_sidewalk_station_running', 'on') }}"
        turn_on:
          service: opensprinkler.run
          data_template:
            entity_id: binary_sensor.zone2_front_yard_sidewalk_station_running
            # Run seconds uses the input_number below.
            run_seconds: "{{ ((states('input_number.station_minutes') | float) * 60) | int }}"
        turn_off:
          service: opensprinkler.stop
          data:
            entity_id: binary_sensor.zone2_front_yard_sidewalk_station_running
      zone_three:
        value_template: "{{ is_state('binary_sensor.zone3_front_fence_station_running', 'on') }}"
        turn_on:
          service: opensprinkler.run
          data_template:
            entity_id: binary_sensor.zone3_front_fence_station_running
            # Run seconds uses the input_number below.
            run_seconds: "{{ ((states('input_number.station_minutes') | float) * 60) | int }}"
        turn_off:
          service: opensprinkler.stop
          data:
            entity_id: binary_sensor.zone3_front_fence_station_running
      zone_four:
        value_template: "{{ is_state('binary_sensor.zone_4_backyard_station_running', 'on') }}"
        turn_on:
          service: opensprinkler.run
          data_template:
            entity_id: binary_sensor.zone_4_backyard_station_running
            # Run seconds uses the input_number below.
            run_seconds: "{{ ((states('input_number.station_minutes') | float) * 60) | int }}"
        turn_off:
          service: opensprinkler.stop
          data:
            entity_id: binary_sensor.zone_4_backyard_station_running
      zone_five:
        value_template: "{{ is_state('binary_sensor.zone5_backyard_side_station_running', 'on') }}"
        turn_on:
          service: opensprinkler.run
          data_template:
            entity_id: binary_sensor.zone5_backyard_side_station_running
            # Run seconds uses the input_number below.
            run_seconds: "{{ ((states('input_number.station_minutes') | float) * 60) | int }}"
        turn_off:
          service: opensprinkler.stop
          data:
            entity_id: binary_sensor.zone5_backyard_side_station_running
      zone_six:
        value_template: "{{ is_state('binary_sensor.zone6_front_yard_trash_station_running', 'on') }}"
        turn_on:
          service: opensprinkler.run
          data_template:
            entity_id: binary_sensor.zone6_front_yard_trash_station_running
            # Run seconds uses the input_number below.
            run_seconds: "{{ ((states('input_number.station_minutes') | float) * 60) | int }}"
        turn_off:
          service: opensprinkler.stop
          data:
            entity_id: binary_sensor.zone6_front_yard_trash_station_running
            
input_number:
  station_minutes:
    initial: 1
    min: 1
    max: 10
    step: 1

Creating a “Run Once” Button

In Step 3, you found the entity name for your “Run Once” scheduled program. If you’d like to create a button in Home Assistant that runs the schedule, you can do that too!

On your Lovelace dashboard, click Add Card > Button. Then, click the Show Editor button in the bottom left corner. Paste in this command, replacing the entity ID with the ID of your run once program.

This one doesn’t correctly change states, but it does run the program. Clicking it again just restarts the program; it’s doesn’t stop. You can tell if it’s running or not if you configured the multiple switches above. And if you’d like to stop it, you can click the top toggle of your multiple switch card.

For the icon, I used mdi:timer-outline

type: button
tap_action:
  action: call-service
  service: opensprinkler.run
  service_data:
    entity_id: binary_sensor.3_day_morning_tue_fri_sun_program_running
entity: binary_sensor.3_day_morning_tue_fri_sun_program_running
show_state: true
hold_action:
  action: toggle

There’s a lot of other entities you can add as well, if you’d like. Such as last run time, water level, whether or not OpenSprinkler is currently enabled. No configuration is needed for those, you can just add them like a regular entity.

Wrapping Up

I hope this guide helps you get OpenSprinkler all integrated in Home Assistant in 2021! I had a lot of fun getting this all set up. Having all my systems integrated into Home Assistant is pretty important to me, as my wife and I can now both run the sprinkler without having her need to download any extra apps.

Good luck!

You may also like

Leave a Comment