HASS sprinkler

Sorry xbmcnut I will not find the time to create a working example without all other stuff I have in there… The C&P above should help you along the way … the template sensors are the most important parts as they calculate the next run based on how the sliders and input select are set.

Please note that the function now should be replaced by now() since 29

If you run into issues I’m happy to look at them

Sorry for the dumb question but how did you hide the settings?
I tried to customize the group with hidden: true but it didnt hide all the group items.

What am i missing???

Hi Ron. Of course, I completely understand and in hindsight, it would probably be above my capabilities at the moment (I’m a hardware guy) are an overkill for my requirements. All I’m attempting to do is the following:

  • Schedule my two water valves on at 0630 everyday for 20 minutes with an input slider for the timer value
  • Check the state of my rain gauge (wet/dry) as a condition to prevent firing if wet
  • Have the timer fire based on the state change of the valve so that the timer always works, even if the valves are manually turned on. This is how it is set up with PLEG in my Vera which I’m trying to replicate in HA.

I’m learning YAML but it is a steep learning curve for a hardware guy, especially when the formatting in all of the examples on the main webpage bare no reference to the required formatting when you split your config up (which is kind of mandatory if you have more that a half-dozen devices).

This is where I’ve got to which I’m happy with (about 6hrs latter!) but is a way from where I need to be.

## Timed Garden Watering ##
timed_garden_water:
  alias: "Garden Water Timer"
  sequence:
    - service: script.turn_off
      entity_id: script.garden_water_timer
    - service: switch.turn_on
      entity_id: switch.ed01_relay1
    - service: switch.turn_on
      entity_id: switch.ed01_relay2
    - service: script.turn_on
      entity_id: script.garden_water_timer

garden_water_timer:
  alias: "Turn off garden water after x minutes"
  sequence:
    - condition: state
      entity_id: input_boolean.water_timer
      state: 'on'
    - delay:
        seconds: 5
    - service: switch.turn_off
      entity_id: switch.ed01_relay1
    - service: switch.turn_off
      entity_id: switch.ed01_relay2

Which gives me this. Any advice to help me achieve my goal would be appreciated.

Well it is not very well described in the documentation but it is done in the groups :slight_smile: nothing with hidden:true :slight_smile:

Groups for the sprinkler look like this:

  #########################
  # Sprinkler group
  #########################
  Sprinkler:
    view: yes
    entities:
      - group.valve_1_status

  valve_1_status:
    name: Valve 1
    icon: mdi:water-pump
    entities:
      - sensor.status_valve_1
      - sensor.last_run_valve_1
      - sensor.next_run_valve_1
      - sensor.schedule_valve_1
      - sensor.starttime_valve_1
      - sensor.duration_valve_1
      - group.valve_1_settings
      
  valve_1_settings:
    name: Settings
    icon: mdi:settings
    entities:  
      - input_select.valve_1_schedule
      - input_slider.valve_1_hour
      - input_slider.valve_1_minutes
      - input_slider.valve_1_duration

Please see also the group documentation on how to use view: yes together with the default_view to create your own layout in the front end. If you got that than the trick is easy as the above basically creates an entry for the Sprinkler in the top menu of the frontend that shows the view for the group valve_1_status. Now the last line in the view valve_1_status is another group group.valve_1_settings.

The effect is that the group.valve_1_settings is only shown if you click on the Settings in the view of valve_1_status.

Not sure if that is clear…

Basically you need to create an automation rule that triggers on turning a valve on. This should include a condition based on “Use Timer for Sprinklers” if that is ON/TRUE than turn_on script that turns them off after a set delay.

This is how I have done that with scripts:

  open_valve_1:
    alias: "Open Valve 1 - timer based"
    sequence:
      - service: script.turn_off
        data:
           entity_id: script.close_valve_1_delayed

      - service: switch.turn_on
        data:
          entity_id: switch.valve_1

      - service: script.turn_on
        data:
          entity_id: script.close_valve_1_delayed

  close_valve_1_delayed:
    alias: "Close Valve 1 after duration"
    sequence:
      - delay: '00:{% if states.input_slider.valve_1_duration.state|length < 4%}0{% endif %}{{ states.input_slider.valve_1_duration.state | int }}'
 
      - service: switch.turn_off
        data:
          entity_id: switch.valve_1

  close_valve_1:
    alias: "Close Valve 1 immediately"
    sequence:
      - service: script.turn_off
        data:
           entity_id: script.close_valve_1_delayed
           
      - service: switch.turn_off
        data:
          entity_id: switch.valve_1
1 Like

see also https://community.home-assistant.io/t/hide-group-attributes-if-used-as-nested-groups/3592

Thank you, that’s a big help. I’ve made some progress this evening but could not pass the value from the input_slider so I’ll try replicating your scripts over the weekend and see how I get on. I had this from a previous post but it does not work.

water_timer_off:
  alias: "Turn off water after (input select) minutes"
  sequence:
    - delay:
        minutes: '{{ input_slider.timer_options_slider }}'
    - service: homeassistant.turn_off
      data:
      entity_id: group.water_valves
      delay: '00:{{ states.input_slider.timer_options_slider.state | int }}:00'

