Skip to content

Commit

Permalink
Check for valid data. Add triggers & id: for trace
Browse files Browse the repository at this point in the history
  • Loading branch information
rgc99 committed May 23, 2022
1 parent ada4482 commit 3d1da35
Showing 1 changed file with 48 additions and 24 deletions.
72 changes: 48 additions & 24 deletions packages/irrigation_unlimited_adjustment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,46 @@ sensor:
# created above to generate a variation.
# Adjust rain_total_threshold, rain_rate_threshold and temperature_threshold variables to suit you needs.
automation:
- alias: Irrigation Unlimited Adjustment
- id: 'IU1653340123453'
alias: Irrigation Unlimited Adjustment
trigger:
platform: state
entity_id:
- sensor.irrigation_unlimited_rain_weighted_total
- sensor.irrigation_unlimited_temperature_5_day_moving_average
- sensor.wupws_preciprate
# -------------------------------------------------------------------
# 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
condition:
condition: and
conditions:
- "{{ states('sensor.irrigation_unlimited_rain_weighted_total') | float(-1) != -1 }}"
- "{{ states('sensor.wupws_preciprate') | 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_z1
# -------------------------------------------------------------------
# Please see documentation regarding the adjust_time service call.
# Choose an option below. Comment out/delete/change as needed.
# *** This will NOT work as is. ***
# 1. Adjust a single zone. Change the zone as required
# entity_id: binary_sensor.irrigation_unlimited_c1_z1
# 2. Adjust a sequence. Change the sequence_id as required
# entity_id: binary_sensor.irrigation_unlimited_c1_m
# sequence_id: 1
# -------------------------------------------------------------------
percentage: >
{# Threshold variables #}
{% set rain_total_threshold = 3.5 %}
Expand All @@ -170,22 +199,17 @@ automation:
{% set rain_rate = states('sensor.wupws_preciprate') | float(-1) %}
{% set temperature_average = states('sensor.irrigation_unlimited_temperature_5_day_moving_average') | float(-273) %}
{# Check if sensor data is valid #}
{% if rain_total != -1 and rain_rate != -1 and temperature_average and temperature_average != -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) }}
{# 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 %}
{{ 100 }}
{% set multiplier = 0.0 %} {# It's raining or enough already #}
{% endif %}
{# Return multiplier as a percentage #}
{{ (multiplier * 100) | round(0) }}

0 comments on commit 3d1da35

Please sign in to comment.