My Garden Irrigation

I suspect so, although I am now GMT+1

I’m also on GMT+1 but with DST it’s +2

Sorry, I meant I am on GMT but now also on DST so GMT+1

1 Like

This should be the code related to this, right?

  cycle1_next_run_time:
    friendly_name: "Next scheduled run time"
    value_template: >
      {% if is_state('input_boolean.cycle1_enable', 'on') %}
        {{ state_attr('input_datetime.cycle1_next_run_time', 'timestamp') | timestamp_custom("%a %d %h at %H:%M") }}
      {% else %}
        None
      {% endif %}

  cycle2_next_run_time:
    friendly_name: "Next scheduled run time"
    value_template: >
      {% if is_state('input_boolean.cycle2_enable', 'on') %}
        {{ state_attr('input_datetime.cycle1_next_run_time', 'timestamp') | timestamp_custom("%a %d %h at %H:%M") }}
      {% else %}
        None
      {% endif %}

Maybe @petro can give some feedback.
Thanks!

This is from the HA docs [https://www.home-assistant.io/docs/configuration/templating/] but I am not sure what local_boolean is. I do have some recollection of it being important sometimes :slight_smile:

image

Strange that it works for me but not you though…

1 Like

I checked my local timezone in the Ubuntu VM and it’s correctly set to Europe/Rome
Then, I have Hassio, it’s in a docker container where I can’t set anything related to TZ, AFAIK.

I tried also to modify the timestamp_custom("%a %d %h at %H:%M") in timestamp_local but nothing changed.
Now it’s reverted back

Is there anyone using this package in a docker container ?

I may have misunderstood you or even if this is the problem but you know you can set Timezone in hassio?

configuration.yaml

homeassistant:
  name: !secret name
  latitude: !secret latitude
  longitude: !secret longitude
  elevation: 40
  unit_system: metric
  time_zone: !secret time_zone

I’m also living in Italy and I get correct values as @klogg

Are you on Docker?
I’m just trying to imagine what can be the issue.

Actually I’m using another irrigation system and here all is working fine when I set the schedule

46

This is how is defined the sensor that shows next run tme (VERY LONG!)

  next_run_zone_1:
     friendly_name: 'Next Run'
     icon_template: mdi:calendar-clock
     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.zone_1_hour.state|length < 4-%}
                {{0}}
            {%- endif -%}
            {{states.input_number.zone_1_hour.state | int  }}{{':'}}
            {%- if states.input_number.zone_1_minutes.state|length < 4 -%}
               {{0}}
            {%- endif -%}
            {{ states.input_number.zone_1_minutes.state | int }}
        {%- endmacro -%}
        {% set StartTime = starttime() %}
        {%- macro tuethusat() -%}
            {%- if currentDay <= 1 -%}
                {{1}}
            {%- elif  currentDay <= 3 -%}
                {{3}}
            {%- elif  currentDay <= 5 -%}
                {{5}}
            {%- elif  currentDay <= 6 -%}
                {{1}}
            {%- 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.zone_1_schedule.state == "Monday" %}
            {% set runDay = 0 |int %}
        {% elif states.input_select.zone_1_schedule.state == "Tuesday" %}
            {% set runDay = 1 |int %}
        {% elif states.input_select.zone_1_schedule.state == "Wednesday" %}
            {% set runDay = 2 |int %}
        {% elif states.input_select.zone_1_schedule.state == "Thursday" %}
            {% set runDay = 3 |int %}
            {% elif states.input_select.zone_1_schedule.state == "Friday" %}
            {% set runDay = 4 |int %}
        {% elif states.input_select.zone_1_schedule.state == "Saturday" %}
            {% set runDay = 5 |int %}
        {% elif states.input_select.zone_1_schedule.state == "Sunday" %}
            {% set runDay = 6 |int %}
        {% elif states.input_select.zone_1_schedule.state == "Tue/Thu/Sat" %}
            {% set runDay = tuethusat() |int -%}
        {% elif states.input_select.zone_1_schedule.state == "Mon/Wed/Fri/Sun" %}
            {% set runDay = monwedfrisun() |int %}
        {% elif states.input_select.zone_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.zone_1_schedule.state == "Tue/Thu/Sat" %}
                        {% set runDay = tuethusat() |int -%}
                    {% elif states.input_select.zone_1_schedule.state == "Mon/Wed/Fri/Sun" %}
                        {% set runDay = monwedfrisun() |int %}
                    {% elif states.input_select.zone_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_zone_1.state = runDate #}
        {% if runDay == 9 %}
            {# schedule not active #}
            {{runDate}}
        {% else %}
            {{weekday}}, {{runDate[8:10]}}-{{runDate[5:7]}}-{{runDate[0:4]}} at {{starttime()}}
        {% endif %}

No I’ve HA installed on a rasbian os

Probably I’ve found the issue.

The Hassio container has UTC has Timezone.

My issue now is how to change it and if I have to change it in both homeassistant and hassio-supervisor container or just the first.

I’m using Portainer, but I don’t know where to change it.

In any case, if this is the issue, the strange thing is why the other irrrigation system sensor return the correct time.

I will try to find another thread where to ask how to change TZ in Docker

1 Like

It’s working!

I’ve set TZ to Europe/Rome and now all is perfect!!!

Thanks to all!

1 Like

HI @klogg, I see in the HA log this WARNING:

[homeassistant.components.automation] Error while executing automation automation.irrigation_master_control_switch. Invalid data for call_service at pos 2: not a valid value for dictionary value @ data['entity_id'] 

I’m not sure there is a problem or not…

I’m not getting that warning.

Can you check that your weather calculation automations have an alias beginning with

Irrigation Weather -

I think I might have changed this at some point after my first GitHub upload.
The current version is correct.

I’m getting too an error on something strange.

When I click the Morning cycle button, the big one, to have a manual cycle, I see Initialising but I still see Not running and nothing happen.

Then the error I get in the log is this

Error while executing automation automation.irrigation_run_a_cycle_manually. Invalid data for call_service at pos 8: Could not parse date for dictionary value @ data['date']

When I try to run the Afternoon cycle manually, all is ok.

Another thing is related to the last HA update, 0.91

Something changed in DarkSky, they introduced also hourly forecast, so the final number indicating the forecast day is now changed in d where d stands for day, and h where h stands for hour.

Strange thing also, is that in your data_collection file I found

sensor. sensor.dark_sky_forecast_daytime_high_temperature_0

while I have, in my devices list,

sensor.dark_sky_daytime_high_temperature_0

without the _forecast word

Really odd!!!

PS: regarding the error, I found that if the input_select.cycle' + cycle + '_watering_days is set to “Once” the Manual activation does not work and produce the error I showed before.
Otherwise it works!

I was writing this reply when I saw your PS.

Yes you are right, good spot I have never had my schedule set to Once!! And thanks for finding this error. There needs to be something in the else in the script irrigation_run_a_cycle.

I will look at fixing this…


I have not yet updated to 0.91 but yes, I will need to change my Dark Sky sensor names when I do.


As for the sensor, yes I have two Dark Sky sensors. the reason for this is because I don’t want hundreds of sensors all updating too often. I have a separate sensor for forecasting that updates less frequently.

  #==============================================
  #=== Dark Sky sensor for forecasting in the
  #=== Custom Dark Sky Animated Weather Card
  #==============================================
  - platform: darksky
    api_key: !secret darksky_api_key
    name: dark_sky_forecast
    units: auto
    scan_interval:
      minutes: 720
    forecast:
      - 0
      - 1
      - 2
      - 3
      - 4
      - 5
    monitored_conditions:
      - icon
      - summary
      - temperature_high           
      - temperature_low 
      - precip_intensity_max
      - precip_probability


  #===================================================
  #=== Dark Sky sensor for current weather conditions
  #===================================================
  - platform: darksky
    api_key: !secret darksky_api_key
    name: dark_sky
    units: auto
    scan_interval:
      hours: 1
    monitored_conditions:
      - icon
      - summary
      - minutely_summary 
      - hourly_summary
      - daily_summary
      - temperature
      - apparent_temperature
      - precip_intensity
#      - precip_type            # If precip_intensity is zero, then this property will be unknown
#      - precip_accumulation    # If no snowfall is expected, this property will be undefined
      - dew_point
      - wind_speed
      - wind_gust
      - wind_bearing
      - cloud_cover
      - humidity
      - pressure
      - visibility
      - ozone
      - uv_index
      - moon_phase
      - nearest_storm_distance
      - nearest_storm_bearing
1 Like

Thanks @klogg for your help!

“Once” does not work also if you have defined a schedule, not only manually, so it should be something related to this…

Yes, every time you run a cycle either scheduled or manually it will call the same script and if it is set for ‘Once’ it will fail!

The solution is to add something to the else which doesn’t change the next run time.

Also, I think this service call should be moved into its own script because it really should only be called on a scheduled run, not a manual run.

For example if you run manually at 8AM and have a schedule set for 10AM you might still want that schedule to run. As it is coded now, the manual run will change the next scheduled run to be for the next day (or the day after that) and the 10AM scheduled run will never happen.

Finally I think I also should add a trigger for the state change of the watering_days to the automation ‘Irrigation - Set next run time when schedule enabled or time changed’ so that it updates the next run time if you change the Watering Days…

I hope that all makes sense, I have uploaded to GitHub.

As always let me know how it goes for you or if you disagree with my reasons for the changes!

1 Like

Thanks @klogg

I’ve tried the manual and scedule with Once and it works fine now.
If I have a scheduled irrigation and I click any manual one, at the end the schedule will return active with the previously defined schedule time.

Fantastic!
Thanks again

1 Like

Hey klogg, that’s some pretty impressive job! well done!
I’ve spent all morning trying to integrate into my system and use a sonoff 4ch pro with original FW connected through peterbuga’s component.

I must say everything went well but it took some time to change all the switch occurances, scripts, notifications etc according to my switch naming.
I also got into installing lovelace-ui addons, which was a first for me (friendly tip: make a list of the 4 ui addons and weather services required so that the new users know what they’re missing - unless you already have it somehwere and i missed it :slight_smile: )

I some questions if you would be kind enough to help me out:

  • Could you please explain to me how the weather adjustment works? (I implemented darksky and smartweather and getting data in the history by excecuting the automation)
    How will the rainfall thershold affect my timers? will it set them to 0 if the real rain exceeds the threshold?
    How does it work with temperature? Im in a country that gets from minus to 45 celcius. Could you give me some pointers on how to adjust that?
    I noticed that the adjusted durations only change when i slide the temperature baseline. Are those numbers the actual timers or are they added to the durations set above?

  • One more thing i noticed, is i cant keep the “Enable Schedule” input booleans on after a restart. input_boolean.cycle1_enable and input_boolean.cycle2_enable switch off on every boot. Although they are both included in the recorder/history components both as domains and specifically as entities. Any ideas? (other booleans, like master control switch, are kept as they were before the reboot) I saw you automatically switch them off on shutdown. I commented out the code as i restart my HA every morning.

  • The big “play” icons on each cycle, are they supposed to change to “pause” when the cycle is running? If they are, that’s not working for me, if they aren’t, that’s a good idea for you to implement at some point :slight_smile:

  • Last but most difficult question: I would like to control two different machines in two different locations within one home assistant. Which means i would like to have a second tab to have an exact copy of the existing one but controlling 4 totally different valves, with different timers and schedule and in a different location (so different weather data). Is this possible? or would one need to re-write your whole code with different names?

Thanks in advance and keep up the great work :slight_smile: