private void EcobeeControls(List <HomeSeerAPI.CAPI.CAPIControl> colSend) { using (var ecobee = new EcobeeConnection()) { var access = ecobee.refreshToken(); if (access) { foreach (var CC in colSend) { try { EcobeeResponse response = null; Util.Log("SetIOMulti set value: " + CC.ControlValue.ToString() + "->ref:" + CC.Ref.ToString(), Util.LogType.LOG_TYPE_INFO); using (var ecobeeData = ecobee.getEcobeeData()) { DeviceClass dv = (DeviceClass)Util.hs.GetDeviceByRef(CC.Ref); string name; string id = Util.GetDeviceKeys(dv, out name); int high = 0; int low = 0; if (name == "Target Temperature High" || name == "Target Temperature Low" || name == "Fan Mode") { foreach (var thermostat in ecobeeData.thermostatList) { if (thermostat.identifier == id) { high = thermostat.runtime.desiredCool; low = thermostat.runtime.desiredHeat; } } } switch (name) { case "Fan Mode": if (CC.Label.ToLower() == "off") //fan settings can be "auto" or "on", can't set to "off" //The fan mode during the event. Values: auto, on Default: based on current climate and hvac mode //https://www.ecobee.com/home/developer/api/documentation/v1/objects/Event.shtml { response = ecobee.setApiJson("{\"selection\":{\"selectionType\":\"thermostats\",\"selectionMatch\":\"" + id + "\"},\"functions\": [{\"type\":\"setHold\",\"params\":{\"holdType\":\"nextTransition\",\"heatHoldTemp\":" + low + ",\"coolHoldTemp\":" + high + ",\"fan\": \"auto\"}}]}"); } else { response = ecobee.setApiJson("{\"selection\":{\"selectionType\":\"thermostats\",\"selectionMatch\":\"" + id + "\"},\"functions\": [{\"type\":\"setHold\",\"params\":{\"holdType\":\"nextTransition\",\"heatHoldTemp\":" + low + ",\"coolHoldTemp\":" + high + ",\"fan\": \"" + CC.Label.ToLower() + "\"}}]}"); } break; case "HVAC Mode": response = ecobee.setApiJson("{\"selection\":{\"selectionType\":\"thermostats\",\"selectionMatch\":\"" + id + "\"},\"thermostat\":{\"settings\":{ \"hvacMode\":\"" + CC.Label.ToLower() + "\"}}}"); break; case "Target Temperature Low": Console.WriteLine("low"); response = ecobee.setApiJson("{\"selection\":{\"selectionType\":\"thermostats\",\"selectionMatch\":\"" + id + "\"},\"functions\": [{\"type\":\"setHold\",\"params\":{\"holdType\":\"nextTransition\",\"heatHoldTemp\":" + CC.ControlValue * 10 + ",\"coolHoldTemp\":" + high + "}}]}"); break; case "Target Temperature High": Console.WriteLine("high"); response = ecobee.setApiJson("{\"selection\":{\"selectionType\":\"thermostats\",\"selectionMatch\":\"" + id + "\"},\"functions\": [{\"type\":\"setHold\",\"params\":{\"holdType\":\"nextTransition\",\"heatHoldTemp\":" + low + ",\"coolHoldTemp\":" + CC.ControlValue * 10 + "}}]}"); break; } } if (response != null && response.status != null && response.status.code == 0) { Util.hs.SetDeviceValueByRef(CC.Ref, CC.ControlValue, true); } else { if (response != null && response.status != null) { if (response.status.code == 14) { EcobeeControls(colSend); } Util.Log(response.status.message, Util.LogType.LOG_TYPE_ERROR); } else { Util.Log("Unknown error while trying to set value", Util.LogType.LOG_TYPE_ERROR); } } } catch (Exception e) { Util.Log(e.ToString(), Util.LogType.LOG_TYPE_ERROR); } } } else { //first try refreshing token // Util.Log("Invalid Refresh Token-Try resetting the token on the Options Page", Util.LogType.LOG_TYPE_ERROR); } } }
private void EcobeeControls(List <HomeSeerAPI.CAPI.CAPIControl> colSend) { foreach (var CC in colSend) { try { EcobeeResponse response = null; Util.Log("SetIOMulti set value: " + CC.ControlValue.ToString() + "->ref:" + CC.Ref.ToString(), Util.LogType.LOG_TYPE_INFO); using (var ecobee = new EcobeeConnection()) { using (var ecobeeData = ecobee.getEcobeeData()) { DeviceClass dv = (DeviceClass)Util.hs.GetDeviceByRef(CC.Ref); string name; string id = Util.GetDeviceKeys(dv, out name); int high = 0; int low = 0; if (name == "Target Temperature High" || name == "Target Tempurature Low") { foreach (var thermostat in ecobeeData.thermostatList) { if (thermostat.identifier == id) { high = thermostat.runtime.desiredCool; low = thermostat.runtime.desiredHeat; } } } switch (name) { case "Fan Mode": response = ecobee.setApiJson("{\"selection\":{\"selectionType\":\"thermostats\",\"selectionMatch\":\"" + id + "\"},\"functions\": [{\"type\":\"setHold\",\"params\":{\"holdType\":\"nextTransition\",\"heatHoldTemp\":" + low + ",\"coolHoldTemp\":" + high + ",\"fan\": \"" + CC.Label.ToLower() + "\"}}]}"); break; case "HVAC Mode": response = ecobee.setApiJson("{\"selection\":{\"selectionType\":\"thermostats\",\"selectionMatch\":\"" + id + "\"},\"thermostat\":{\"settings\":{ \"hvacMode\":\"" + CC.Label.ToLower() + "\"}}}"); break; case "Target Temperature Low": Console.WriteLine("low"); response = ecobee.setApiJson("{\"selection\":{\"selectionType\":\"thermostats\",\"selectionMatch\":\"" + id + "\"},\"functions\": [{\"type\":\"setHold\",\"params\":{\"holdType\":\"nextTransition\",\"heatHoldTemp\":" + CC.ControlValue * 10 + ",\"coolHoldTemp\":" + high + "}}]}"); break; case "Target Temperature High": Console.WriteLine("high"); response = ecobee.setApiJson("{\"selection\":{\"selectionType\":\"thermostats\",\"selectionMatch\":\"" + id + "\"},\"functions\": [{\"type\":\"setHold\",\"params\":{\"holdType\":\"nextTransition\",\"heatHoldTemp\":" + low + ",\"coolHoldTemp\":" + CC.ControlValue * 10 + "}}]}"); break; } } } if (response != null && response.status != null && response.status.code == 0) { Util.hs.SetDeviceValueByRef(CC.Ref, CC.ControlValue, true); } else { if (response != null && response.status != null) { Util.Log(response.status.message, Util.LogType.LOG_TYPE_ERROR); } else { Util.Log("Unknown error while trying to set value", Util.LogType.LOG_TYPE_ERROR); } } } catch (Exception e) { Util.Log(e.ToString(), Util.LogType.LOG_TYPE_ERROR); } } }