Page 1 of 1

Virtual On/Off Devices send url and update status

PostPosted: Fri Aug 18, 2017 6:47 am
by qcvictor
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

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

PostPosted: Fri Aug 18, 2017 9:29 am
by jay (support)
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.

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

PostPosted: Fri Aug 18, 2017 12:47 pm
by qcvictor
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 ?

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

PostPosted: Fri Aug 18, 2017 2:37 pm
by jay (support)
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.

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

PostPosted: Sun Aug 20, 2017 6:18 am
by qcvictor
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

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

PostPosted: Sun Aug 20, 2017 2:06 pm
by jay (support)
requests is probably my most used python module - it should be part of the standard Python library IMO...