Good day everyone.
How can I use if and else in scrips? Using template service seems to be not enough.
Trying to make a script which would check if I woke up. Here is a part of algorithm which I have troubles with:
-check motion sensor 1:
If it is Off (for 10 min or more) - play a sound on media player(short one), Wait when motion will get On and then turn off media player. Timeout - 30 seconds. Go to the next step.
Else - go to the next step.
Actually, there is the same thing going over and over again. Just in case, here is full part of script which checks if I am awake
-alarm clock. Start the timer
-delay 30 seconds
-check motion sensor 1:
If it is Off (for 10 min or more) - play a sound on media player(short one), Wait when motion will get On and then turn off media player. Timeout - 30 seconds. Go to the next step
Else - go to the next step.
-delay 5 minutes
-check motion sensor 2:
If it is Off (for 15 min or more) - play a sound on media player (long one). Wait when motion will get On and then turn off media player. Timeout - 5 minutes. Go to the next step.
Else - go to the next step.
-timer is up
-check motion sensor 3:
If it is Off (for 6 minutes or more) - go to the next step
Else - stop the script
-check motion sensor 2:
If it is Off (for 6 minutes or more) - go to the next step
Else - stop the script
-check motion sensor 4:
If it is Off (for 6 minutes or more) - go to the next step
Else - stop the script
-check motion sensor 1:
If it is Off (for 6 minutes or more) - play a sound on a media player. Wait when motion2 will get On and then turn off media player. Then stop the script.
Else - stop the script
Hi, one small question here. I used delay at sixth point instead of timer finish. Now I have a timer and I am thinking witch way would be the best to go
Use an automation witch would trigger on event (timer is over)
Use wait template
I would like to use wait template because I have an automation which turns off this script if I leave home. But I do not know how to use event in wait template.
A delay says wait exactly this long and then continue.
A wait template says wait until this condition is true (you can’t test for events, but you could have another automation that triggers on the event, and sets the state of a boolean, say, and use the state of that).
A timer can be pause, reset, or left to run until it completes, and then the completion of the timer starts another automation (assuming you’ve set that up).
In my view:
delay is ideal when you want a fixed time between two actions
wait template is ideal when you want to wait until a condition is true (for instance, I use it for a notification to turn off an extractor after humidity drops to the right level)
timers are great where you want a delay, but with more flexibility