Esempio n. 1
0
        // This method is called whenever a Options page control is used (buttons, textboxes, etc.)
        public override string postBackProc(string page, string data, string user, int userRights)
        {
            System.Collections.Specialized.NameValueCollection parts = null;
            parts = HttpUtility.ParseQueryString(data);

            using (var ecobee = new EcobeeConnection())
            {
                string id = parts["id"];
                Console.WriteLine(data);

                if (id == "pin_get")
                {
                    pin_code = ecobee.retrievePin();
                    divToUpdate.Add("pin_region", pin_code);
                }

                if (id == "access_button")
                {
                    var success = ecobee.retrieveAccessToken(true);

                    if (success)
                    {
                        pageCommands.Add("popmessage", "Successfully reset Access Token");
                    }
                    else
                    {
                        pageCommands.Add("popmessage", "Failed to reset Access Token");
                    }
                }
            }
            return(base.postBackProc(page, data, user, userRights));
        }
Esempio n. 2
0
 private void updateStatusValues()
 {
     running = true;
     try
     {
         using (var ecobee = new EcobeeConnection())
         {
             var access = ecobee.retrieveAccessToken(false);
             if (access)
             {
                 Util.Find_Create_Devices(ecobee);
             }
             else
             {
                 Util.Log("Invalid Refresh Token-Try resetting the token on the Options Page", Util.LogType.LOG_TYPE_ERROR);
             }
         }
     }
     catch (Exception ex)
     {
         Util.Log(ex.ToString(), Util.LogType.LOG_TYPE_ERROR);
         System.IO.File.WriteAllText(@"Data/hspi_ecobeesiid/debug.txt", ex.ToString());
     }
     running = false;
 }
Esempio n. 3
0
        static internal void Find_Create_Devices(EcobeeConnection ecobee)
        {
            List <DeviceDataPoint> deviceList = new List <DeviceDataPoint>();

            using (var ecobeeData = ecobee.getEcobeeData())
            {
                deviceList = Get_Device_List(deviceList);

                Find_Create_Thermostats(ecobeeData, deviceList, ecobee);
            }
        }
Esempio n. 4
0
        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);
                }
            }
        }
Esempio n. 5
0
        static internal bool Remote_Devices(string tString, Thermostat thermostat, RemoteSensors remote, SensorCapabilities capability, List <DeviceDataPoint> deviceList, EcobeeConnection ecobee)
        {
            var sensorType = "";

            if (capability.type.Equals("temperature"))
            {
                sensorType = "Temperature";
            }
            if (capability.type.Equals("occupancy"))
            {
                sensorType = "Occupancy";
            }

            string name;
            string id;

            foreach (var ddPoint in deviceList)
            {
                id = GetDeviceKeys(ddPoint.device, out name);

                if (id == (thermostat.identifier + remote.code) && name == (sensorType + tString))
                {
                    Update_RemoteDevice(thermostat, capability, ddPoint, ecobee);
                    return(false);
                }
            }



            DeviceClass dv = new DeviceClass();

            dv = GenericHomeSeerDevice(dv, sensorType + tString, remote.name, thermostat.identifier + remote.code);
            var dvRef = dv.get_Ref(hs);

            id = GetDeviceKeys(dv, out name);

            switch (name)
            {
            case "Temperature Sensor":
            {
                VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair);
                SPair                   = new VSVGPairs.VSPair(ePairStatusControl.Status);
                SPair.PairType          = VSVGPairs.VSVGPairType.Range;
                SPair.RangeStart        = -500;
                SPair.RangeEnd          = 500;
                SPair.RangeStatusSuffix = " " + getTemperatureUnits(thermostat.settings.useCelsius);
                hs.DeviceVSP_AddPair(dvRef, SPair);

                VSVGPairs.VGPair GPair = new VSVGPairs.VGPair();
                GPair.PairType   = VSVGPairs.VSVGPairType.Range;
                GPair.RangeStart = -500;
                GPair.RangeEnd   = 500;
                GPair.Graphic    = "/images/HomeSeer/contemporary/Thermometer-70.png";
                hs.DeviceVGP_AddPair(dvRef, GPair);
                break;
            }

            case "Occupancy Sensor":
            {
                VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair);
                SPair          = new VSVGPairs.VSPair(ePairStatusControl.Status);
                SPair.PairType = VSVGPairs.VSVGPairType.SingleValue;
                SPair.Value    = 0;
                SPair.Status   = "Unoccupied";
                hs.DeviceVSP_AddPair(dvRef, SPair);

                SPair.Value  = 1;
                SPair.Status = "Occupied";
                hs.DeviceVSP_AddPair(dvRef, SPair);

                VSVGPairs.VGPair GPair = new VSVGPairs.VGPair();
                GPair.PairType  = VSVGPairs.VSVGPairType.SingleValue;
                GPair.Set_Value = 0;
                GPair.Graphic   = "/images/HomeSeer/contemporary/away.png";
                hs.DeviceVGP_AddPair(dvRef, GPair);

                GPair.Set_Value = 1;
                GPair.Graphic   = "/images/HomeSeer/contemporary/home.png";
                hs.DeviceVGP_AddPair(dvRef, GPair);
                break;
            }
            }

            return(true);
        }
