Skip to content

Instantly share code, notes, and snippets.

@hdurdle
Created February 29, 2016 13:13
Show Gist options
  • Save hdurdle/940a06c1fc4821f595c7 to your computer and use it in GitHub Desktop.
Save hdurdle/940a06c1fc4821f595c7 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#
# Copyright 2015 - fullTalgoRythm
#
# Licensed under GNU General Public License 3.0 or later.
# Some rights reserved. See COPYING, AUTHORS.
#
# @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>
#
# see http://www.domoticz.com/wiki/Evohome
# see http://evohome-client.readthedocs.org/en/latest/index.html
#
import evoconfig
from evohomeclient2 import EvohomeClient
import requests
import json
import datetime
import base64
import os
import sys, traceback
if os.path.isfile("/var/tmp/evo-noup.tmp"):
os.remove("/var/tmp/evo-noup.tmp")
sys.exit(1)
#connect to evohome web portal @ http://www.mytotalconnect.com
client = EvohomeClient(evoconfig.usr,evoconfig.pw)
locations = client.locations
createdev=False
updatedev=True
if len(sys.argv)>1:
mode=sys.argv[1]
if mode=="init":
createdev=True
elif mode=="quick":
updatedev=False
for i in range(len(locations)):
hwname = "evohome" + str(i)
if createdev:
#create evohome script hardware
r=requests.get("http://%s:%s/json.htm?type=command&param=addhardware&htype=40&port=1&name=%s&enabled=true&datatimeout=0" % (evoconfig.url,evoconfig.port,hwname))
fi=client.full_installation()
systemId=fi['gateways'][0]['temperatureControlSystems'][0]['systemId']
modelType=fi['gateways'][0]['temperatureControlSystems'][0]['modelType']
status=client.locations[i].status()
tcs=status['gateways'][0]['temperatureControlSystems'][0]
zones=tcs['zones']
currentmode=tcs['systemModeStatus']['mode']
#find last added evohome script hw
r=requests.get("http://%s:%s/json.htm?type=hardware" % (evoconfig.url,evoconfig.port))
hwl=json.loads(r.text)
hwid=-1
for hw in hwl['result']:
#if hw['Type']==40:
if hw['Name']==hwname:
hwid=int(hw['idx'])
if hwid==-1:
print "ERROR: evohome hardware not found"
sys.exit(1)
if createdev:
#create evohome controller device
r=requests.get("http://%s:%s/json.htm?type=createevohomesensor&idx=%d&sensortype=69" % (evoconfig.url,evoconfig.port,hwid))
#create evohome dhw device
if 'dhw' in tcs:
r=requests.get("http://%s:%s/json.htm?type=createevohomesensor&idx=%d&sensortype=71" % (evoconfig.url,evoconfig.port,hwid))
#create evohome zones - create all zones
for i in range(len(zones)):
r=requests.get("http://%s:%s/json.htm?type=createevohomesensor&idx=%d&sensortype=70" % (evoconfig.url,evoconfig.port,hwid))
#update evohome devices with default name, id for portal access and correct location/name of script to run
r=requests.get("http://%s:%s/json.htm?type=devices&displayhidden=1&used=all" % (evoconfig.url,evoconfig.port))
devl=json.loads(r.text)
for dev in devl['result']:
if dev['HardwareID']==hwid:
if dev['SubType']=='Evohome':
if updatedev:
r=requests.get("http://%s:%s/json.htm?type=setused&idx=%s&deviceid=%s&used=true&name=%s&strparam1=%s" % (evoconfig.url,evoconfig.port,dev['idx'],systemId,modelType,base64.urlsafe_b64encode('%s/evo-setmode.sh {status}' % (evoconfig.srt))))
r=requests.get("http://%s:%s/json.htm?type=command&param=switchmodal&idx=%s&status=%s&action=0&ooc=1" % (evoconfig.url,evoconfig.port,dev['idx'],currentmode))
elif dev['SubType']=='Hot Water' and 'dhw' in tcs:
dhw=tcs['dhw']
if updatedev:
r=requests.get("http://%s:%s/json.htm?type=setused&idx=%s&deviceid=%s&used=true&name=%s&strparam1=%s" % (evoconfig.url,evoconfig.port,dev['idx'],dhw['dhwId'],"Hot Water",base64.urlsafe_b64encode('%s/evo-setdhw.sh {deviceid} {mode} {state} {until}' % (evoconfig.srt))))
zonemode=dhw['stateStatus']['mode']
if currentmode=="HeatingOff" or currentmode=="AutoWithEco" or currentmode=="Custom":# dhw has no economy mode and does not turn off for heating off also appears custom does not support the dhw zone
currentmode="Auto"
if zonemode=="FollowSchedule":
zonemode=currentmode
req="http://%s:%s/json.htm?type=command&param=udevice&idx=%s&nvalue=0&svalue=%s;%s;%s" % (evoconfig.url,evoconfig.port,dev['idx'],dhw['temperatureStatus']['temperature'],dhw['stateStatus']['state'],zonemode)
if zonemode=="TemporaryOverride":
req+=";%s" % (dhw['stateStatus']['until'])
r=requests.get(req)
elif dev['SubType']=='Zone' and dev['Unit']<=len(zones):
zone=zones[dev['Unit']-1]
if updatedev:
r=requests.get("http://%s:%s/json.htm?type=setused&idx=%s&deviceid=%s&used=true&name=%s&strparam1=%s" % (evoconfig.url,evoconfig.port,dev['idx'],zone['zoneId'],zone['name'],base64.urlsafe_b64encode('%s/evo-settemp.sh {deviceid} {mode} {setpoint} {until}' % (evoconfig.srt))))
if not zone['temperatureStatus']['isAvailable']:
continue
zonemode=zone['heatSetpointStatus']['setpointMode']
#for custom mode the rooms are assignable so ideally we need to check the schedule and see if the room is assigned or not
if zonemode=="FollowSchedule" or currentmode=="HeatingOff": #heating off doesn't support override i.e. heating is permanently switched off
zonemode=currentmode
req="http://%s:%s/json.htm?type=command&param=udevice&idx=%s&nvalue=0&svalue=%s;%s;%s" % (evoconfig.url,evoconfig.port,dev['idx'],zone['temperatureStatus']['temperature'],zone['heatSetpointStatus']['targetTemperature'],zonemode)
if zonemode=="TemporaryOverride":
req+=";%s" % (zone['heatSetpointStatus']['until'])
r=requests.get(req)
if createdev:
print "Your evohome zones should now be available in the Domoticz"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment