Learning to use Async


#1

I’m trying to learn the proper use of Async. Currently, when I come home, lights turn on for a few minutes and then turn off, and my mode is set.

If presence=home
only when mode=away-night
turn on lights
wait 5 minutes
turn off lights
end when
if other conditions
set mode home-night
end if
end if

This isn’t my real code, but it gets the idea across. I want to wait the 5 minutes to turn off the light, but I don’t want to wait 5 minutes to change the mode. To make this change, would I put the Async on the block to turn on the lights, or the block to set the home?


#2

This sounds illogical to me. How can you be home and away at the same time?!?


Why not something like this:

IF Presence changes to Home
Then
    Turn on lights
        IF other conditions
        Then
            Set mode to home-night
        END IF
    Wait 5 minutes
    Turn off lights
END IF

No need for ASYNC


#3

That kind of defeats the purpose of learning how to use async. :stuck_out_tongue_winking_eye:

Bad pseudocode. I am triggering on presence change. If I didn’t want to change the code - to learn to get comfortable with async - which block would that go on?


#4

I see your predicament… LOL

In my experience, 99.8% of the time I am able to code without using ASYNC. There may come a time when you need it, but trying to force ASYNC is not a path that I will recommend.
(I usually recommend replacing ASYNC with more streamlined code)

The best advice is to think of each trigger as running thru the entire piston from top to bottom.

Adding ASYNC changes that, and you run a higher possibility of commands not always reaching their destination