-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdomoticz.py
53 lines (42 loc) · 1.38 KB
/
domoticz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python
import sys
import json
import urllib2
import re
import time
import datetime
import httplib, urllib
class Domoticz():
def __init__(self, url):
self.baseurl = url
def __execute__(self, url):
req = urllib2.Request(url)
return urllib2.urlopen(req, timeout=5)
def set_device_on(self, xid):
"""
Get the Domoticz device information.
"""
url = "%s/json.htm?type=command¶m=switchlight&idx=%s&switchcmd=On" % (self.baseurl, xid)
data = json.load(self.__execute__(url))
return data
def set_device_off(self, xid):
"""
Get the Domoticz device information.
"""
url = "%s/json.htm?type=command¶m=switchlight&idx=%s&switchcmd=Off" % (self.baseurl, xid)
data = json.load(self.__execute__(url))
return data
def set_thermostat_value(self, xid, value):
"""
Update Setpoint for Thermostat
"""
url = "%s/json.htm?type=command¶m=udevice&idx=%s&svalue=%s" % (self.baseurl, xid, value)
data = json.load(self.__execute__(url))
return data['status']
def get_thermostat_value(self, xid):
"""
Get current Thermostat Value
"""
url = "%s/json.htm?type=devices&rid=%s" % (self.baseurl, xid)
data = json.load(self.__execute__(url))
return data['result'][0]['SetPoint']