Variables not set immediately (trigger insert state)

Posted on
Sun Apr 17, 2016 2:47 am
ydcl offline
Posts: 4
Joined: Apr 15, 2016

Variables not set immediately (trigger insert state)

Hi.
I'm new to Indigo.
I've Z-Wave device values I can't access directly in AppleScript in triggers (as stated in documentation).
So, I have 2 actions in a trigger, in that order :
- an insert state ('sensor value') into an indigo variable
- an applescript which uses that variable.

But, the variable is not set in the script with the new value : I have to delay the script by 1s (the minimum) to see the variable set
I tried a delay of 0, but it doesn't work.
A delay in the script itself does not work either.
Same result when I tried the same script in an action group called by the trigger (instead of script directly in the trigger).
I just thought the first action (copy) should be (fully) terminated when the second would start.

The annoying thing is that when the script is delayed, the 'current trigger name' is set to "" (or not set without error), instead of the correct name (it is OK when not delayed, directly in the trigger or in the action group).

Am I missing something ?

Posted on
Sun Apr 17, 2016 4:48 am
ydcl offline
Posts: 4
Joined: Apr 15, 2016

Re: Variables not set immediately (trigger insert state)

I add :

I tried with 2 triggers :
- first for the device : copy to the variable
- second for the variable : my AppleScript.

The problem : we can not trigger a variable when assign the same value as the previous value (any value).
For Z-Wave, we have 'Z-Wave Event', which triggers all.

What I want to do is to detect every message from the (Z-wave) device, even if no change :
- get the new value, if any, of course
- ensure that the device is still 'alive' : it is not rare I loss messages (often for X10, but sometimes with Z-Wave)

Posted on
Mon Apr 18, 2016 10:41 am
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Variables not set immediately (trigger insert state)

The variable trigger you're using is a change trigger. Since the value of the variable isn't changed, the trigger doesn't fire. Same with a device state changed trigger.

You can try a Z-Wave Event->Z-Wave Command Received trigger type and specify any command. That may fire any time any message is received from the Z-Wave device.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Apr 18, 2016 12:00 pm
ydcl offline
Posts: 4
Joined: Apr 15, 2016

Re: Variables not set immediately (trigger insert state)

That's I've done, of course.
May be I'm not clear enough (sorry for my English).

Trigger On Zwave command
2 actions (in that order) :
- copy the sensor value to indigo variable
- AppleScript uses that indigo variable

When the AppleScript is called with no delay, the new value is not in the indigo variable.
When the AppleScript is called with delay, the new value is in the indigo variable.


Since this question/remark, I've tested with Python (I am not used to) (indeed of the AppleScript).
I've got the same behavior, the variable is not set.
But I can access to the device value directly, the value is correct.
(For personal purpose, I have to send it with an AppleEvent, and it is so easy from Python).


The Python Script :
myDev = indigo.devices[1159781392] # "Cuis - Temperature"
myDevVal = myDev.sensorValue
indigo.server.log(str(myDevVal)) # dev value
myVar = indigo.variables[751674025] # "CuisTemperature"
myVarVal = myVar.value
indigo.server.log(str(myVarVal)) # var value


So, in log, so the dev value first, the var value second :

18 avr. 2016 19:12:06
Z-Wave received "Cuis - Temperature" sensor update to 19.3 °C
Trigger Cuis Temperature changes (d+v)
Script 19.3 -> dev correct
Script 19.2 -> var not correct, not updated

The variable is not set.


If I delay the PythonScript by 1s, the variable is set.
(in the log, all the value are same, but new)

8 avr. 2016 19:24:11
Z-Wave received "Cuis - Temperature" sensor update to 19.4 °C
Trigger Cuis Temperature (d+v)
Schedule Cuis Temperature (d+v) (delayed action)
Script 19.4
Script 19.4


I duplicated the Python Script (2 same scripts in trigger) : both script with no delay.

Z-Wave received "Cuis - Temperature" sensor update to 19.3 °C
Trigger Cuis Temperature (d+v)
Script 19.3 -> dev correct
Script 19.4 -> var not updated
Script 19.3 -> dev still correct (of course)
Script 19.3 -> var updated !!!

The second one works as expected !
That seems to confirm that we have to wait (delay) to have the variable set.
Are you sure the process to update the variable is fully completed when the script begins ?
Or are you starting the script while the variable update process is just lunched (and not completed) ?

Posted on
Mon Apr 18, 2016 12:08 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Variables not set immediately (trigger insert state)

