rgc99 / irrigation_unlimited

♒Irrigation controller for Home Assistant
MIT License
331 stars 49 forks source link

Next cycle not working #84

Closed bsmith76s closed 2 years ago

bsmith76s commented 2 years ago

I have deleted and reloaded the integration multiple times. I've tried to only use the bare minimum configuration and it will not calculate the next cycle. here is a link to pic showing the next cycle not being calculated. This all worked last year and worked up until 2 days ago.

https://imgur.com/a/IkIITsK

Version of the custom_component

I have tried 2022.6 and the master -->

Configuration

irrigation_unlimited:
  controllers:
    entity_id: "input_boolean.garden_irrigation"
  #  enabled: true
    zones:
      - name: "Tomato Garden"
        entity_id: "switch.tasmota_garden_1"
      - name: "Bean Patch"
        entity_id: "switch.tasmota_garden_2"
      - name: "Lettuce Patch"
        entity_id: "switch.tasmota_garden_3"
      - name: "Zucchini Patch"
        entity_id: "switch.tasmota_garden_4" 
    sequences:
      - name: "Morning Spring and Autumn"
        duration: "00:10"
        delay: "00:00"
        repeat: 3
        schedules:
          - name: "Sunrise"
            time:
              sun: "sunrise"
              before: "01:30"
            month: [jun, jul, aug, sep, oct]
        zones:
          - zone_id: 1
          - zone_id: 2
            duration: "00:06"
          - zone_id: 3
            duration: "00:07"
          - zone_id: 4
            duration: "00:07"
    #  - name: "Mid Day Summer"
      #  duration: "00:10"
      #  delay: "00:05"
      #  repeat: 3
      #  schedules:
        #  - name: "Mid-day"
          #  time: "12:15"
          #  month: [jun, jul, aug]
      #  zones:
        #  - zone_id: 1
        #  - zone_id: 3
      - name: "Evening Spring and Autumn"
        duration: "00:10"
        delay: "00:00"
        repeat: 3
        schedules:
          - name: "Before sunset"
            time:
              sun: "sunset"
              before: "03:15"
            month: [jun, jul, aug, sep, oct]
        zones:
          - zone_id: 1
            # duration: "00:08"
          - zone_id: 2
            duration: "00:06"
          - zone_id: 3
            duration: "00:07"
          - zone_id: 4
            duration: "00:07"

Add your logs here.


## Describe the bug
The have deleted and reloaded the integration multiple times. I've tried to only use the bare minimum configuration and it will not calculated the next cycle. I see the logs say "does not match the unit of already compiled statistics (in)" but I have used all converted sensors in the configurations to metric. Should I switch the home assistant units to metric instead of imperial? This all worked last year on older version and worked up until 2 days ago. Now it will not calculate next cycle time.

## Debug log

<!-- To enable debug logs check this https://www.home-assistant.io/components/logger/ -->

```{
  "trace": {
    "last_step": "action/0",
    "run_id": "050b411933a401563fd1112b1fc07a35",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2022-07-07T01:18:56.887509+00:00",
      "finish": "2022-07-07T01:18:56.918644+00:00"
    },
    "domain": "automation",
    "item_id": "IU1653340123453",
    "trigger": "state of sensor.rain_rate_median_over_last_8_hours",
    "trace": {
      "trigger/1": [
        {
          "path": "trigger/1",
          "timestamp": "2022-07-07T01:18:56.887640+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.irrigation_unlimited_adjustment",
              "state": "on",
              "attributes": {
                "last_triggered": "2022-07-07T01:18:15.620863+00:00",
                "mode": "single",
                "current": 0,
                "id": "IU1653340123453",
                "friendly_name": "Irrigation Unlimited Adjustment"
              },
              "last_changed": "2022-07-07T01:17:25.460223+00:00",
              "last_updated": "2022-07-07T01:18:15.672375+00:00",
              "context": {
                "id": "01G7B3RXJ2VN55D97FW8KHTGGC",
                "parent_id": "01G7B3RXHHAMGN0PWQTVPKWKF9",
                "user_id": null
              }
            },
            "trigger": {
              "id": "1",
              "idx": "1",
              "platform": "state",
              "entity_id": "sensor.rain_rate_median_over_last_8_hours",
              "from_state": {
                "entity_id": "sensor.rain_rate_median_over_last_8_hours",
                "state": "6.86",
                "attributes": {
                  "state_class": "measurement",
                  "age_coverage_ratio": 0.79,
                  "buffer_usage_ratio": 0.05,
                  "source_value_valid": true,
                  "unit_of_measurement": "mm/hr",
                  "icon": "mdi:calculator",
                  "friendly_name": "Rain Rate Median over last 8 hours"
                },
                "last_changed": "2022-07-07T01:18:12.898109+00:00",
                "last_updated": "2022-07-07T01:18:12.898109+00:00",
                "context": {
                  "id": "01G7B3RTX2YC5YT2721HV64WMS",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "sensor.rain_rate_median_over_last_8_hours",
                "state": "6.1",
                "attributes": {
                  "state_class": "measurement",
                  "age_coverage_ratio": 0.79,
                  "buffer_usage_ratio": 0.05,
                  "source_value_valid": true,
                  "unit_of_measurement": "mm/hr",
                  "icon": "mdi:calculator",
                  "friendly_name": "Rain Rate Median over last 8 hours"
                },
                "last_changed": "2022-07-07T01:18:56.876500+00:00",
                "last_updated": "2022-07-07T01:18:56.876500+00:00",
                "context": {
                  "id": "01G7B3T5VCY223J9KVKHN1N7A7",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": null,
              "attribute": null,
              "description": "state of sensor.rain_rate_median_over_last_8_hours"
            }
          }
        }
      ],
      "condition/0": [
        {
          "path": "condition/0",
          "timestamp": "2022-07-07T01:18:56.887756+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "condition/0/conditions/0": [
        {
          "path": "condition/0/conditions/0",
          "timestamp": "2022-07-07T01:18:56.887831+00:00",
          "result": {
            "result": true,
            "entities": [
              "sensor.irrigation_unlimited_rain_weighted_total"
            ]
          }
        }
      ],
      "condition/0/conditions/1": [
        {
          "path": "condition/0/conditions/1",
          "timestamp": "2022-07-07T01:18:56.888557+00:00",
          "result": {
            "result": true,
            "entities": [
              "sensor.rain_rate_median_over_last_8_hours"
            ]
          }
        }
      ],
      "condition/0/conditions/2": [
        {
          "path": "condition/0/conditions/2",
          "timestamp": "2022-07-07T01:18:56.889115+00:00",
          "result": {
            "result": true,
            "entities": [
              "sensor.irrigation_unlimited_temperature_5_day_moving_average"
            ]
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2022-07-07T01:18:56.901213+00:00",
          "changed_variables": {
            "context": {
              "id": "01G7B3T5VQPP36802ETTYY7GAV",
              "parent_id": "01G7B3T5VCY223J9KVKHN1N7A7",
              "user_id": null
            }
          },
          "result": {
            "params": {
              "domain": "irrigation_unlimited",
              "service": "adjust_time",
              "service_data": {
                "entity_id": "binary_sensor.irrigation_unlimited_c1_m",
                "zones": 0,
                "percentage": 0
              },
              "target": {}
            },
            "running_script": false,
            "limit": 10
          }
        }
      ]
    },
    "config": {
      "id": "IU1653340123453",
      "alias": "Irrigation Unlimited Adjustment",
      "trigger": [
        {
          "platform": "time",
          "at": "02:00"
        },
        {
          "platform": "state",
          "entity_id": [
            "sensor.irrigation_unlimited_rain_weighted_total",
            "sensor.irrigation_unlimited_temperature_5_day_moving_average",
            "sensor.rain_rate_median_over_last_8_hours"
          ]
        }
      ],
      "condition": {
        "condition": "and",
        "conditions": [
          "{{ states('sensor.irrigation_unlimited_rain_weighted_total') | float(-1) != -1 }}",
          "{{ states('sensor.rain_rate_median_over_last_8_hours') | float(-1) != -1 }}",
          "{{ states('sensor.irrigation_unlimited_temperature_5_day_moving_average') | float(-273) != -273 }}"
        ]
      },
      "action": {
        "service": "irrigation_unlimited.adjust_time",
        "data": {
          "entity_id": "binary_sensor.irrigation_unlimited_c1_m",
          "zones": 0,
          "percentage": "{

Add your logs here.

Logger: homeassistant.components.sensor.recorder
Source: components/sensor/recorder.py:492
Integration: Sensor (documentation, issues)
First occurred: 9:20:10 PM (6 occurrences)
Last logged: 9:20:10 PM

The unit of sensor.irrigation_unlimited_rain_1 (mm) does not match the unit of already compiled statistics (in). Generation of long term statistics will be suppressed unless the unit changes back to in. Go to https://my.home-assistant.io/redirect/developer_statistics to fix this
The unit of sensor.irrigation_unlimited_rain_2 (mm) does not match the unit of already compiled statistics (in). Generation of long term statistics will be suppressed unless the unit changes back to in. Go to https://my.home-assistant.io/redirect/developer_statistics to fix this
The unit of sensor.irrigation_unlimited_rain_3 (mm) does not match the unit of already compiled statistics (in). Generation of long term statistics will be suppressed unless the unit changes back to in. Go to https://my.home-assistant.io/redirect/developer_statistics to fix this
The unit of sensor.irrigation_unlimited_rain_4 (mm) does not match the unit of already compiled statistics (in). Generation of long term statistics will be suppressed unless the unit changes back to in. Go to https://my.home-assistant.io/redirect/developer_statistics to fix this
rgc99 commented 2 years ago

Let's unpack this.

The adjustment is being set to 0% which in turn will make the duration 0. If you believe the adjustment is not correct then take the last part of the automation from the line below percentage: > and paste into Developer Tools -> TEMPLATE. This will allow you to work through the calculations. The calculations on my system yield 0 because it has been raining a lot recently.

          {# Threshold variables #}
          {% set rain_total_threshold = 3.5 %}
          {% set rain_rate_threshold = 1.0 %}
          {% set temperature_threshold = 20.0 %}
          {# Sensor data #}
          {% set rain_total = states('sensor.irrigation_unlimited_rain_weighted_total') | float(-1) %}
          {% set rain_rate = states('sensor.wupws_preciprate') | float(-1) %}
          {% set temperature_average = states('sensor.irrigation_unlimited_temperature_5_day_moving_average') | float(-273) %}
          {# Threshold variables #}
          {% set rain_multiplier = (1 - (rain_total / rain_total_threshold)) %}
          {% set temperature_multiplier = temperature_average / temperature_threshold %}
          {% set multiplier = 1.0 %}
          {% if rain_rate < rain_rate_threshold and rain_multiplier > 0 and rain_total < rain_total_threshold %}
            {% set multiplier = multiplier * temperature_multiplier %}
            {% set multiplier = multiplier * rain_multiplier %}
          {% else %}
            {% set multiplier = 0.0 %} {# It's raining or enough already #}
          {% endif %}
          {# Return multiplier as a percentage #}
          {{ (multiplier * 100) | round(0) }}

Because the adjustment is 0 there really is no future schedule. In the past it would show the next event even though it had a zero duration. This is actually not correct and misleading as nothing will happen. The code was altered to show the next event that has a duration > 0 and activate something. In this situation there is no future event.

At the moment you are adjusting all of the zones which is fine. There are other options to adjust sequences or sequence zones. No right or wrong just flexibility.

bsmith76s commented 2 years ago

Thanks for explaining how the new way of calculating the adjustment works and code shows the next cycle event. I will not close this until it stops raining and I see it is working correctly.

Also does the irrigation_unlimited_smart_irrigation.yaml only need added to packages folder if using jeroenterheerdt/HAsmartirrigation automation? Also do I just set the entitiy_id to the main control to do all zones or do I add zones: 0 to irrigation_unlimited_smart_irrigation.yaml like in my irrigation_unlimited_adjustment.yaml?

Sorry for all the questions but I am trying to wrap my head around this. Last year I think I used the HAsmartirrigation automation but I am unsure. I have changed so many things in Home Assistant over last year I just don't recall. This integration is great and thank you for all your work on it and help.

rgc99 commented 2 years ago

You only need irrigation_unlimited_smart_irrigation.yaml if using HAsmartirrigation. It was recently updated to check it was installed and configured, caused problems otherwise.

There are two basic areas; zones and sequences.

Zones The entity_id: can either be the zone i.e. ...c1_z1 or the controller ...c1_m along with the zones: parameter. It doesn't matter which as it all ends up at the same place. The zones parameter can be 0 in which it just loops through all the zones. Can also be a list like [1,3,5].

Sequences The entity_id: must be the controller. Leave the zones parameter out and use the sequence_id: parameter.

For an in-depth dive there is a section in the documentation at service call access roadmap

Hope this helps.

bsmith76s commented 2 years ago

Everything seems to be working good now. I have adjusted some of the values in the adjustment.yaml for better need in my garden. thank you again for your help.

bsmith76s commented 2 years ago

I did not want to open another issue because I have a question about the adjustment.yaml. I could not find a way to send you a message. in the adjustment.yaml in the automation section there are 3 way to trigger. you mention comment and uncomment as needed.

automation:
  - id: 'IU1653340123453'
    alias: Irrigation Unlimited Adjustment
    trigger:
      # -------------------------------------------------------------------
      # Choose how you want to trigger this automation.
      # Comment out/delete/change as required.
      # -------------------------------------------------------------------
      # Run at a fixed time
      - platform: time
        at: "02:00"
      # Run when Home Assistant starts
      - platform: homeassistant
        event: start
      # Run when the sensors update. Don't use this option if any of your
      # schedules use the 'anchor: finish'. It will most likely cause the
      # system to skip. Use a fixed time.
      - platform: state
        entity_id:
          - sensor.irrigation_unlimited_rain_weighted_total
          - sensor.irrigation_unlimited_temperature_5_day_moving_average
          - sensor.wupws_preciprate

can you use more than 1 trigger or is only 1 trigger is allowed? I have all uncommented at the moment but the adjustment does not seem to change unless I restart Home Assistant then the adjustment is calculated. I would like to just use when sensors update and at a certain time. Any help would be great. Thank you.

rgc99 commented 2 years ago

You can have multiple triggers. At the moment the automation will trigger on HA startup, at 02:00 or when any of the three entities listed change state. For just time and sensor update then comment out the HA startup bit. Does the automation not trigger or does the adjustment not appear?

automation:
  - id: 'IU1653340123453'
    alias: Irrigation Unlimited Adjustment
    trigger:
      # -------------------------------------------------------------------
      # Choose how you want to trigger this automation.
      # Comment out/delete/change as required.
      # -------------------------------------------------------------------
      # Run at a fixed time
      - platform: time
        at: "02:00"
      # Run when Home Assistant starts
      # - platform: homeassistant
      #   event: start
      # Run when the sensors update. Don't use this option if any of your
      # schedules use the 'anchor: finish'. It will most likely cause the
      # system to skip. Use a fixed time.
      - platform: state
        entity_id:
          - sensor.irrigation_unlimited_rain_weighted_total
          - sensor.irrigation_unlimited_temperature_5_day_moving_average
          - sensor.wupws_preciprate
bsmith76s commented 2 years ago

The adjustment is showing but has been at 42% for days have not had any rain for over a week so I would think it would be back to 100%.

rgc99 commented 2 years ago

If you haven't already, turn on debug logging. Add this to the configuration and restart.

logger:
  default: info
  logs:
    custom_components.irrigation_unlimited: debug

Go to Settings -> System -> Logs -> LOAD FULL LOG. Put in 'irrigation_unlimited' into the 'search logs' box. You should see all the key information and service calls. For example:

2022-07-22 16:15:35 DEBUG (MainThread) [custom_components.irrigation_unlimited] CALL [2022-07-22 16:15:35] service: adjust_time, controller: 1, zone: 8, data: {"entity_id": "binary_sensor.irrigation_unlimited_c1_z8", "actual": "13:38:19"}

If you know your way around linux then try grep custom_components.irrigation_unlimited home-assistant.log. Install terminal in Settings -> Add-ons -> Terminal & SSH is pretty handy.

If you are not seeing these CALL messages then the automation is not working. If you do see them please post them here.

bsmith76s commented 2 years ago

here are 2 CALL's that happened during a rain event

2022-07-25 10:30:09 DEBUG (MainThread) [custom_components.irrigation_unlimited] CALL [2022-07-25 10:29:00] service: adjust_time, controller: 1, zone: 0, data: {"entity_id": "binary_sensor.irrigation_unlimited_c1_m", "zones": [0], "percentage": 22.0}

2022-07-25 11:33:00 DEBUG (MainThread) [custom_components.irrigation_unlimited] CALL [2022-07-25 11:32:00] service: adjust_time, controller: 1, zone: 0, data: {"entity_id": "binary_sensor.irrigation_unlimited_c1_m", "zones": [0], "percentage": 0.0}

there is no CALL for the platform time for 2 days. it should show a CALL at 3:00AM but for last 2 days thelog shows nothing. After a home assistant restart debug logger shows the CALL to the adjustment. here is the CALL after restart

2022-07-26 12:29:44 DEBUG (MainThread) [custom_components.irrigation_unlimited] CALL [2022-07-26 12:29:00] service: adjust_time, controller: 1, zone: 0, data: {"entity_id": "binary_sensor.irrigation_unlimited_c1_m", "zones": [0], "percentage": 24.0}

do you think the double quotes around the desired time for platform in the adjustment.yaml should be single quotes? I changed the desired time to single quotes and will see if this makes a difference tomorrow.

rgc99 commented 2 years ago

That's what I would expect. The adjustment went from 22% to 0 at the start of the rain event. Duplicate calls are ignored so setting the same adjustment will not be recorded. Some sensors update every 30 seconds even though the information has not changed. In these cases the call is just let go through to the keeper. You can still see if the automation fired from Settings -> Automations and click on 'Debug automation'.

You can use single or double quotes, no difference.

rgc99 commented 2 years ago

Assume all is working ok now.