Integrate with OpenSprinkler

Hi UI Guy

At the moment I have my Home Assistant setup all built and running nicely with a few automations and existing senors for temperature, humidity, and presence (via wifi connections).

I’m planning on buying the MiFlora sensor and Open Sprinkler Bee in the Black Friday sales next week.

So did you have much luck connecting up MiFlora, Home Assistant, and Open Sprinkler? I’m assuming you went down the REST path to interact with Open Sprinkler?

Craig

Hi,

Yes I am all setup and all is working great.

I went with command line to integrate OPensprinkler… details here: Integrate with OpenSprinkler

I’ve created a package file for this. It contains most of the above put together for easy reference.

Things I’d like to see added in this thread:

  • Automations that delay based on a rainy day
  • Automations that take into account a heat wave, or factor in summer months
  • Automations that get their status from Mi Flora, and auto water when conditions require it.
  • Notifications when the sprinklers start, and at end time, advise the run duration.
  • Anything else?

Copy and paste the below into your packages directory. Be sure to set the configuration.yaml up such that it will reference the package file.

    switch:
      - platform: command_line
        switches:
          veggies:
            command_on: '/usr/bin/curl -X GET "http://192.168.X.X/cm?pw=xxx&sid=0&en=1&t=600"'
            command_off: '/usr/bin/curl -X GET "http://192.168.X.X/cm?pw=xxx&sid=0&en=0"'
            command_state: '/usr/bin/curl -X GET "http://192.168.X.X/js?pw=xxx&sid=0&en=0"'
            friendly_name: Veggies Valve
            value_template: "{{ value_json.sn[0] == 1 }}"

    sensor:
      name: "Opensprinkler"
      platform: rest
      resource: http://192.168.X.X/js?pw=xxx
      value_template: "{{ value_json.sn[0] }}"

    input_number:
      sprinkler_timer:
        name: Sprinkler Timer
        min: 1
        max: 60
        step: 1
        initial: 5
        unit_of_measurement: step
        icon: mdi:target

    group:
      sprinkler:
        name: Sprinklers
        entities:
          - switch.veggies
          - input_number.sprinkler_timer
        
    automation:
      - alias: Opensprinkler Timer
        trigger: 
          platform: state
          entity_id: switch.veggies
          to: 'on'
        action:
          - delay: '00:{{ states.input_number.sprinkler_timer.state | int }}:00'
          - service: homeassistant.turn_off
            entity_id: switch.veggies

See my comments below inline:

Hey all,

I created a custom component for opensprinkler over the weekend. It is available here: https://github.com/vinteo/hass-opensprinkler

I’m new to python and home assistant so it’s a work in progress but some of you might find it useful

5 Likes

thanks a lot!

is it possible to modify the timer time? by defoult is 1 to 10 min. i wish it can be set up to 2 hours.
and also, are the scene working? i can see the program in thee ha ui. but when i trigger one scene opensprinkler doesn’t start the progam.

1 Like

hi nebbiadigiorno,

i will look to add the maximum into config. but in the mean time you can just change the following line to the number you want (in minutes)

regarding the scene, it works for me, do you have any errors in the HA log? look at info under the developer tools

Nice timing!
Im also developing one, but I only did the monitoring, chek it out.
https://github.com/philmottin/ha-opensprinkler

Now, Im working to integrate the controller components.
When I was trying your code for adding the input_numbers, I notice a problem, the state get stuck with initial value (1). It never updates when you change the slider, only if you set state value via services tab.
First a tought it was a compability issue somehow on our code, but I got the same behavior after running only your component. Can you please confirm this?

1 Like

Hi philmottin,

first of all great job! I haven’t used yours yet but from the screenshots it looks great!

To answer you question, I have not noticed that issue, but I just tried it and “Unable to find service input_number/set_value” warnings are appearing in the logs now. I never noticed these warnings before but I did just update HA yesterday, so there might be an issue there. But I cannot confirm if it wasn’t there before. Will have to test it more, let me know if you find a solution.

BTW not sure if you are willing, but maybe we should only continue with one component instead of doing two separate ones. I am happy to just stop developing mine since yours looks much better and integrate my crappy code into yours if any of it is of any use.

I made a few tests, and still don’t know why any dynamically created entity doesn’t update it state.
If you open two home assistant windows and change one (slider for example), the same one on the second window won’t update.
This happens to the input_sliders and input_text that are commented on main component setup code. uncomment lines 91-96 to see

I had to use a dummy input_text as data transfer between custom ui state cards and custom scene component
I don’t think using scenes to handle all the controller’s logic is the right way to do. Polymer is not so user friendly. This is the way I figure to make it all work, but it’s not good… yet :slight_smile:
Looking foward to keep improving this, hopefully someone with better understanding can help us.

