Hi,
I’ve been looking at the notes on conditional script programming but haven’t found a specific example for what I need to do yet. It may be there, but it hasn’t jumped out at me, even using Google to scan the forums as suggested.
I have a fairly long script that manages lighting sequences when in Away mode. But the problem is if I return home before the last light turn on event then Vera fires that event even though I have changed from Away/Vacation mode to Home.
There is discussion about creating a virtual switch and using that for Home/Away, but that still leaves me wondering where I would drop in LUA code for this scene to prevent the lights on (or off I suppose) events from triggering.
The is mention about the main Tab for the scene or another spot but I only see one place to add code in my scene but again it is not clear that this would accomplish what I really need. Since it is only one spot in the scene editor would this really be able to prevent all of the events from being triggered. See the 2 questions for more details.
So two questions:
1 - Would I be better off splitting the scene into multiple ones that would fire at different times, in which case maybe that would solve my issue since in theory Vera should be in Home mode before the time for the event to fire? And if that didn’t work, e.g. Vera still thinks it should fire the event even after changing to Home mode before the time the even should fire, then perhaps I can add the conditional test to each of the individual scenes.
2 - Kind of related to my idea in #1 is it possible to read the Home/Away state and have LUA code that prevents the even from firing, or is the only way to do this is to use a virtual switch.
I’m thinking that splitting things into multiple scenes may be the best way to go, but if that is not the best approach then I’m open to suggestions.
If someone has done this same type of processing could you point me to a post that addresses this type of processing in a specific fashion.
Thanks in advance,
Burt
If your scenes use delayed actions to achieve the timing, there is no way to stop them. Once the scene is run (if permitted by any included Lua code), all the associated actions are queued - even the delayed ones. These will then happen regardless unless Vera restarts.
Solution number one: Implement your logic in PLEG. Instead of using delayed actions, use PLEG’s SelfTrigger interval timers (Schedules). In the Conditions that are triggered by the timers completing, you can check if you still need to run the actions. This effectively cancels the timers.
The is mention about the main Tab for the scene or another spot but I only see one place to add code in my scene but again it is not clear that this would accomplish what I really need. Since it is only one spot in the scene editor would this really be able to prevent all of the events from being triggered.
In UI5, each trigger can have its own Lua code. In UI7, this is not yet available but we have been told it is coming. Lua code in a scene’s main LUUP/Lua tab will permit or prevent a scene running regardless of the source of the trigger - including manual activation.
Would I be better off splitting the scene into multiple ones that would fire at different times, in which case maybe that would solve my issue since in theory Vera should be in Home mode before the time for the event to fire? And if that didn't work, e.g. Vera still thinks it should fire the event even after changing to Home mode before the time the even should fire, then perhaps I can add the conditional test to each of the individual scenes.
This is a better solution. It is the delayed actions that cause most problems of this nature. It is also possible to have one scene run another after a delay. The second scene could check whether it still needed to do something. Delayed action are explained in the Conditional Scene Execution thread.
Kind of related to my idea in #1 is it possible to read the Home/Away state and have LUA code that prevents the even from firing, or is the only way to do this is to use a virtual switch.
You can access the Home/Away/Night/Vaction state of the House Modes attribute. This is how:
local houseMode = luup.attr_get("Mode")
1 = Home
2 = Away
3 = Night
4 = Vacation
Thanks,
I kind of suspected that the delayed events were being queued.
And I’ve been running UI7 since that was what was on the device when I received it. So that explains why I only see one place to add LUA code.
I’ll look at PLEG.
Burt
I added some stuff to my response.
I would never discourage anybody from switching to PLEG. 
In PLEG you have a bypass or arm button on each one. So if you have a SET of conditions you don’t want to run when your home/away throw them in there and have your home and away set the bypass or arm accordingly to pause everything.