@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.
Hi @ronvl, I copied some of your code a while back and was never able to get it to work properly. I read that home assistant does all of it’s time calculations at timezone +0 GMT and then converts it to your local time after when displaying on the UI. The problem I’m having is getting the following to not use the internal time and use my local time when displaying on the sensor. I’m in timezone +8 so it always displays 8 hours behind. If you can help that would be much appreciated!
I don’t know how to run those in developer tools, what Domain and Service do i use? I’m assuming that list is supposed to go under the Service Data (JSON, optional)?
I’m starting to think about a garden project ready for the summer. At the moment I have no hardware for the garden at all but I have experience with ESP8266/Arduino (currently using some for PIR/Temp Sensors in HASS).
If you were to start from scratch, what hardware would you use? At the moment I have an outside tap and a water butt and NOTHING else. Would be interested to hear what people would recommend.
What I’d like to do is… water my veg patch, borders and grass.
I’m using Dark Sky to predict weather in HASS today. And I have a weather station linked to Wunderground which is then imported into HASS for live weather of my garden also (temp, wind direction, speed and rain)
Working on same. Got a LinkNode R4 controlled by HA/MQTT but would like to see HA code for nice UI to set and run an irrigation schedule.
Did you finish your project?
Any chance of sharing on GitHub?
Hey revz
The code is all there in the postings. HASS has moved on a lot and things might not all work anymore but the basics still does. I have started to add and change things a bit since as well so I can’t realy share this any more as it was shown here.
If I had to do it again I would use python scripts, custom_ui and make a custom sprinkler component based on the switch component. That is the problem with HASS it is sooo flexible
Ah, yes ok I see that now. Good advice re: python scripts and custom UI, I’ve seen that approach recommended elsewhere. Agreed re: HASS- flexibility is its strength but can be a problem too!
It is a sensor that calculates th ethe next rundate based on the various settings on the valve
next_run_valve_1:
friendly_name: 'Next Run'
value_template: >
{# runDay set to 9 = Not Set #}
{% set runDay = 9 |int %}
{# Set todays day #}
{% set currentDay = now().weekday() |int %}
{# calculate starttime #}
{%- macro starttime() -%}
{%- if states.input_number.valve_1_hour.state|length < 4-%}
{{0}}
{%- endif -%}
{{states.input_number.valve_1_hour.state | int }}{{':'}}
{%- if states.input_number.valve_1_minutes.state|length < 4 -%}
{{0}}
{%- endif -%}
{{ states.input_number.valve_1_minutes.state | int }}
{%- endmacro -%}
{% set StartTime = starttime() %}
{%- macro monthu() -%}
{%- if currentDay == 0 -%}
{{0}}
{%- elif currentDay <= 3 -%}
{{3}}
{%- else -%}
{{0}}
{%- endif -%}
{%- endmacro -%}
{%- macro monwedfrisun() -%}
{%- if currentDay == 0 -%}
{{0}}
{%- elif currentDay <= 2 -%}
{{2}}
{%- elif currentDay <= 4 -%}
{{4}}
{%- elif currentDay <= 6 -%}
{{6}}
{%- endif -%}
{%- endmacro -%}
{# set configured runDay from input_select #}
{% if states.input_select.valve_1_schedule.state == "Monday" %}
{% set runDay = 0 |int %}
{% elif states.input_select.valve_1_schedule.state == "Tuesday" %}
{% set runDay = 1 |int %}
{% elif states.input_select.valve_1_schedule.state == "Wednesday" %}
{% set runDay = 2 |int %}
{% elif states.input_select.valve_1_schedule.state == "Thursday" %}
{% set runDay = 3 |int %}
{% elif states.input_select.valve_1_schedule.state == "Friday" %}
{% set runDay = 4 |int %}
{% elif states.input_select.valve_1_schedule.state == "Saturday" %}
{% set runDay = 5 |int %}
{% elif states.input_select.valve_1_schedule.state == "Sunday" %}
{% set runDay = 6 |int %}
{% elif states.input_select.valve_1_schedule.state == "Mon Thu" %}
{% set runDay = monthu() |int -%}
{% elif states.input_select.valve_1_schedule.state == "Mon Wed Fri Sun" %}
{% set runDay = monwedfrisun() |int %}
{% elif states.input_select.valve_1_schedule.state == "Every Day" %}
{% set runDay = currentDay |int %}
{% endif %}
{# determine the next runday #}
{% if runDay == 9 %}
{# schedule not active #}
{% set runDate = "Not set" %}
{% else %}
{# schedule is active so determine next run #}
{# first check if runDay = today #}
{% if currentDay == runDay %}
{# are we passed the scheduled time? #}
{% if starttime() < now().time().strftime("%H:%M") %}
{# than we need to fake tomorrow #}
{% set currentDay = (currentDay + 1) |int %}
{# and calculate new runDay in case we have a list of multiple run days in in a week #}
{% if states.input_select.valve_1_schedule.state == "Mon Thu" %}
{% set runDay = monthu() |int -%}
{% elif states.input_select.valve_1_schedule.state == "Mon Wed Fri Sun" %}
{% set runDay = monwedfrisun() |int %}
{% elif states.input_select.valve_1_schedule.state == "Every Day" %}
{% set runDay = currentDay |int %}
{% endif %}
{% endif %}
{% endif %}
{# Now we can determine next runDate base on now().weekday() and not currentDay as that can be set to fake tomorrow #}
{% if currentDay <= runDay %}
{% set Days = runDay - now().weekday() |int %}
{% else %}
{% set Days = runDay + 7 - now().weekday() |int %}
{% endif %}
{% set runDate = ((as_timestamp(now()) + (86400 * Days)) | timestamp_local) %}
{# we also want to show the weekday of the next date #}
{% set weekdayList = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] %}
{% if now().weekday()+ Days < 7 %}
{% set weekday = weekdayList[(now().weekday()+ Days)] %}
{% else %}
{% set weekday = weekdayList[(now().weekday()+ Days)- 7] %}
{% endif %}
{% endif %}
{# all done #}
{# set states.sensor.next_run_date_valve_1.state = runDate #}
{% if runDay == 9 %}
{# schedule not active #}
{{runDate}}
{% else %}
{{weekday}}, {{runDate[8:10]}}-{{runDate[5:7]}}-{{runDate[0:4]}} at {{starttime()}}
{% endif %}
To be fair I don’t know if it is all still running (as there where a few HASS updates) as it is winter here and I haven’t been using it since September. I guess in a couple of months I need to get it up and running again.
Will not update and remains “Opened 0 minutes ago”.
Looking online this seems due to template sensor values not updating with now().
Fix: Link. Create a new Time & Date sensor then use that in place of “Now()”
I.E. Replace “now()” with “strptime(states.sensor.date__time.state, ‘%Y-%m-%d, %H:%M’”
Hey guys, had quite a struggle to get this working on 0.94.0. I’m experiencing issues when setting the schedule to include more than one day, for instance, Mon,Tue,Wednesday. The next runtime will change to “Not Set” Is this normal? The next runtime on any other static day like just “Monday” works without an issue.
next_run_valve_1:
friendly_name: 'Next Run'
value_template: >
{# runDay set to 9 = Not Set #}
{% set runDay = 9 |int %}
{# Set todays day #}
{% set currentDay = now().weekday() |int %}
{# calculate starttime #}
{%- macro starttime() -%}
{%- if states.input_number.valve_1_hour.state|length < 4-%}
{{0}}
{%- endif -%}
{{states.input_number.valve_1_hour.state | int }}{{':'}}
{%- if states.input_number.valve_1_minutes.state|length < 4 -%}
{{0}}
{%- endif -%}
{{ states.input_number.valve_1_minutes.state | int }}
{%- endmacro -%}
{% set StartTime = starttime() %}
{%- macro monthu() -%}
{%- if currentDay == 0 -%}
{{0}}
{%- elif currentDay <= 3 -%}
{{3}}
{%- else -%}
{{0}}
{%- endif -%}
{%- endmacro -%}
{%- macro monwedfrisun() -%}
{%- if currentDay == 0 -%}
{{0}}
{%- elif currentDay <= 2 -%}
{{2}}
{%- elif currentDay <= 4 -%}
{{4}}
{%- elif currentDay <= 6 -%}
{{6}}
{%- endif -%}
{%- endmacro -%}
{# set configured runDay from input_select #}
{% if states.input_select.valve_1_schedule.state == "Monday" %}
{% set runDay = 0 |int %}
{% elif states.input_select.valve_1_schedule.state == "Tuesday" %}
{% set runDay = 1 |int %}
{% elif states.input_select.valve_1_schedule.state == "Wednesday" %}
{% set runDay = 2 |int %}
{% elif states.input_select.valve_1_schedule.state == "Thursday" %}
{% set runDay = 3 |int %}
{% elif states.input_select.valve_1_schedule.state == "Friday" %}
{% set runDay = 4 |int %}
{% elif states.input_select.valve_1_schedule.state == "Saturday" %}
{% set runDay = 5 |int %}
{% elif states.input_select.valve_1_schedule.state == "Sunday" %}
{% set runDay = 6 |int %}
{% elif states.input_select.valve_1_schedule.state == "Mon Thu" %}
{% set runDay = monthu() |int -%}
{% elif states.input_select.valve_1_schedule.state == "Mon Wed Fri Sun" %}
{% set runDay = monwedfrisun() |int %}
{% elif states.input_select.valve_1_schedule.state == "Every Day" %}
{% set runDay = currentDay |int %}
{% endif %}
{# determine the next runday #}
{% if runDay == 9 %}
{# schedule not active #}
{% set runDate = "Not set" %}
{% else %}
{# schedule is active so determine next run #}
{# first check if runDay = today #}
{% if currentDay == runDay %}
{# are we passed the scheduled time? #}
{% if starttime() < now().time().strftime("%H:%M") %}
{# than we need to fake tomorrow #}
{% set currentDay = (currentDay + 1) |int %}
{# and calculate new runDay in case we have a list of multiple run days in in a week #}
{% if states.input_select.valve_1_schedule.state == "Mon Thu" %}
{% set runDay = monthu() |int -%}
{% elif states.input_select.valve_1_schedule.state == "Mon Wed Fri Sun" %}
{% set runDay = monwedfrisun() |int %}
{% elif states.input_select.valve_1_schedule.state == "Every Day" %}
{% set runDay = currentDay |int %}
{% endif %}
{% endif %}
{% endif %}
{# Now we can determine next runDate base on now().weekday() and not currentDay as that can be set to fake tomorrow #}
{% if currentDay <= runDay %}
{% set Days = runDay - now().weekday() |int %}
{% else %}
{% set Days = runDay + 7 - now().weekday() |int %}
{% endif %}
{% set runDate = ((as_timestamp(now()) + (86400 * Days)) | timestamp_local) %}
{# we also want to show the weekday of the next date #}
{% set weekdayList = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] %}
{% if now().weekday()+ Days < 7 %}
{% set weekday = weekdayList[(now().weekday()+ Days)] %}
{% else %}
{% set weekday = weekdayList[(now().weekday()+ Days)- 7] %}
{% endif %}
{% endif %}
{# all done #}
{# set states.sensor.next_run_date_valve_1.state = runDate #}
{% if runDay == 9 %}
{# schedule not active #}
{{runDate}}
{% else %}
{{weekday}}, {{runDate[8:10]}}-{{runDate[5:7]}}-{{runDate[0:4]}} at {{starttime()}}
{% endif %}
My project uses only sonoff Flashed with Tasmota. In Hass have UI and one scene, some automation only for emergency stop and notifications to phone apk. Base is on Node-Red.