My problem: After using home_assistant.turn_off on a script that is queued, I cannot run the script again, it is queued but does not run.
Background:
I am automating a 10 zone sprinkler system. script.run_irrigation_zone turns off all zones, turns on one zone, delays X minutes, then turns off all zones. To run a sequence of zones, I have an automation that invokes run_irrigation_zone for each of the zones. run_irrigation_zone is queued. The queueing makes it easy for me to add extra watering at the end of the automation. Sometimes I want to cancel an irrigation program that is running, including queued zones. For this, script.cancel_irrigation does a homeassistant.turn_off on script.run_irrigation_zone, and turns off all zones. script.cancel_irrigation successfully stops the irrigation and removes all queued invocations for the zones. I have verified this by examining state in developer tools. If I cancel and then try to run an automation that runs zones, they do not start. In developer tools I see current go to 10 for script.run_irrigation_zone, so it looks like they are queued, but never start. By accident, I discovered that if I edit and save any script in the UI, then it will cancel all the queued invocations. After that, I can run an automation that runs the irrigation zones. That is the behavior I want. It seems like homeassistant.turn_off leaves queued scripts in a bad state, or I am missing an extra step to re-enable the script after using homeassistant.turn_off
I use the docker container and see the same behavior with latest (core-2021.7.4) and stable.
The forum had several discussions of cancelling scripts and automations, and they recommended using homeassistant.turn_off. I cannot find any discussion specific to cancelling queued scripts.
Here is the script for running a zone:
run_irrigation_zone:
alias: Run Irrigation Zone
sequence:
- service: script.turn_off_irrigation
- service: switch.turn_on
target:
entity_id: '{{ zone }}'
- delay:
hours: 0
minutes: '{{ minutes }}'
seconds: 0
milliseconds: 0
- service: script.turn_off_irrigation
mode: queued
icon: hass:water
max: 100
Here is the script for cancelling:
cancel_irrigation:
alias: Cancel Irrigation
sequence:
- service: homeassistant.turn_off
entity_id: script.run_irrigation_zone
- service: script.turn_off_irrigation
mode: single
icon: hass:water
And here is how I turn off zones:
turn_off_irrigation:
alias: Turn Off Irrigation Zones
sequence:
- service: switch.turn_off
target:
entity_id: group.Irrigation
mode: single
icon: hass:water
Here is how I use an automation to run 3 zones:
- id: '1622121450319'
alias: 'Lawn Watering: Morning'
description: ''
trigger:
- platform: sun
event: sunrise
offset: '- 1:0:0'
condition: []
action:
- service: script.turn_on
target:
entity_id: script.run_irrigation_zone
data:
variables:
zone: switch.irrigation_rear_woods
minutes: 20
interval: 4
- service: script.turn_on
target:
entity_id: script.run_irrigation_zone
data:
variables:
zone: switch.irrigation_rear_fence
minutes: 20
interval: 3
- service: script.turn_on
target:
entity_id: script.run_irrigation_zone
data:
variables:
zone: switch.irrigation_right_side
minutes: 20
interval: 3