Esempio n. 6
0
        static internal bool Thermostat_Devices(string tString, Thermostat thermostat, List <DeviceDataPoint> deviceList, EcobeeConnection ecobee)
        {
            string name;
            string id;

            foreach (var ddPoint in deviceList)
            {
                id = GetDeviceKeys(ddPoint.device, out name);
                if (id == thermostat.identifier && name == tString)
                {
                    Update_ThermostatDevice(thermostat, ddPoint, ecobee);
                    return(false);
                }
            }

            DeviceClass dv = new DeviceClass();

            dv = GenericHomeSeerDevice(dv, tString, thermostat.name, thermostat.identifier);
            var dvRef = dv.get_Ref(hs);

            id = GetDeviceKeys(dv, out name);
            switch (name)
            {
            case "Root":
            {
                DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo();
                dt.Device_API  = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat;
                dt.Device_Type = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Thermostat.Root;
                dv.set_DeviceType_Set(hs, dt); dv.set_Relationship(hs, Enums.eRelationship.Parent_Root);
                dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY);

                VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair);
                SPair          = new VSVGPairs.VSPair(ePairStatusControl.Status);
                SPair.PairType = VSVGPairs.VSVGPairType.SingleValue;
                SPair.Value    = 0;
                SPair.Status   = "Thermostat Root";
                hs.DeviceVSP_AddPair(dvRef, SPair);

                VSVGPairs.VGPair GPair = new VSVGPairs.VGPair();
                GPair.PairType  = VSVGPairs.VSVGPairType.SingleValue;
                GPair.Set_Value = 0;
                GPair.Graphic   = "/images/HomeSeer/contemporary/ok.png";
                hs.DeviceVGP_AddPair(dvRef, GPair);

                break;
            }

            case "HVAC Mode":
            {
                dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES);
                DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo();
                dt.Device_API     = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat;
                dt.Device_Type    = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Thermostat.Mode_Set;
                dt.Device_SubType = 0;
                dv.set_DeviceType_Set(hs, dt);

                VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair);
                SPair                        = new VSVGPairs.VSPair(ePairStatusControl.Both);
                SPair.PairType               = VSVGPairs.VSVGPairType.SingleValue;
                SPair.Render                 = Enums.CAPIControlType.Button;
                SPair.Value                  = 0;
                SPair.Status                 = "Off";
                SPair.Render_Location.Row    = 1;
                SPair.Render_Location.Column = 1;
                SPair.ControlUse             = ePairControlUse._ThermModeOff;
                hs.DeviceVSP_AddPair(dvRef, SPair);

                VSVGPairs.VGPair GPair = new VSVGPairs.VGPair();
                GPair.PairType  = VSVGPairs.VSVGPairType.SingleValue;
                GPair.Set_Value = 0;
                GPair.Graphic   = "/images/HomeSeer/contemporary/modeoff.png";
                hs.DeviceVGP_AddPair(dvRef, GPair);

                SPair.Value  = 1;
                SPair.Status = "Auto";
                SPair.Render_Location.Row    = 1;
                SPair.Render_Location.Column = 2;
                SPair.ControlUse             = ePairControlUse._ThermModeAuto;
                hs.DeviceVSP_AddPair(dvRef, SPair);

                GPair.PairType  = VSVGPairs.VSVGPairType.SingleValue;
                GPair.Set_Value = 1;
                GPair.Graphic   = "/images/HomeSeer/contemporary/auto-mode.png";
                hs.DeviceVGP_AddPair(dvRef, GPair);

                SPair.Value  = 2;
                SPair.Status = "Cool";
                SPair.Render_Location.Row    = 1;
                SPair.Render_Location.Column = 2;
                SPair.ControlUse             = ePairControlUse._ThermModeCool;
                hs.DeviceVSP_AddPair(dvRef, SPair);

                GPair.PairType  = VSVGPairs.VSVGPairType.SingleValue;
                GPair.Set_Value = 2;
                GPair.Graphic   = "/images/HomeSeer/contemporary/cooling.png";
                hs.DeviceVGP_AddPair(dvRef, GPair);

                SPair.Value  = 3;
                SPair.Status = "Heat";
                SPair.Render_Location.Row    = 1;
                SPair.Render_Location.Column = 2;
                SPair.ControlUse             = ePairControlUse._ThermModeHeat;
                hs.DeviceVSP_AddPair(dvRef, SPair);

                GPair.PairType  = VSVGPairs.VSVGPairType.SingleValue;
                GPair.Set_Value = 3;
                GPair.Graphic   = "/images/HomeSeer/contemporary/heating.png";
                hs.DeviceVGP_AddPair(dvRef, GPair);

                break;
            }

            case "Fan Mode":
            {
                dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES);
                DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo();
                dt.Device_API     = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat;
                dt.Device_Type    = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Thermostat.Fan_Mode_Set;
                dt.Device_SubType = 0;
                dv.set_DeviceType_Set(hs, dt);

                VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair);
                SPair                        = new VSVGPairs.VSPair(ePairStatusControl.Both);
                SPair.PairType               = VSVGPairs.VSVGPairType.SingleValue;
                SPair.Render                 = Enums.CAPIControlType.Button;
                SPair.Value                  = 0;
                SPair.Status                 = "Off";
                SPair.Render_Location.Row    = 1;
                SPair.Render_Location.Column = 1;
                hs.DeviceVSP_AddPair(dvRef, SPair);

                VSVGPairs.VGPair GPair = new VSVGPairs.VGPair();
                GPair.PairType  = VSVGPairs.VSVGPairType.SingleValue;
                GPair.Set_Value = 0;
                GPair.Graphic   = "/images/HomeSeer/contemporary/fan-state-off.png";
                hs.DeviceVGP_AddPair(dvRef, GPair);

                SPair.Value  = 1;
                SPair.Status = "On";
                SPair.Render_Location.Row    = 1;
                SPair.Render_Location.Column = 2;
                SPair.ControlUse             = ePairControlUse._ThermFanOn;
                hs.DeviceVSP_AddPair(dvRef, SPair);

                GPair.PairType  = VSVGPairs.VSVGPairType.SingleValue;
                GPair.Set_Value = 1;
                GPair.Graphic   = "/images/HomeSeer/contemporary/fan-on.png";
                hs.DeviceVGP_AddPair(dvRef, GPair);

                SPair.Value  = 2;
                SPair.Status = "Auto";
                SPair.Render_Location.Row    = 1;
                SPair.Render_Location.Column = 2;
                SPair.ControlUse             = ePairControlUse._ThermFanAuto;
                hs.DeviceVSP_AddPair(dvRef, SPair);

                GPair.PairType  = VSVGPairs.VSVGPairType.SingleValue;
                GPair.Set_Value = 2;
                GPair.Graphic   = "/images/HomeSeer/contemporary/fan-auto.png";
                hs.DeviceVGP_AddPair(dvRef, GPair);
                break;
            }

            case "Deadband":
            case "Target Temperature High":
            case "Target Temperature Low":
            case "Ambient Temperature":
            {
                VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair);
                SPair                   = new VSVGPairs.VSPair(ePairStatusControl.Status);
                SPair.PairType          = VSVGPairs.VSVGPairType.Range;
                SPair.RangeStart        = -150;
                SPair.RangeEnd          = 100;
                SPair.RangeStatusSuffix = " °" + VSVGPairs.VSPair.ScaleReplace;
                SPair.HasScale          = true;
                hs.DeviceVSP_AddPair(dvRef, SPair);

                if (name.Equals("Target Temperature High") || name.Equals("Target Temperature Low"))
                {
                    dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES);

                    SPair                        = new VSVGPairs.VSPair(HomeSeerAPI.ePairStatusControl.Control);
                    SPair.PairType               = VSVGPairs.VSVGPairType.Range;
                    SPair.Render                 = Enums.CAPIControlType.TextBox_Number;
                    SPair.Render_Location.Row    = 1;
                    SPair.Render_Location.Column = 1;
                    SPair.Status                 = "Enter target:";
                    SPair.RangeStart             = 0;
                    SPair.RangeEnd               = 100;
                    if (name.Equals("Target Temperature Low"))
                    {
                        SPair.ControlUse = ePairControlUse._HeatSetPoint;
                        DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo();
                        dt.Device_API     = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat;
                        dt.Device_Type    = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Thermostat.Setpoint;
                        dt.Device_SubType = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceSubType_Setpoint.Heating_1;
                        dv.set_DeviceType_Set(hs, dt);
                    }
                    else if (name.Equals("Target Temperature High"))
                    {
                        SPair.ControlUse = ePairControlUse._CoolSetPoint;

                        DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo();
                        dt.Device_API     = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat;
                        dt.Device_Type    = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Thermostat.Setpoint;
                        dt.Device_SubType = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceSubType_Setpoint.Cooling_1;
                        dv.set_DeviceType_Set(hs, dt);
                    }
                    hs.DeviceVSP_AddPair(dvRef, SPair);
                }
                else if (name.Equals("Ambient Temperature"))
                {
                    DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo();
                    dt.Device_API  = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat;
                    dt.Device_Type = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Thermostat.Temperature;
                    dv.set_DeviceType_Set(hs, dt);
                }

                VSVGPairs.VGPair GPair = new VSVGPairs.VGPair();
                GPair.PairType   = VSVGPairs.VSVGPairType.Range;
                GPair.RangeStart = -100;
                GPair.RangeEnd   = 150;
                GPair.Graphic    = "/images/HomeSeer/contemporary/Thermometer-70.png";
                hs.DeviceVGP_AddPair(dvRef, GPair);

                break;
            }

            case "Current Program":
            {
                dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES);

                VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair);
                SPair          = new VSVGPairs.VSPair(ePairStatusControl.Status);
                SPair.PairType = VSVGPairs.VSVGPairType.SingleValue;
                SPair.Value    = 0;
                SPair.Status   = "Hold";
                hs.DeviceVSP_AddPair(dvRef, SPair);

                SPair.Value  = 1;
                SPair.Status = "Demand Response";
                hs.DeviceVSP_AddPair(dvRef, SPair);

                SPair.Value  = 2;
                SPair.Status = "Sensor";
                hs.DeviceVSP_AddPair(dvRef, SPair);

                SPair.Value  = 3;
                SPair.Status = "Switch Occupancy";
                hs.DeviceVSP_AddPair(dvRef, SPair);
                SPair.Value  = 4;
                SPair.Status = "Vacation";
                hs.DeviceVSP_AddPair(dvRef, SPair);
                SPair.Value  = 5;
                SPair.Status = "Quick Save";
                hs.DeviceVSP_AddPair(dvRef, SPair);
                SPair.Value  = 6;
                SPair.Status = "Today";
                hs.DeviceVSP_AddPair(dvRef, SPair);
                SPair.Value  = 7;
                SPair.Status = "Template";
                hs.DeviceVSP_AddPair(dvRef, SPair);

                VSVGPairs.VGPair GPair = new VSVGPairs.VGPair();
                GPair.PairType   = VSVGPairs.VSVGPairType.Range;
                GPair.RangeStart = 0;
                GPair.RangeEnd   = 4;
                GPair.Graphic    = "/images/HomeSeer/contemporary/home.png";
                hs.DeviceVGP_AddPair(dvRef, GPair);

                break;
            }

            case "HVAC Status":
            case "Fan Status":
            case "Cool Range":
            case "Heat Range":
            {
                VSVGPairs.VGPair GPair = new VSVGPairs.VGPair();
                GPair.PairType = VSVGPairs.VSVGPairType.SingleValue;
                GPair.Graphic  = "/images/HomeSeer/contemporary/alarmheartbeat.png";
                hs.DeviceVGP_AddPair(dvRef, GPair);

                break;
            }

            case "Humidity":
            {
                DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo();
                dt.Device_API     = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat;
                dt.Device_Type    = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Thermostat.Temperature;
                dt.Device_SubType = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceSubType_Temperature.Humidity;
                dv.set_DeviceType_Set(hs, dt);

                VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair);
                SPair                   = new VSVGPairs.VSPair(ePairStatusControl.Status);
                SPair.PairType          = VSVGPairs.VSVGPairType.Range;
                SPair.RangeStart        = 0;
                SPair.RangeEnd          = 100;
                SPair.RangeStatusSuffix = " %";
                hs.DeviceVSP_AddPair(dvRef, SPair);

                VSVGPairs.VGPair GPair = new VSVGPairs.VGPair();
                GPair.PairType   = VSVGPairs.VSVGPairType.Range;
                GPair.RangeStart = 0;
                GPair.RangeEnd   = 100;
                GPair.Graphic    = "/images/HomeSeer/contemporary/water.gif";
                hs.DeviceVGP_AddPair(dvRef, GPair);

                break;
            }

            case "Occupancy":
            {
                VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair);
                SPair          = new VSVGPairs.VSPair(ePairStatusControl.Status);
                SPair.PairType = VSVGPairs.VSVGPairType.SingleValue;
                SPair.Value    = 0;
                SPair.Status   = "Unoccupied";
                hs.DeviceVSP_AddPair(dvRef, SPair);

                SPair.Value  = 1;
                SPair.Status = "Occupied";
                hs.DeviceVSP_AddPair(dvRef, SPair);

                SPair.Value  = 2;
                SPair.Status = "No Event";
                hs.DeviceVSP_AddPair(dvRef, SPair);

                VSVGPairs.VGPair GPair = new VSVGPairs.VGPair();
                GPair.PairType  = VSVGPairs.VSVGPairType.SingleValue;
                GPair.Set_Value = 0;
                GPair.Graphic   = "/images/HomeSeer/contemporary/away.png";
                hs.DeviceVGP_AddPair(dvRef, GPair);

                GPair.Set_Value = 1;
                GPair.Graphic   = "/images/HomeSeer/contemporary/home.png";
                hs.DeviceVGP_AddPair(dvRef, GPair);

                GPair.Set_Value = 2;
                GPair.Graphic   = "/images/HomeSeer/contemporary/userclosing.png";
                hs.DeviceVGP_AddPair(dvRef, GPair);

                break;
            }
            }

            return(true);
        }
