Wait for expression not working

I just don't get it. I've recreated this rule, used different conditionals different ways, and tried everything I know of but I can't get this simple rule to work. I've done more complex stuff, but this one keeps stumping me.

I have a door contact on the pantry door and a smart switch on the light. I want it to turn on if the door opens and turn off if the door closes. If the door is left open, I want it to wait five minutes and turn off. Done.

But.....Hubitat can't see that the light is on....or at least the rule can't see it. I re-did the rule this morning and put the wait for expression to 20 seconds for testing. Everything worked great. When I extended the duration to 5 minutes, it stops working again. The problem is the reporting. It turns the light on and then the rule thinks the light is off (see screenshot). When I go to the device page for the light, it shows current status: on, but the rule is showing it's off. Am I missing something simple?

The rule worked. I changed the duration, and now it doesn't. How would the duration change the current status of the light? The red line is where I changed the duration. Below worked with a 20 second wait. Above does not work. Please help!! I think I'm going crazy.


and further, I went back in right after the rule didn't work and shows it's waiting on the expression to become true, and the rule is showing that the light is on.

So rule shows it's on, device page shows it's on, log shows it's off and the wait for expression is false.
image

The logs in the first post do not match the rule in the second. Either way, you've likely induced a race condition that's part of your headache. Looking at the logs from the first post, the wait for expression appears to have been evaluated before the device status was updated to ON. I think I would just change that action to wait the 5 minutes and then turn off the light. The wait will be reset if the door is closed/opened and you won't have to worry about the expression being evaluated incorrectly.

Thanks for the reply!! I realized that after I posted the screen shot. You are correct. I opened the rule to add a delay thinking that it might need a few seconds to update the status. I added the delay, and then took the screenshot. The rule was the same (minus the delay). At that point, I hadn't hit "done" so it wouldn't have re-initialized yet.

Side note though, I'm assuming the race condition you mentioned is that the device status doesn't have time to update before the wait starts, so it sees it as off? I haven't heard that term, so I just wanted to make sure I understood. I've tested it with the delay inserted at one second and it seems to work now. I'm not sure why the wait duration would change that, but the delay seems to be allowing it time to realize the light is on.

My approach to writing this rule would be a little different. You might want to consider this:

Trigger Events
Pantry Door Contact opened

Actions to Run
On: Pantry Light
Wait for Event: Pantry Door Contact closed -->timeout: 0:05:00
Off: Pantry Light
1 Like

:point_up:

I started with that, or something similar. Tried to keep it very basic. I may end up going back to that.

When I started, the kids were bad about not closing the door. That works on the first time with the timeout. The second time when the door is still open and they physically turn the light on, then the rule doesn't trigger at all (even if they close the door).

At one point I had an extra trigger in there for if the light turns on and stays on for 5 minutes, but ended up removing it. At least if it hangs, we can push the door closed and it will turn off. I'm not opposed to simple and making them turn it off. :slight_smile:

@jaredeaves This updated trigger should work

Trigger Events
Pantry Door Contact open
OR
Pantry Light turns on
1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.