I see you have 2 times a delay in there … not sure if that works

another tip is try to evaluate your template in the developer tools under Templates. That will show you how the template renders the output as a common issue here with time is that you get one digit back and than your delay looks like 00:5:00 and that will not work.

Search in this forum on the topic alarm clock and you will find lot of entries how other have solved some of the issues with this

Thanks, will do. Learning every day.

Hi Ronvl,
Suspect that Im getting the below errors due to the now function change.
Can you help identify which of the now statements need changing? Below is an example of a few instances I have found - unsure which examples need changing.

{% set runDate = ((as_timestamp(now) + (86400 * Days)) | timestamp_local) %} snip {% if states.sensor.starttime_valve_1.state < now.time().strftime("%H:%M") %} snip value_template: "{% if states.switch.valve_1.state == 'on'%}Opened {{((as_timestamp(now) - as_timestamp(states.switch.valve_1.last_changed)) / 60) | round(0) }} minutes ago{% else %}Closed{% endif %}" snip {% set weekday = weekdayList[(now.weekday()+ Days)] %}

Currently getting a couple errors in the log file on 0.30.2.

16-10-14 23:55:44 homeassistant.components.sensor.template: UndefinedError: ‘function object’ has no attribute ‘weekday’
16-10-14 23:55:44 homeassistant.components.sensor.template: UndefinedError: ‘None’ has no attribute ‘last_changed’

I’m not near HASS at the moment but it looks like you have two times as_timestamp(now) that need to be changed to as_timestamp(now()) I believe. You can test it via the developer tools under Templates, just past it in there there … way easier than starting the HASS every time :slight_smile:

Can check it later this weekend if it not works

Thanks, its working.

Please be aware that the Status that shows how long the Valve is open is not working anymore since 29.5…
See:

If you follow the links to the PR you will find a work around that I haven’t tested yet… as it is authum here in Germany and getting below zero at night the sprinkler is currently not installed :slight_smile:

I noticed that if i restart hass the parameters i set are not saved and rolls back to default.
For example the select sensor returns back to its default which is None.
Also the time and duration is reset to default.

Is this normal or did i do something wrong?

Yep normal behavior of HASS at the moment.
See Ability for input_boolean, input_select and input_slider to retain values over a restart

Instead of automation with slide bars for,hour and minute and days, I moved my logic to be control with a google calendar with the latest release.

My sensor Based on the calendar searches for Bed 1, which is my sprinkler in one of my raised bed, it uses the state = on to turn it off, but I still set the off with a timer set with a slider and a Mqtt command

Hi guys,
I’ve used a line from the code above:

last_run_valve_1:
friendly_name: ‘Last Run’
entity_id: switch.valve_1
value_template: “{{states.switch.valve_1.last_changed.strftime(’%a’)}}, {{states.switch.valve_1.last_changed.strftime(’%d-%m-%Y’)}}”

to create a sensor for when I last ran the sprinkler automation. The issue I’m having is the time here isn’t my “local” timezone it’s the UTC timezone that home assistant runs everything with in the background. How can i translate to my local time with the strftime?

Hey Guys,
did someone got an answer for this error?

17-01-25 15:17:45 ERROR (MainThread) [homeassistant.components.sensor.template] UndefinedError: 'function object' has no attribute 'weekday'

I get this error every time now.weekday() is called.

Greets Julian

@thejacko12354 that code is a bit old and now.weekday() is replaced by now().weekday(). have a search on the release notes as there were a few changes since

@ronvl yeah i found that error.
Now I’m stuck with the next one…
If I set a day, I get this error:

Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/usr/lib/python3.5/site-packages/homeassistant-0.36.0.dev0-py3.5.egg/homeassistant/helpers/entity.py", line 212, in async_update_ha_state
    yield from self.async_update()
  File "/usr/lib/python3.5/asyncio/coroutines.py", line 206, in coro
    res = func(*args, **kw)
  File "/usr/lib/python3.5/site-packages/homeassistant-0.36.0.dev0-py3.5.egg/homeassistant/components/sensor/template.py", line 114, in async_update
    self._state = self._template.async_render()
  File "/usr/lib/python3.5/site-packages/homeassistant-0.36.0.dev0-py3.5.egg/homeassistant/helpers/template.py", line 99, in async_render
    return self._compiled.render(kwargs).strip()
  File "/usr/lib/python3.5/site-packages/jinja2/environment.py", line 989, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/lib/python3.5/site-packages/jinja2/environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3.5/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 66, in top-level template code
  File "/usr/lib/python3.5/site-packages/jinja2/sandbox.py", line 355, in call
    return __context.call(__obj, *args, **kwargs)
  File "/usr/lib/python3.5/site-packages/homeassistant-0.36.0.dev0-py3.5.egg/homeassistant/util/dt.py", line 79, in as_timestamp
    raise ValueError("not a valid date/time.")
ValueError: not a valid date/time.