Esempio n. 7
0
        static internal void Find_Create_Thermostats(EcobeeData ecobeeData, List <DeviceDataPoint> deviceList, EcobeeConnection ecobee)
        {
            bool          create     = false;
            bool          associates = false;
            List <string> tStrings   = getThermostatStrings();

            try
            {
                foreach (var thermostat in ecobeeData.thermostatList)
                {
                    foreach (var tString in tStrings)
                    {
                        create = Thermostat_Devices(tString, thermostat, deviceList, ecobee);
                        if (create) // True if a device was created
                        {
                            associates = true;
                        }
                    }
                    foreach (var remote in thermostat.remoteSensors)
                    {
                        if (remote.inUse && remote.name != thermostat.name)
                        {
                            foreach (var capability in remote.capabilityList)
                            {
                                if (capability.type.Equals("temperature") || capability.type.Equals("occupancy"))
                                {
                                    create = Remote_Devices(" Sensor", thermostat, remote, capability, deviceList, ecobee);
                                    if (create) // True if a device was created
                                    {
                                        associates = true;
                                    }
                                }
                            }
                        }
                    }
                }
                if (associates)
                {
                    SetAssociatedDevices("Thermostats");
                }
            }
            catch (Exception ex)
            {
                Log("Exception in Find_Create_Thermostats: " + ex.Message, LogType.LOG_TYPE_ERROR);
                System.IO.File.WriteAllText(@"Data/hspi_ecobeesiid/debug.txt", ex.ToString());
            }
        }