Ah - yes, I see. Actions are run in parallel as much as possible, so the update to the variable happens at the same time the script is running. So it's getting the old value rather than the new. If you need the new value, then you would want to delay as you've seen.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Apr 18, 2016 12:40 pm
ydcl offline
Posts: 4
Joined: Apr 15, 2016

[ANSWERED]Variables not set immediately (trigger insert stat

Thank you.

Posted on
Sun Oct 08, 2017 12:06 pm
Umtauscher offline
User avatar
Posts: 566
Joined: Oct 03, 2014
Location: Cologne, Germany

Re: Variables not set immediately (trigger insert state)

I know this is an old thread, but how would I set actions to be executed in sequence?

I have an apple script that executes a curl command and I habe to make sure it went through before doing anything else.

Any ideas?
TIA
Wilhelm

Posted on
Sun Oct 08, 2017 12:50 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Variables not set immediately (trigger insert state)

The only way to sequence actions is to add delays to the start of the later ones.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sun Oct 08, 2017 1:11 pm
Umtauscher offline
User avatar
Posts: 566
Joined: Oct 03, 2014
Location: Cologne, Germany

Re: Variables not set immediately (trigger insert state)

I don't understand that. Why would I be able to move certain actions up and down in the list if it wouldn't change the sequence they are executed?

Posted on
Sun Oct 08, 2017 1:14 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Variables not set immediately (trigger insert state)

Umtauscher wrote:
I don't understand that. Why would I be able to move certain actions up and down in the list if it wouldn't change the sequence they are executed?


Actions using different interfaces can be run in parallel. Actions using the same interface (Z-Wave, Insteon, etc) are run in the order given. If all your actions are for the same device type, then the ordering is important.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sun Oct 08, 2017 1:26 pm
Umtauscher offline
User avatar
Posts: 566
Joined: Oct 03, 2014
Location: Cologne, Germany

Re: Variables not set immediately (trigger insert state)

Thanks for the explanation, but I am using scripts and plugins in that action. so they all run in parallel?

Posted on
Sun Oct 08, 2017 1:31 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Variables not set immediately (trigger insert state)

Umtauscher wrote:
Thanks for the explanation, but I am using scripts and plugins in that action. so they all run in parallel?


Actions for the same plugin would be run sequentially, I think. The rest in parallel. But I've never tested that exact scenario. Matt or Jay would have the definitive answer.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sun Oct 08, 2017 2:52 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Variables not set immediately (trigger insert state)

It depends. Indigo uses a lot of independent processes to both improve performance and to sandbox problems so that an error/hang in one area doesn't bring down the entire Indigo Server. That is one of the reasons Indigo is so robust, even if you use lots of plugins. In general all of these run asynchronously (in parallel) in their own processes:

• Every Indigo Plugin
• External file AppleScripts
• External file Python scripts

Commands sent to INSTEON or Z-Wave interfaces also run in parallel.

Embedded AppleScripts run in the main Indigo Server thread, so those will run sequentially (but other script or plugin actions started before any embedded AppleScripts will continue to run unblocked as the AppleScript runs).

Embedded Python scripts run sequentially, but they run in their own independent process parallel with the Indigo Server.

It gets complicated to predict if you have a plugin or script that is then calling an Indigo Server API, since that runs in the main Indigo Server thread. So while all of the processes run in parallel they can block/wait for the Indigo Server depending on what they are doing.

As to the particular problem described above, you could use an Indigo Variable value to signal when the AppleScript is "done" and then trigger off of the variable value state change. That trigger would do the post-AppleScript processing and then would toggle the variable value back to the "ready" state.

Image

Posted on
Mon Oct 09, 2017 2:57 am
Umtauscher offline
User avatar
Posts: 566
Joined: Oct 03, 2014
Location: Cologne, Germany

Re: Variables not set immediately (trigger insert state)

Thanks for the explanation. It would be good if there were a mechanism that could hold an action until another action has finished.

In my case I use an embedded Applescript statement to start a curl which sends an command via http to a network device. This changes the setting of that device which in turn should be reflected in a GhostXML plugin query to see if the setting took place.
To split that in several actions and triggers is a pain frankly because there are simply 2 statement that depend on each other.

Cheers
Wilhelm

Posted on
Mon Oct 09, 2017 11:59 am
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: Variables not set immediately (trigger insert state)

I highly recommend against using embedded AppleScripts to make blocking curl requests. Embedded AppleScripts have to run in the main Indigo Server thread and if they get blocked/stuck – which has been known to occur when making network calls – then the entire Indigo Server stops. Yet another reason embedded python is a preferred choice (it doesn't block the Indigo Server). I provided an example of using the python requests module to make a simple HTTP request here.

Image

Who is online

Users browsing this forum: No registered users and 9 guests

cron