Here is the new version with the controller components
https://github.com/philmottin/ha-opensprinkler

os_controler

you have decide to merge your project? or it will be 2 separate component?

I will have some time to test phil’s component this weekend. If it fits my needs i will start using his

Hi philmottin,

have you pushed your latest code? I cannot seem to get the “controller” card going, it just shows an empty card. There are some console errors on the browsers, not sure if it is causing it:

Uncaught TypeError: Cannot read property ‘attributes’ of undefined
at Object.getViewEntities (core-aa5473dbea8ac5b75ae0e8239f8e0e38.js:1)
at HTMLElement.computeViewStates (frontend-ebcb41952b21503c6a09065b084a638d.html:86)
at f (frontend-ebcb41952b21503c6a09065b084a638d.html:1)
at Object.l [as fn] (frontend-ebcb41952b21503c6a09065b084a638d.html:1)
at a (frontend-ebcb41952b21503c6a09065b084a638d.html:1)
at e (frontend-ebcb41952b21503c6a09065b084a638d.html:1)
at frontend-ebcb41952b21503c6a09065b084a638d.html:1
at HTMLElement._propertiesChanged (frontend-ebcb41952b21503c6a09065b084a638d.html:1)
at HTMLElement._flushProperties (frontend-ebcb41952b21503c6a09065b084a638d.html:1)
at HTMLElement._flushProperties (frontend-ebcb41952b21503c6a09065b084a638d.html:1)

Hey vinteo, Im not sure what’s going on based on the logs, but let’s figure this out.

Try clicking on the errror’s line number with chrome, and see which html file was.

Make sure you have custom-ui installed -> link
Are the custom cards (html files) copied on www/custom_ui ? including all ha-custom-ui and mines

How is your configs.yaml? Make sure is all set accordfing my git instructions. Post you config if you can.

Maybe try loading the custom-ui without my component just to make sure the custom-ui is loaded without problems.

if you load the cuistom-ui alone, you should be able to this to a light switch:

customize:
  light.office:
    custom_ui_state_card: state-card-custom-ui
    extra_data_template: "more data"

check if the switch has “more data” text showing

Using the hosted style I can load the custom-ui on its own, tested with your config above.

Seems like it is not loading your custom html, not sure what stupid thing I am doing wrong. here is my config

opensprinkler:
  host: xxxx
  port: 80
  password: !secret opensprinkler

input_text:
  scene_temp_var:
    initial: 'off:1'

sensor:
  - platform: opensprinkler
    monitored_conditions:
      - opensprinkler_station
      - opensprinkler_schedule
      - opensprinkler_lastrun
      - opensprinkler_rain

group:
  group_opensprinkler:
    name: 'Open Sprinkler'
    control: hidden
    entities:
      - sensor.os_lastrun
      - sensor.os_rain
      - sensor.os_schedule_1
      - sensor.os_schedule_2
      - sensor.os_schedule_3
      - sensor.os_schedule_4
        #continue with all your schedules
      - sensor.os_station_1
      - sensor.os_station_2
      - sensor.os_station_3
      - sensor.os_station_4
      - sensor.os_station_5
      - sensor.os_station_6
      - sensor.os_station_7
      - sensor.os_station_8
      - sensor.os_pump_1
      - sensor.os_pump_2

  group_opensprinkler_controller:
    name: 'Open Sprinkler controller'
    control: hidden
    entities:
      - scene.os_program_1
      - scene.os_program_2
      - scene.os_program_3
      - scene.os_program_4
      #continue with all your schedules
      - scene.os_station_1
      - scene.os_station_2
      - scene.os_station_3
      - scene.os_station_4
      - scene.os_station_5
      - scene.os_station_6
      - scene.os_station_7
      - scene.os_station_8

and I have this:

frontend:
  extra_html_url:
    - https://raw.githubusercontent.com/andrey-git/home-assistant-custom-ui/master/state-card-custom-ui.html
    - /local/custom_ui/state-card-opensprinkler-control-station.html
    - /local/custom_ui/state-card-opensprinkler-control-program.html
  extra_html_url_es5:
    - https://raw.githubusercontent.com/andrey-git/home-assistant-custom-ui/master/state-card-custom-ui-es5.html

I no longer have the console error. I can see all your sensors, but the controller card is empty. I copied the html into /config/www/custom_ui/ ? Is this the right place for hass.io image?

I Figured it out I need to add this:

customize_glob:
    "*.*":
      custom_ui_state_card: state-card-custom-ui

in the homeassistant: section

