EDIT: Whilst the script as given below is not correct, I now think my issue is the conditional delay.
I have found entries here on the forum that seem to imply it can’t be done without comparing times. i.e. compare the time the trigger occurs and the time it will be after the required delay.
That seems a bit cumbersome to me but I’ll work on that for now until I hear otherwise!
=====================================
Is it possible to have logic in a script?
I would like to cause a delay if an input_boolean
is ‘On’ and I would like that delay to be for the amount set in an input_number
. Else the delay should be 15 seconds.
To illustrate, this is what I have now but is only one of many attempts I have had at doing this.
irrigation_cycle:
alias: "Irrigation cycle"
sequence:
# Open valve
- service: homeassistant.turn_on
entity_id: switch.test_sonoff_basic
# If included in cycle, delay for 'zone 1 duration'
# else delay for 15 seconds
- service_template: >
{% if is_state('input_boolean.water_zone1', 'on') %}
delay: '00:{{ state('input_number.zone1_duration') }}:00'
{% else %}
delay: '00:00:15'
{% endif %}
# close valve
- service: homeassistant.turn_off
entity_id: switch.test_sonoff_basic
# delay for 15 seconds
- delay: '00:00:15'
(For clarity, input_number.zone1_duration is a number between 1 and 59 and there is intended to be a further delay of 15 seconds at the end)