Virtual On/Off Devices send url and update status

Posted on
Fri Aug 18, 2017 6:47 am
qcvictor offline
Posts: 80
Joined: Apr 23, 2015
Location: Quebec, Canada

Virtual On/Off Devices send url and update status

Hi Guys
My setup on virtual device on/off sending an url via python script to my envisalink for open my garage door, I would like updates the status on this virtual switch (without send url) coming from DSC alarm plugin device (status is open/closed)
Not sure the best way to do that ?
Regards
Vic

Posted on
Fri Aug 18, 2017 9:29 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Virtual On/Off Devices send url and update status

Use the Device Actions->Virtual Device Controls->Set Virtual On/Off Device State action type to set the state. You can use those in triggers on the DSC device state.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Aug 18, 2017 12:47 pm
qcvictor offline
Posts: 80
Joined: Apr 23, 2015
Location: Quebec, Canada

Re: Virtual On/Off Devices send url and update status

ok I will give it a try after solved this small issue, url send give this error :
Script Error embedded script: nonnumeric port: 'user@10.10.10.13'
Script Error Exception Traceback (most recent call shown last):

embedded script, line 2, at top level
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 431, in open
response = self._open(req, data)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 449, in _open
'_open', req)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
result = func(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1227, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1166, in do_open
h = http_class(host, timeout=req.timeout, **http_conn_args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 751, in __init__
(self.host, self.port) = self._get_hostport(host, port)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 793, in _get_hostport
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
InvalidURL: nonnumeric port: 'user@10.10.10.13'

the script look like that
import urllib2
return_string = urllib2.urlopen("http://user:password@10.10.10.13/2?A=1&P=2&p=1").read()

How pass authentication ?

Posted on
Fri Aug 18, 2017 2:37 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Virtual On/Off Devices send url and update status

Hmmm - odd. Change the URL to:

"http://user:password@10.10.10.13:80/2?A=1&P=2&p=1"


It looks like the urlopen is getting confused about the password possibly.

Or, use the requests module (included with Indigo 7) rather than urllib2.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Aug 20, 2017 6:18 am
qcvictor offline
Posts: 80
Joined: Apr 23, 2015
Location: Quebec, Canada

Re: Virtual On/Off Devices send url and update status

tks Jay
import requests
r = requests.get('http://10.10.10.13/2?A=1&P=2&p=1', auth=('user', 'password'))
works like a charm
regards
Vic

Posted on
Sun Aug 20, 2017 2:06 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Virtual On/Off Devices send url and update status

requests is probably my most used python module - it should be part of the standard Python library IMO...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 0 guests