Page 1 of 1

Evaluate conditions after a delay.

PostPosted: Wed Jul 10, 2019 7:53 am
by berkinet
I have the following situation: Light A is controlled by a contractor (basically a bi-stable latching relay). Each time the contractor is pulsed it changes state (toggles) between On and Off. The contractor is actually two switches in one. Switch 1 controls light A while switch 2 controls connects to a digital input (DI) on an I/O board that is visible to Indigo. Indigo can also control a relay on the I/O board to operate the contractor. Thus, I can control the contractor, and the connected light, by local push-buttons or via Indigo, and Indigo knows the state of the contractor, and by extension, the light. All of this works well and is the basis for a Virtual Device in Indigo.

I also have a trigger that looks for my gate to open and will then turn on light A. A condition in the trigger requires the contractor be Off for the action to take place. Otherwise, if light A were on when the gate opened, it would be turned off (toggled). All good so far. However, I want light A to turn off 10 minutes after the gate opens. I can configure trigger to auto-off after 10 minutes (or add a second a action to do that after a delay of 10 minutes). The problem is if someone has manually turned light A during the 10 minute period, the trigger will actually turn it back on (since light A is only a toggle with no specific On/Off state). So, I only want the trigger to toggle light A if it is already On.

My solution was to add a second action to my trigger, with a delay of 10 minutes. This action sets a variable to True. I then have a second trigger keyed to that variable, with the condition that Light A be on, and one action to toggle light and a second action to set the variable to False. I effectively push the condition check out 10 minutes. This all works.

My question is, is there a more direct way to do this? Allowing Triggers to define conditions for each of multiple actions (evaluated at execution time) would address the issue, as would allowing Action Groups to have conditions. However, I am not sure either idea would really benefit Indigo and might add more confusion than help. Another approach might be to build a seemingly stateful Virtual Device front end for something that is truly only a toggle. So, it it were set to On, it would first check the current state and then only operate if it were currently Off. This could probably be done by embedding code in the Virtual Device's Action Groups. But, it seems like it would end up being more complex than my current solution.

So, has anyone else dealt with a situation like this? Or does someone have some thoughts, comments or ideas on the topic?

Re: Evaluate conditions after a delay.

PostPosted: Thu Jul 11, 2019 4:20 am
by berkinet
For anyone else who has this issue, I decided to make my toggle device stateful. All I had to do was execute a Python script in the ON and OFF Action Groups called by the Virtual Device. The script checks the current status of the device and if that matches the desires state (on or off) it just exits. Otherwise, it executes the Toggle Action Group. Here is the script I used for the On action:
Code: Select all
toggleDeviceState = <ID Number of status Variable as defined in the Virtual Device>
indigoActionGroup = <ID Number of the Toggle Group as defined in the Virtual device>
var = indigo.variables[toggleDeviceState]
# add "not" in the On Action and delete it in the Off Action
if not var.getValue(bool):
    indigo.actionGroup.execute(indigoActionGroup)

Re: Evaluate conditions after a delay.

PostPosted: Sat Jul 13, 2019 9:14 am
by matt (support)
Yeah, I probably would have taken a similar approach. I have a few cases where I've added action execution level logic/conditionals by executing embedded python scripts similar to what you've done. Having UI to attach conditionals to actions would solve the problem too of course, but that would be a pretty large feature. :twisted: