I have an atomation that triggers fine and the script loops, but it will never stop and I cant figure out why. I would like the automation immediately go further and turn off the script when someone is home or boolean is turned off or time reaches 23:00.
I am a beginner and using UI. What am I doing wrong?
But if someone comes home I would like the script to stop too (condition: or), that is not working right now. I have other automations using home/not home with numeric states, that works fine. Must be something with this repeatition action?
I have tested in Developer Tools, so far it looks correct! Have to see tomorrow if my automation works as intended. Will come back!
I can understand the confusion about zone and input_boolean. Zone is what it sounds like, boolean is a button in Lovelace to be able to cancel the automation manually, even if zone is not_home.
At first look, I don’t see anything wrong with your script snippet. The indentation is fine. And it should work as-is, although it doesn’t hurt to convert to a single template condition if you prefer.
You show the trace summary, but what does it show under “Step Details”, etc.? Are there any clues there as to how it is evaluating the conditions? I tried a quick test with a single input_boolean (and the script just had one step which was a delay.) The trace shows, e.g.:
Iteration 1
Executed: January 17, 2023 at 1:57:22 PM
Result:
delay: 5
done: true
Iteration 2
Executed: January 17, 2023 at 1:57:27 PM
Result:
delay: 5
done: true
Iteration 1
Executed: January 17, 2023 at 1:57:27 PM
Result:
result: false
Iteration 2
Executed: January 17, 2023 at 1:57:32 PM
Result:
result: true
Iteration 1
Executed: January 17, 2023 at 1:57:27 PM
Result:
result: false
Iteration 2
Executed: January 17, 2023 at 1:57:32 PM
Result:
result: true
ditions/0
Iteration 1
Executed: January 17, 2023 at 1:57:27 PM
Result:
result: false
ditions/0
Iteration 2
Executed: January 17, 2023 at 1:57:32 PM
Result:
result: true
ditions/0/entity_id/0
Iteration 1
Executed: January 17, 2023 at 1:57:27 PM
Result:
result: false
state: 'on'
wanted_state: 'off'
ditions/0/entity_id/0
Iteration 2
Executed: January 17, 2023 at 1:57:32 PM
Result:
result: true
state: 'off'
wanted_state: 'off'
You can see at the end it is indicating how it is evaluating the state condition.
Note that the conditions you show in the repeat-until step only get evaluated and the end of each execution of the sequence, which, in this case, is each time script.not_homefinishes.
Do you really want to wait until script.not_home completes before checking the conditions that should stop it?
I would like the script to be canceled directly when any of the conditions are met. The script is about 30 min - 1 hour (using random pauses). Maybe this is the case?
Earlier I had the script sequence directly in the automation instead, anyway the problem was the same.
Some workaround to cancel the repetition directly when any condition are met, if that is the problem? I haven’t been able to test the template suggested above yet, but I guess it will not work anyway then.
Hmm, wait a second. Looking back at your script snippet, it does NOT wait for script.not_home to complete. Rather, it immediately checks the conditions, and then callsscript.not_homeagain if none of the conditions are true!
What mode is script.not_home? If the default single, then you’re probably getting a lot of warnings that the script is already running? Or maybe you’ve already addressed that???
Note that whether or not the calling automation/script waits for the called script to finish before continuing itself depends on how the script is called. See Waiting for script to complete.
I’m not exactly sure how what you’ve shown fits in with the rest of your system, but one thing you might try is to add a “repeat while true” loop inside script.not_home. E.g.,
not_home:
sequence:
- repeat:
while: "{{ true }}"
sequence:
# All the steps it performed before go here
- ...
Now when the script is started it will run forever, or until it is stopped.
Like you said, it calls the script without waiting for it to complete. The script apparently takes 30-60 minutes to complete. There’s no delay within the repeat so it’s free to repeatedly call the script quite a few times!
I’m also curious to know what is the script’s mode. If it’s the default then, like you said, there are probably a lot of warnings (unless if, of course, they set it to silent).