Esempio n. 8
0
        static internal void Update_RemoteDevice(Thermostat thermostat, SensorCapabilities capability, DeviceDataPoint ddPoint, EcobeeConnection ecobee)
        {
            string name;
            string id = GetDeviceKeys(ddPoint.device, out name);


            if (name.Equals("Temperature Sensor"))
            {
                if (capability.value != "unknown")
                {
                    var temp = Int16.Parse(capability.value) / 10;
                    hs.SetDeviceValueByRef(ddPoint.dvRef, temp, true);
                }
                else
                {
                    hs.SetDeviceString(ddPoint.dvRef, "unknown", true);
                }
                ddPoint.device.set_ScaleText(hs, thermostat.settings.useCelsius ? "C" : "F");
            }
            if (name.Equals("Occupancy Sensor"))
            {
                if (capability.value.Equals("true"))
                {
                    hs.SetDeviceValueByRef(ddPoint.dvRef, 1, true);
                }
                else
                {
                    hs.SetDeviceValueByRef(ddPoint.dvRef, 0, true);
                }
            }
        }
Esempio n. 9
0
        static internal void Update_ThermostatDevice(Thermostat thermostat, DeviceDataPoint ddPoint, EcobeeConnection ecobee)
        {
            string name;
            string id = GetDeviceKeys(ddPoint.device, out name);

            ThermostatEvent thermEvent  = null;
            var             eventExists = false;

            if (thermostat.events != null || thermostat.events.Count() != 0)
            {
                foreach (var tEvent in thermostat.events)
                {
                    if (tEvent.running)
                    {
                        thermEvent  = tEvent;
                        eventExists = true;
                    }
                }
            }

            switch (name)
            {
            case "Ambient Temperature":
            {
                hs.SetDeviceValueByRef(ddPoint.dvRef, Math.Ceiling(Convert.ToDouble(thermostat.runtime.actualTemperature) / 10), true);
                ddPoint.device.set_ScaleText(hs, thermostat.settings.useCelsius ? "C" : "F");

                break;
            }

            case "Humidity":
            {
                hs.SetDeviceValueByRef(ddPoint.dvRef, thermostat.runtime.actualHumidity, true);
                break;
            }

            case "Cool Range":
            {
                var range = thermostat.settings.coolRangeLow / 10 + " - " + thermostat.settings.coolRangeHigh / 10 + " " + getTemperatureUnits(thermostat.settings.useCelsius);
                hs.SetDeviceString(ddPoint.dvRef, range, true);
                break;
            }

            case "Heat Range":
            {
                var range = thermostat.settings.heatRangeLow / 10 + " - " + thermostat.settings.heatRangeHigh / 10 + " " + getTemperatureUnits(thermostat.settings.useCelsius);
                hs.SetDeviceString(ddPoint.dvRef, range, true);
                break;
            }

            case "HVAC Mode":
            {
                switch (thermostat.settings.hvac_mode)
                {
                case "off":
                    hs.SetDeviceValueByRef(ddPoint.dvRef, 0, true);
                    break;

                case "auto":
                    hs.SetDeviceValueByRef(ddPoint.dvRef, 1, true);
                    break;

                case "cool":
                    hs.SetDeviceValueByRef(ddPoint.dvRef, 2, true);
                    break;

                case "heat":
                    hs.SetDeviceValueByRef(ddPoint.dvRef, 3, true);
                    break;
                }
                break;
            }

            case "HVAC Status":
            {
                hs.SetDeviceString(ddPoint.dvRef, thermostat.settings.hvac_mode, true);
                break;
            }

            case "Fan Mode":
            {
                switch (thermostat.runtime.desiredFanMode)
                {
                case null:
                case "off":
                    hs.SetDeviceValueByRef(ddPoint.dvRef, 0, true);
                    break;

                case "on":
                    hs.SetDeviceValueByRef(ddPoint.dvRef, 1, true);
                    break;

                case "auto":
                    hs.SetDeviceValueByRef(ddPoint.dvRef, 2, true);
                    break;
                }

                break;
            }

            case "Fan Status":
            {
                hs.SetDeviceString(ddPoint.dvRef, thermostat.runtime.desiredFanMode, true);

                break;
            }

            case "Deadband":
            {
                hs.SetDeviceValueByRef(ddPoint.dvRef, Math.Ceiling(Convert.ToDouble((thermostat.runtime.desiredCool - thermostat.runtime.desiredHeat)) / 10), true);
                ddPoint.device.set_ScaleText(hs, thermostat.settings.useCelsius ? "C" : "F");

                break;
            }

            case "Target Temperature High":
            {
                if (eventExists)
                {
                    hs.SetDeviceValueByRef(ddPoint.dvRef, Math.Ceiling(Convert.ToDouble(thermEvent.coolHoldTemp) / 10), true);
                }
                else
                {
                    hs.SetDeviceValueByRef(ddPoint.dvRef, Math.Ceiling(Convert.ToDouble(thermostat.runtime.desiredCool) / 10), true);
                }
                ddPoint.device.set_ScaleText(hs, thermostat.settings.useCelsius ? "C" : "F");

                break;
            }

            case "Target Temperature Low":
            {
                if (eventExists)
                {
                    hs.SetDeviceValueByRef(ddPoint.dvRef, Math.Ceiling(Convert.ToDouble(thermEvent.heatHoldTemp) / 10), true);
                }
                else
                {
                    hs.SetDeviceValueByRef(ddPoint.dvRef, Math.Ceiling(Convert.ToDouble(thermostat.runtime.desiredHeat) / 10), true);
                }
                ddPoint.device.set_ScaleText(hs, thermostat.settings.useCelsius ? "C" : "F");

                break;
            }

            case "Current Program":
            {
                if (eventExists)
                {
                    switch (thermEvent.type)
                    {
                    case "hold":
                        hs.SetDeviceValueByRef(ddPoint.dvRef, 0, true);
                        break;

                    case "demandResponse":
                        hs.SetDeviceValueByRef(ddPoint.dvRef, 1, true);
                        break;

                    case "sensor":
                        hs.SetDeviceValueByRef(ddPoint.dvRef, 2, true);
                        break;

                    case "switchOccupancy":
                        hs.SetDeviceValueByRef(ddPoint.dvRef, 3, true);
                        break;

                    case "vacation":
                        hs.SetDeviceValueByRef(ddPoint.dvRef, 4, true);
                        break;

                    case "quickSave":
                        hs.SetDeviceValueByRef(ddPoint.dvRef, 5, true);
                        break;

                    case "today":
                        hs.SetDeviceValueByRef(ddPoint.dvRef, 6, true);
                        break;

                    case "template":
                        hs.SetDeviceValueByRef(ddPoint.dvRef, 7, true);
                        break;
                    }
                }
                else
                {
                    hs.SetDeviceValueByRef(ddPoint.dvRef, 0, true);
                }
                break;
            }

            case "Occupancy":
            {
                if (eventExists)
                {
                    if (thermostat.events[0].isOccupied)
                    {
                        hs.SetDeviceValueByRef(ddPoint.dvRef, 1, true);
                    }
                    else
                    {
                        hs.SetDeviceValueByRef(ddPoint.dvRef, 0, true);
                    }
                }
                else
                {
                    hs.SetDeviceValueByRef(ddPoint.dvRef, 2, true);
                }

                break;
            }
            }
        }
Esempio n. 10
0
        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);
                }
            }
        }