Jump to content

question about variables in Network Resources


Recommended Posts

Well - I'm still new, so I'll ask another question while it's still forgivable hopefully

I want to use the ${alert.details} variable in a HTTP GET Network Resource, but I can't seem to get it to resolve at runtime - it works fine in a "Customized Content" email message called from a program, but, in the Network Resource, nothing happens to it.

Specifically, I put it into the path, like:  /cgi-bin/myscript.cgi?alert=${alert.details}    -- not URL-encoded

But when the Network Resource gets invoked by a Program when an event happens, on the other side I just see literally "${alert.details}"   (whereas in the email custom content, instead I get information about the event that just happened, which is what I want)

I've been reading a lot, but haven't yet found an instance where a variable like that is used in a Network Resource - can it be done?

 

Thanks again!

 

edit - if I put the variable in body with a POST request, like:

alert=${alert.details}

-- at least I get something other than the literal variable name:

      At: 2018/07/19  9:46:42 PM

  Value: null

 

but it looks like the information that's going into the email isn't making to the Network Resource (instead it's just "null").  For what it's worth, here's what comes in the email notification invoked by the same Program handling the same event, and this is what I would love to see in the CGI script that's being called by the Network Resource, rather than "Value: null":

     At: 2018/07/19  9:46:42 PM

Program: motion

 Device: ZW 002 Motion Sensor (ZW002_155)   

 Action: Status

  Value: On

 

 

 

Any suspicions as to what I'm doing wrong?

 

Link to comment

Please post a screenshot. There are some setting that are incompatible with variable substitutions.... principally the ‘Encode URL’ (which *must* be unchecked for variable substitutions to work). Encoding is done by the admin console when the network resource is saved and not at runtime after the substitution is made.

 

Also, if the variable substitute contains any invalid characters without encoding you cannot use that variable for substitution.

 

Other things that cannot be used - and variable with # (to indicate the triggering device). I suspect this variable is in the same category. There is no association between triggering event and the rule that can be used at runtime. Email substitutions do have the triggering device association.

Link to comment

thanks!!

Here's the Program:

       If
	       Status 'ZW 002 Motion Sensor' is Off
	    Or Status 'ZW 002 Motion Sensor' is On
	Then
	    Resource 'myscript'
	    Send Notification to 'localemail' content 'event'
	Else
	 - No Actions - (To add one, press 'Action')
	

Here are some screenshots.  First - is the Custom email Notification that does what I want it to do, and then I have two alternatives I've tried for the Network Resource, one using GET and one using POST

 

In the Custom Notification, the variable ${alert.details} is replaced with this (which is what I want to happen in the Network Resource):

"    At: 2018/07/19  9:46:42 PM

Program: motion

 Device: ZW 002 Motion Sensor (ZW002_155)   

 Action: Status

  Value: On"

 

With the GET Resource, my cgi script receives the "${alert.details}" literally as the "data" form field value, and with the POST Resource, the "data" form field value looks like:

"     At: 2018/07/19  9:46:42 PM

  Value: null"

 

[by the way - my alternative will be to simply use the email notifications to communicate - I'll direct the custom notification to a script that will extract the data I want and send it on its way.  I would prefer to use the Network Resource approach though - because it would be more standardized, and I wouldn't need to add a mail server to my local specified configuration (which doesn't currently include a web server, either, I suppose -- ideal would be for the ISY to send Zero MQ messages with JSON payloads, but I don't see how that could work at the moment)]

[and you may have answered the question when you said "There is no association between triggering event and the rule that can be used at runtime. Email substitutions do have the triggering device association." -- i.e., Email Custom Notifications have the runtime context for the substitution but Network Resources don't -- but just in case I don't understand, I'll still hold onto hope]

 

 

customnotification.jpg

resource-get.jpg

resource-post.jpg

Link to comment

I got the email thing working and then noticed that the ISY supports a bidirectional websocket with the REST API - doh!

Anyway, I learned a lot. I'm sure I have never seen such a small plastic box with so much going on in it!

Link to comment

Agreed. It’s an amazing little box - once the nuances are understood!

It was explained to me as a difference in how the actions are queued. Emails are fast to create so the substitutions happen inline with program execution and do not delay the execution. The result is hen queued to send in another thread. Network rules are queued before substitution and executed not necessarily inline with where the resource was called. So, at substitution time the engine does not know from where the resource was triggered.

The reason was that the designer did not want a slow or unresponsive network server to slow down or stall all program execution on the ISY.

I know somewhere in the change backlog is a proper queue mechanism for network resources where the substitution happens before queuing so that these variable values can be used.

Link to comment

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...