Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Create a file called wiserkeys.params and place two lines, one with the wiser IP
e.g.
```
wiserkey=ABCDCDCDCCCDCDC
wiserip=192.168.0.22
wiserhubip=192.168.0.22
```

## 5. Run the sample
Expand Down
65 changes: 44 additions & 21 deletions wiserHeatingAPI/wiserHub.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@


class wiserHub():


def __init__(self,hubIP,secret):
_LOGGER.info("WiserHub API Init")
Expand All @@ -35,7 +34,7 @@ def __init__(self,hubIP,secret):
self.headers = {'SECRET': self.hubSecret,'Content-Type': 'application/json;charset=UTF-8'}
self.device2roomMap={} # Dict holding Valve2Room mapping convinience variable
self.refreshData() # Issue first refresh in init

def refreshData(self):
"""
Forces a refresh of data
Expand Down Expand Up @@ -63,8 +62,6 @@ def refreshData(self):
_LOGGER.warning("Wiser found no rooms")
return self.wiserHubData



def getHubData(self):
"""
Retrieves the full JSON payload , for functions where I havent provided a API yet
Expand Down Expand Up @@ -157,7 +154,6 @@ def getDevice(self,deviceId):
return device
return None


def getDeviceRoom(self,deviceId):
"""
Convinience function to return the name of a room which is associated with a device (roomstat or trf)
Expand Down Expand Up @@ -185,7 +181,7 @@ def getHeatingRelayStatus(self):
if heatingChannel.get("HeatingRelayState")=="On":
heatingRelayStatus="On"
return heatingRelayStatus

def getHotwaterRelayStatus(self):
"""
Returns hotwater relay status
Expand All @@ -196,7 +192,43 @@ def getHotwaterRelayStatus(self):
if (self.wiserHubData==None):
self.refreshData()
return self.wiserHubData.get("HotWater")[0].get("WaterHeatingState")


def setHotwaterMode(self, mode):
"""
Switch Hot Water on or off manually, or reset to 'Auto' (schedule).

'mode' can be "on", "off" or "auto".
"""

# Wiser requires a temperature when patching the Hot Water state,
# reflecting 'on' or 'off'
DHWOnTemp = 1100
DHWOffTemp = -200

modeMapping = {
'on': {"RequestOverride":{"Type":"Manual", "SetPoint": DHWOnTemp}},
'off': {"RequestOverride":{"Type":"Manual", "SetPoint": DHWOffTemp}},
'auto': {"RequestOverride":{"Type":"None", "Mode": "Auto"}},
}

_mode = mode.lower()
if _mode not in ['on', 'off', 'auto']:
raise Exception("Hot Water can be either 'on', 'off' or 'auto' - not '%s'" % _mode)

# Obtain our DHW control ID
if (self.wiserHubData==None):
self.refreshData()
DHWId = self.wiserHubData.get("HotWater")[0].get("id")

_url = WISERHUBURL.format(self.hubIP) + "/HotWater/{}/".format(DHWId)
_LOGGER.debug ("Sending Patch Data: {}, to URL [{}]".format(modeMapping.get(_mode), _url))
self.response = requests.patch(url=_url, headers=self.headers, json=modeMapping.get(_mode))
if (self.response.status_code!=200):
_LOGGER.debug("Set DHW Response code = {}".format(self.response.status_code))
raise Exception("Error setting hot water mode to {}, error {} {}".format(_mode, self.response.status_code, self.response.text))

return True

def getRoomStatData(self,deviceId):
"""
Gets Roomt Thermostats Data
Expand All @@ -212,7 +244,7 @@ def getRoomStatData(self,deviceId):
for roomStat in self.wiserHubData['RoomStat']:
if roomStat.get("id")==deviceId:
return roomStat
return None
return None

def setHomeAwayMode(self,mode,temperature=10):
"""
Expand Down Expand Up @@ -247,8 +279,6 @@ def setHomeAwayMode(self,mode,temperature=10):
_LOGGER.debug("Set Home/Away Response code = {}".format(self.response.status_code))
raise Exception("Error setting Home/Away , error {} {}".format(self.response.status_code, self.response.text))



def setRoomTemperature(self, roomId, temperature):
"""
Sets the room temperature
Expand All @@ -262,15 +292,13 @@ def setRoomTemperature(self, roomId, temperature):
patchData={"RequestOverride":{"Type":"Manual","SetPoint":apitemp}}
self.response = requests.patch(WISERSETROOMTEMP.format(
self.hubIP,roomId), headers=self.headers,json=patchData)

if self.response.status_code != 200:
_LOGGER.error("Set Room {} Temperature to = {} resulted in {}".format(roomId,temperature,self.response.status_code))
raise Exception("Error setting temperature, error {} ".format(self.response.text))
_LOGGER.debug("Set room Temp, error {} ({})".format(self.response.status_code, self.response.text))




# Set Room Mode (Manual, Boost,Off or Auto )
# If set to off then the trv goes to manual and temperature of -200
#
Expand Down Expand Up @@ -309,24 +337,19 @@ def setRoomMode(self,roomId, mode,boost_temp=20,boost_temp_time=30):
patchData = {"Mode": "Manual","RequestOverride": {"Type": "Manual","SetPoint": -200}}
else:
raise Exception("Error setting setting room mode, received {} but should be auto,boost,off or manual ".format(mode))

# if not a boost operation cancel any current boost
if (mode.lower()!="boost"):
cancelBoostPostData={"RequestOverride":{"Type":"None","DurationMinutes": 0, "SetPoint":0, "Originator":"App"}}

self.response = requests.patch(WISERROOM.format(self.hubIP,roomId), headers=self.headers,json=cancelBoostPostData)
if (self.response.status_code != 200):
_LOGGER.error("Cancelling boost resulted in {}".format(self.response.status_code))
raise Exception("Error cancelling boost {} ".format(mode))

# Set new mode
self.response = requests.patch(WISERROOM.format(
self.hubIP,roomId), headers=self.headers,json=patchData)
self.hubIP,roomId), headers=self.headers,json=patchData)
if self.response.status_code != 200:
_LOGGER.error("Set Room mode to {} resulted in {}".format(mode,self.response.status_code))
raise Exception("Error setting mode to error {} ".format(mode))





2 changes: 1 addition & 1 deletion wiserapitest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# wh.refreshdata()
# print("itrv 8 is in room {}".format(wh.getDeviceRoom(8)['roomName']))
# Heating State
print ("Hot water status {} ".format(wh.getHeatingRelayStatus()))
print ("Hot water status {} ".format(wh.getHotwaterRelayStatus()))
print ("Roomstat humidity {}".format(wh.getRoomStatData(1).get("MeasuredHumidity")))

print("--------------------------------")
Expand Down