Delayed action with pre condition

I need help setting up a scene…
I have a relay controlling the power of my home’s ventilation system…
I’d like the system to turn off 2h after I left home but only when I’m still away…

I setup a scene that triggers when I’m switching to away using HouseMode Plugin.
The scene has a delayed action to turn off the ventilation after 2h and should run only when I’m in away mode.

My expectation is that the delayed action should check again whether I’m home, but so far it looks like this is checked only before running the full scene and not specific actions.

Does anyone have an idea how I could solve this problem?

That’s how scenes work. Their logic is processed instantly and they end. In your case, the scene runs, starts the 2 hour count down and ends. Nothing will stop that countdown except a Vera engine restart.

There is a way to accomplish your goal using Lua code in a scene, but it is somewhat complex. See: Conditional Scene Execution: Some Examples by @RexBeckett.

The other and relatively easier way is to use the Program Logic Event Generator(PLEG) plugin. You can replace your scene with a few simple PLEG conditions and get just what you want. @RexBeckett wrote a PLEG primer as well, PLEG Basics - An Introduction to the Program Logic Event Generator

If you want to do conditional at delayed time …
Then you want to run a second Scene 2 hours later.
That second scene could have some conditional logic in it to cancel the scene.

However, if Vera restarts during that two hours … that second scene will never run.

That’s one of the benefits of using PLEG. Timers work even if vera restarts.

Great, many thanks for the tips… Will try it out right away

You can do this with variables and such.

Scene starts and logic is processed (as stated). The scene shouldn’t “do” anything (immediately or delayed). Use LUA code to affect what you want like this:

[code]luup.call_delay (“eval_HVAC”, xxx, “”)

function eval_HVAC (empty)
local mode = luup.attr_get “Mode”
if (mode == “2”) then
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },<device_id>)
return (true)[/code]

Or something reasonably close to that. Change xxx to the number of seconds you want it to ‘sleep’ for (7200 for two hours). Keep in mind that you can’t stop the delay or timer. So, if you leave, come back in an hour, and leave again, it will still shut down two hours after the FIRST time you left.

Or use the countdown timer plugin. You start it when you leave with a 2 hour countdown. Then at expiry, it triggers another scene that checks to see if you are still away before doing the action. Note that the countdown timer can be reset as well, so you can instead trigger on the change to home to stop the timer. My understanding is that the count down timer will survive a lua restart (can anyone confirm?), but the luup.call_delay will not.

Or use PLEG as mentioned.

Yes the Countdown Timer WILL survive a LUA restart.
Enhancing the Coundown Timer and Combination Switch plugins where part of my motivation for PLTS and later PLEG.