Just got your code installed but it’s having a problem loading the custom component. I have HA running on a Windows machine which could be the source of the problem but I’m hoping you could possibly help me try to figure out what’s wrong and get it running for me.

Here’s what I see in the log:

2018-02-28 16:57:56 ERROR (MainThread) [homeassistant.setup] Error during setup of component opensprinkler
Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\homeassistant\setup.py", line 148, in _async_setup_component
    component.setup, hass, processed_config)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\asyncio\futures.py", line 327, in __iter__
    yield self  # This tells Task to wait for completion.
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\asyncio\tasks.py", line 250, in _wakeup
    future.result()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\asyncio\futures.py", line 243, in result
    raise self._exception
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\concurrent\futures\thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Users\Administrator\AppData\Roaming\.homeassistant\custom_components\opensprinkler.py", line 63, in setup
    hass.data[DATA_OPENSPRINKLER].update()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\homeassistant\util\__init__.py", line 306, in wrapper
    result = method(*args, **kwargs)
  File "C:\Users\Administrator\AppData\Roaming\.homeassistant\custom_components\opensprinkler.py", line 130, in update
    api_dict['data'] = parse_api_data(json.loads(response.text, object_pairs_hook=OrderedDict))
  File "C:\Users\Administrator\AppData\Roaming\.homeassistant\custom_components\opensprinkler.py", line 249, in parse_api_data
    programs = response['programs']['pd']
KeyError: 'programs'
2018-02-28 16:57:56 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of sensor.opensprinkler. Setup failed for dependencies: opensprinkler
2018-02-28 16:57:56 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.opensprinkler: Could not setup all dependencies.

If you need specifics of OS or Python versions I can supply that.

Thanks,
George

I did a little debugging and first I verified that the modules required for each of the programs in the stack trace were on my machine and they were.

Then I decided to add a couple of debug statements in the component program opensprinkler.py:

    server = conf.get(CONF_HOST)
    port = conf.get(CONF_PORT)
    password = conf.get(CONF_PASSWORD)
    _LOGGER.warning("password string: %s", password)

    server += ":"+port
    _LOGGER.warning("server string: %s", server)
    hass.data[DATA_OPENSPRINKLER] = OpenSprinklerData(server, password)
    _LOGGER.warning("hass.data[] string: %s", hass.data[DATA_OPENSPRINKLER])

Everything looks fine in the log file (I have the password in MD5 hash lower case but I’ve removed it in this paste)

2018-02-28 18:25:03 WARNING (SyncWorker_7) [custom_components.opensprinkler] password string: xxXXxx
2018-02-28 18:25:03 WARNING (SyncWorker_7) [custom_components.opensprinkler] server string: 192.168.10.230:8080
2018-02-28 18:25:03 WARNING (SyncWorker_7) [custom_components.opensprinkler] hass.data[] string: <custom_components.opensprinkler.OpenSprinklerData object at 0x0630D570>
2018-02-28 18:25:04 ERROR (MainThread) [homeassistant.setup] Error during setup of component opensprinkler
Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\homeassistant\setup.py", line 148, in _async_setup_component
    component.setup, hass, processed_config)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\asyncio\futures.py", line 327, in __iter__
    yield self  # This tells Task to wait for completion.
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\asyncio\tasks.py", line 250, in _wakeup
    future.result()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\asyncio\futures.py", line 243, in result
    raise self._exception
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\concurrent\futures\thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Users\Administrator\AppData\Roaming\.homeassistant\custom_components\opensprinkler.py", line 66, in setup
    hass.data[DATA_OPENSPRINKLER].update()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib\site-packages\homeassistant\util\__init__.py", line 306, in wrapper
    result = method(*args, **kwargs)
  File "C:\Users\Administrator\AppData\Roaming\.homeassistant\custom_components\opensprinkler.py", line 133, in update
    api_dict['data'] = parse_api_data(json.loads(response.text, object_pairs_hook=OrderedDict))
  File "C:\Users\Administrator\AppData\Roaming\.homeassistant\custom_components\opensprinkler.py", line 252, in parse_api_data
    programs = response['programs']['pd']
KeyError: 'programs'
2018-02-28 18:25:04 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of sensor.opensprinkler. Setup failed for dependencies: opensprinkler
2018-02-28 18:25:04 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.opensprinkler: Could not setup all dependencies.

I’ll keep poking but hopefully someone more experienced in Python can help out.

…with line 129 logger warning enabled I can see the response is:

2018-02-28 18:39:50 WARNING (SyncWorker_6) [custom_components.opensprinkler] response: {"fwv":217}

So I’m getting a response from opensprinkler but is this the first expected response?