Adding variable to url and then run/open url

Posted on
Wed Apr 09, 2014 4:14 am
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Adding variable to url and then run/open url

Hi,
I am starting to try to migrate from vera to indigo. But in order to do so I have to take it in steps.
The thing I want to try is to move some of my rf equipment to indigo.
So I want to try to update a variable that is on the vera.

Here is my case.
I store values from my sensors in a variable in indigo.
Then I want to add this variable at the end of a url (VALUE) and run that url. Is this possible to do?


http://IP:3480/data_request?id=variable ... alue=VALUE



regards

Håvard

Posted on
Wed Apr 09, 2014 4:22 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Adding variable to url and then run/open url

Check this Python example in our Python scripting tutorial.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Apr 10, 2014 3:34 am
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Adding variable to url and then run/open url

Hi thank you for your reply.
I am new to this, so please bear with me...

When I try the following I get an error when I try to run the script.
"embedded script: not a valid non-strig sequence or mapping object"



myVar = indigo.variables[1338124154]
import urllib, urllib2
urllib2.urlopen("http://10.0.1.222:3480/data_request?id=variableset&DeviceNum=67&serviceId=urn:upnp-org:serviceId:VContainer1&Variable=Variable1&Value=%s" % urllib.urlencode(myVar.value))

Can you see what is wrong with the script?

regards

Håvard

Posted on
Thu Apr 10, 2014 7:51 am
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Adding variable to url and then run/open url

My bad - you want to use quote_plus() rather than urlencode:

Code: Select all
myVar = indigo.variables[1338124154]
import urllib, urllib2
urllib2.urlopen("http://10.0.1.222:3480/data_request?id=variableset&DeviceNum=67&serviceId=urn:upnp-org:serviceId:VContainer1&Variable=Variable1&Value=%s" % urllib.quote_plus(myVar.value))


The point is that because variable values can contain any kind of value (spaces, etc.), if you're going to pass them on a URL line they need to be encoded.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Apr 11, 2014 3:43 am
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Adding variable to url and then run/open url

Thank you for your help.
That did the trick. I can now do exactly what I was hoping for.

Håvard

Posted on
Tue Apr 29, 2014 5:30 am
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Adding variable to url and then run/open url

Has been using this, and it is working good.
But I wonder if it is possible to turn it the other way around?
Can I set a variable in indigo by a http request?

thanks for your help so far.
regards

Håvard

Posted on
Tue Apr 29, 2014 7:58 am
Bollar offline
Posts: 528
Joined: Aug 11, 2013

Re: Adding variable to url and then run/open url

This is documented in the Indigo help, but you might also find these real world examples helpful. I created them as I was trying to figure out how it all works: viewtopic.php?f=107&t=11386

Insteon / Z-Wave / Bryant Evolution Connex /Tesla / Roomba / Elk M1 / SiteSage / Enphase Enlighten / NOAA Alerts

Posted on
Tue Apr 29, 2014 9:51 am
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Adding variable to url and then run/open url

I found an example I could use. I can now do exactly what I wanted to do.
Thanks for your input.

Regards

Håvard

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 5 guests