Exemple #1
0
 public void LightsAction(string lvltype, string val, string effect)
 {
     try
     {
         if (HueBridge.Authorized == true && HueBridge.Populated == true)
         {
             Payload payload = new Payload()
             {
                 SetType = "lights", LvlType = lvltype, OnOff = val, Effect = effect
             };
             string json        = HueBridge.SetCmd(PayloadType.BulbOnOff, payload, BulbId);
             JArray JReturn     = JArray.Parse(json);
             string tokenreturn = "/lights/" + BulbId + "/state/on";
             foreach (var Jobj in JReturn)
             {
                 var    myaction   = Jobj["success"];
                 string whodidwhat = myaction.ToString();
                 if (whodidwhat.Contains(tokenreturn))
                 {
                     HueBridge.HueBulbs[_bulbListId].On = (bool)myaction[tokenreturn];
                     BulbIsOn = (ushort)(HueBridge.HueBulbs[_bulbListId].On ? 1 : 0);
                     TriggerBulbOnOffUpdate();
                 }
             }
         }
         else
         {
             CrestronConsole.PrintLine("Error with Bulb Action {0}", BulbName);
         }
     }
     catch (Exception e)
     {
         CrestronConsole.PrintLine("Exception is {0}", e);
     }
 }
Exemple #2
0
 public void RecallScene(ushort i)
 {
     try
     {
         if (HueBridge.Authorized == true && HueBridge.Populated == true)
         {
             Payload payload = new Payload()
             {
                 SetType = "groups", Scene = this.SceneId[i]
             };
             string json = HueBridge.SetCmd(PayloadType.Scene, payload, RoomId);
             //CrestronConsole.PrintLine("json response: {0}",json);
             if (json.Contains("success"))
             {
                 CrestronConsole.PrintLine("Scene changed");
             }
         }
         else
         {
             CrestronConsole.PrintLine("Bridge not authorized");
         }
     }
     catch (Exception e)
     {
         CrestronConsole.PrintLine("Exception is {0}", e);
     }
 }
Exemple #3
0
 /// <summary>
 /// Sets a group to be on/off/scene select
 /// </summary>
 /// <param name="action">"true", "false", "scene"</param>
 /// <param name="lvltype"></param>
 /// <param name="val"></param>
 /// <param name="effect"></param>
 public void GroupAction(string lvltype, string val, string effect)
 {
     try
     {
         if (HueBridge.Authorized == true && HueBridge.Populated == true)
         {
             Payload payload = new Payload()
             {
                 SetType = "groups", LvlType = lvltype, OnOff = val, Effect = effect
             };
             string json        = HueBridge.SetCmd(PayloadType.RoomOnOff, payload, RoomId);
             JArray JReturn     = JArray.Parse(json);
             string tokenreturn = "/groups/" + RoomId + "/action/on";
             foreach (var Jobj in JReturn)
             {
                 var    myaction   = Jobj["success"];
                 string whodidwhat = myaction.ToString();
                 if (whodidwhat.Contains(tokenreturn))
                 {
                     HueBridge.HueGroups[RoomId - 1].On = (bool)myaction[tokenreturn];
                     GroupIsOn = (ushort)(HueBridge.HueGroups[RoomId - 1].On ? 1 : 0);
                     TriggerRoomOnOffUpdate();
                 }
             }
         }
         else
         {
             CrestronConsole.PrintLine("Bridge not authorized");
         }
     }
     catch (Exception e)
     {
         CrestronConsole.PrintLine("Exception is {0}", e);
     }
 }
Exemple #4
0
 /// <summary>
 /// Registers the app to the bridge, if API key already exists in datastore will pull
 /// </summary>
 public void Register()
 {
     try
     {
         HueBridge.SetupDataStore();
         string tempapi;
         tempapi = HueBridge.GetDataStore();
         if (HueBridge.LocalKey == true)
         {
             HueBridge.BridgeApi  = tempapi;
             HueBridge.Authorized = true;
             Authorized           = (ushort)(HueBridge.Authorized ? 1 : 0);
         }
         else
         {
             HueBridge.Register();
             Authorized = (ushort)(HueBridge.Authorized ? 1 : 0);
         }
         APIKey = HueBridge.BridgeApi;
         HueBridge.HueBulbs.Clear();
         HueBridge.HueGroups.Clear();
         HueBridge.HueSensors.Clear();
         getData();
     }
     catch (Exception e)
     {
         CrestronConsole.PrintLine("Exception is {0}", e);
     }
 }
Exemple #5
0
 /// <summary>
 /// Registers the app to the bridge, if API key already exists in datastore will pull
 /// </summary>
 public void Register()
 {
     try
     {
         HueBridge.SetupDataStore();
         string tempapi;
         tempapi = HueBridge.GetDataStore();
         if (tempapi != null)
         {
             HueBridge.BridgeApi  = tempapi;
             HueBridge.Authorized = true;
             Authorized           = (ushort)(HueBridge.Authorized ? 1 : 0);
         }
         else
         {
             HueBridge.register();
             Authorized = (ushort)(HueBridge.Authorized ? 1 : 0);
         }
         APIKey = HueBridge.BridgeApi;
     }
     catch (Exception e)
     {
         CrestronConsole.PrintLine("Exception is {0}", e);
     }
 }
Exemple #6
0
        /// <summary>
        /// Pulls all the bulbs and their current state from the bridge
        /// </summary>
        public void ProcBulbs(string jsondata)
        {
            try
            {
                JObject json = JObject.Parse(jsondata);
                HueBridge.HueBulbs.Clear();
                foreach (var bulb in json)
                {
                    string id  = bulb.Key;
                    uint   hue = 0;
                    uint   sat = 0;
                    uint   ct  = 0;
                    string colormode;
                    bool   on           = (bool)json[id]["state"]["on"];
                    uint   bri          = (uint)json[id]["state"]["bri"];
                    string type         = (string)json[id]["type"];
                    string name         = (string)json[id]["name"];
                    string model        = (string)json[id]["modelid"];
                    string manufacturer = (string)json[id]["manufacturername"];
                    string uid          = (string)json[id]["uniqueid"];
                    string swver        = (string)json[id]["swversion"];
                    bool   reachable    = (bool)json[id]["state"]["reachable"];
                    if (json[id]["state"].SelectToken("colormode") != null)
                    {
                        colormode = (string)json[id]["state"]["colormode"];
                        if (json[id]["state"].SelectToken("hue") != null)
                        {
                            hue = (uint)json[id]["state"]["hue"];
                        }
                        if (json[id]["state"].SelectToken("sat") != null)
                        {
                            sat = (uint)json[id]["state"]["sat"];
                        }
                        if (json[id]["state"].SelectToken("ct") != null)
                        {
                            ct = (uint)json[id]["state"]["ct"];
                        }
                        HueBridge.HueBulbs.Add(new HueBulb(id, on, bri, hue, sat, ct, type, name, model, manufacturer, uid, swver, colormode, reachable));
                    }
                    else
                    {
                        HueBridge.HueBulbs.Add(new HueBulb(id, on, bri, type, name, model, manufacturer, uid, swver, reachable));
                    }
                }

                /*
                 * foreach (var bulb in HueBridge.HueBulbs)
                 * {
                 *      CrestronConsole.PrintLine("Bulb Name: {0}, Bulb ID: {1}", bulb.Name, bulb.Id);
                 * }*/
                BulbNum = (ushort)HueBridge.HueBulbs.Count;
                CrestronConsole.PrintLine("{0} Bulbs discovered", BulbNum);
                HueBridge.GetBridgeInfo("groups");
            }
            catch (Exception e)
            {
                CrestronConsole.PrintLine("Error getting bulbs: {0}", e);
            }
        }
Exemple #7
0
        public void LightsVal(string lvltype, ushort val)
        {
            try
            {
                if (HueBridge.Authorized == true)
                {
                    var payload = new Payload()
                    {
                        SetType = "lights", Lvl = val, LvlType = lvltype
                    };
                    var json = HueBridge.SetCmd(PayloadType.Lvl, payload, BulbId);
                    //CrestronConsole.PrintLine("json: {0}",json);
                    if (json.Contains("success"))
                    {
                        var jData   = JArray.Parse(json);
                        var nodeVal = "/" + payload.SetType + "/" + BulbId + "/" + payload.CmdType + "/" + lvltype;
                        switch (lvltype)
                        {
                        case "bri":
                        {
                            HueBridge.HueBulbs[_bulbListId].Bri = (uint)jData[0]["success"][nodeVal];
                            BulbBri = (ushort)HueBridge.HueBulbs[_bulbListId].Bri;
                            TriggerBulbBriUpdate();
                            break;
                        }

                        case "hue":
                        {
                            HueBridge.HueBulbs[_bulbListId].Hue = (uint)jData[0]["success"][nodeVal];
                            BulbHue = (ushort)HueBridge.HueBulbs[_bulbListId].Hue;
                            TriggerBulbHueUpdate();
                            break;
                        }

                        case "sat":
                        {
                            HueBridge.HueBulbs[_bulbListId].Sat = (uint)jData[0]["success"][nodeVal];
                            BulbSat = (ushort)HueBridge.HueBulbs[_bulbListId].Sat;
                            TriggerBulbSatUpdate();
                            break;
                        }

                        default:
                            break;
                        }
                    }
                }
                else
                {
                    CrestronConsole.PrintLine("Bridge not authorized");
                }
            }
            catch (Exception e)
            {
                CrestronConsole.PrintLine("Exception is {0}", e);
            }
        }
Exemple #8
0
        /// <summary>
        /// test
        /// </summary>
        /// <param name="settype"></param>
        /// <param name="lvltype"></param>
        /// <param name="val"></param>
        public void LightsVal(string lvltype, ushort val)
        {
            try
            {
                if (HueBridge.Authorized == true && HueBridge.Populated == true)
                {
                    var payload = new Payload()
                    {
                        SetType = "groups", Lvl = val, LvlType = lvltype
                    };
                    var json = HueBridge.SetCmd(PayloadType.Lvl, payload, RoomId);

                    if (json.Contains("success"))
                    {
                        var jData   = JArray.Parse(json);
                        var nodeVal = "/" + payload.SetType + "/" + RoomId + "/" + payload.CmdType + "/" + lvltype;
                        switch (lvltype)
                        {
                        case "bri":
                        {
                            _room.Bri = (uint)jData[0]["success"][nodeVal];
                            RoomBri   = (ushort)_room.Bri;
                            TriggerRoomBriUpdate();
                            break;
                        }

                        case "hue":
                        {
                            _room.Hue = (uint)jData[0]["success"][nodeVal];
                            RoomHue   = (ushort)_room.Hue;
                            TriggerRoomHueUpdate();
                            break;
                        }

                        case "sat":
                        {
                            _room.Sat = (uint)jData[0]["success"][nodeVal];
                            RoomSat   = (ushort)_room.Sat;
                            TriggerRoomSatUpdate();
                            break;
                        }

                        default:
                            break;
                        }
                    }
                }
                else
                {
                    CrestronConsole.PrintLine("Bridge not authorized");
                }
            }
            catch (Exception e)
            {
                CrestronConsole.PrintLine("Exception is {0}", e);
            }
        }
Exemple #9
0
 /// <summary>
 /// gets bridge IP from the broker server www.meethue.com/api/nupnp
 /// </summary>
 public void getIP()
 {
     try
     {
         IPAddress = HueBridge.GetIp();
     }
     catch (Exception e)
     {
         CrestronConsole.PrintLine("Exception: {0}", e);
     }
 }
Exemple #10
0
        /// <summary>
        /// Pulls all the groups/rooms from the bridge
        /// </summary>
        public void ProcRooms(string jsondata)
        {
            try
            {
                JObject json = JObject.Parse(jsondata);
                HueBridge.HueGroups.Clear();
                foreach (var group in json)
                {
                    string   load;
                    uint     bri;
                    JArray   loadList;
                    string[] loads;
                    string   roomclass;
                    string   type;
                    string   id = group.Key;
                    if ((string)json[id]["type"] == "Room")
                    {
                        string name = (string)json[id]["name"];
                        roomclass = (string)json[id]["class"];
                        type      = (string)json[id]["type"];
                        bri       = 0;
                        if (json[id]["lights"].HasValues)
                        {
                            load     = (string)json[id]["lights"][0];
                            loadList = (JArray)json[id]["lights"];
                            loads    = loadList.ToObject <string[]>();
                            if (json[id]["action"].SelectToken("bri") != null)
                            {
                                bri = (uint)json[id]["action"]["bri"];
                            }
                        }
                        else
                        {
                            load  = "0";
                            loads = null;
                            CrestronConsole.PrintLine("No lights in {0}", name);
                        }

                        bool on = (bool)json[group.Key]["action"]["on"];
                        HueBridge.HueGroups.Add(new HueGroup(id, name, type, on, bri, load, loads, roomclass));
                    }
                }
                GroupNum = (ushort)HueBridge.HueGroups.Count;
                CrestronConsole.PrintLine("{0} Rooms discovered", GroupNum);
                if (Authorized == 1)
                {
                    HueBridge.GetBridgeInfo("scenes");
                }
            }
            catch (Exception e)
            {
                CrestronConsole.PrintLine("Error getting rooms: {0}", e);
            }
        }
Exemple #11
0
        /// <summary>
        /// test
        /// </summary>
        /// <param name="settype"></param>
        /// <param name="lvltype"></param>
        /// <param name="val"></param>
        public void LightsVal(string settype, string lvltype, ushort val)
        {
            try
            {
                if (HueBridge.Authorized == true && HueBridge.Populated == true)
                {
                    String cmdval = "{\"" + lvltype + "\":" + val.ToString() + "}";
                    String json   = HueBridge.SetLvl(settype, RoomID, "action", cmdval);
                    if (json.Contains("success"))
                    {
                        JArray JData   = JArray.Parse(json);
                        string NodeVal = "/" + settype + "/" + RoomID + "/action/" + lvltype;
                        switch (lvltype)
                        {
                        case "bri":
                        {
                            HueBridge.HueGroups[RoomID - 1].Bri = (uint)JData[0]["success"][NodeVal];
                            RoomBri = (ushort)HueBridge.HueGroups[RoomID - 1].Bri;
                            TriggerRoomBriUpdate();
                            break;
                        }

                        case "hue":
                        {
                            HueBridge.HueGroups[RoomID - 1].Hue = (uint)JData[0]["success"][NodeVal];
                            RoomHue = (ushort)HueBridge.HueGroups[RoomID - 1].Hue;
                            TriggerRoomHueUpdate();
                            break;
                        }

                        case "sat":
                        {
                            HueBridge.HueGroups[RoomID - 1].Sat = (uint)JData[0]["success"][NodeVal];
                            RoomSat = (ushort)HueBridge.HueGroups[RoomID - 1].Sat;
                            TriggerRoomSatUpdate();
                            break;
                        }

                        default:
                            break;
                        }
                    }
                }
                else
                {
                    CrestronConsole.PrintLine("Bridge not authorized");
                }
            }
            catch (Exception e)
            {
                CrestronConsole.PrintLine("Exception is {0}", e);
            }
        }
Exemple #12
0
 /// <summary>
 /// Pulls all the bulbs and their current state from the bridge
 /// </summary>
 ushort getBulbs()
 {
     try
     {
         if (HueBridge.Authorized == true)
         {
             string  json  = HueBridge.GetBridgeInfo("lights");
             JObject JData = JObject.Parse(json);
             HueBridge.HueBulbs.Clear();
             foreach (var bulb in JData)
             {
                 string id           = bulb.Key;
                 bool   on           = (bool)JData[id]["state"]["on"];
                 uint   bri          = (uint)JData[id]["state"]["bri"];
                 string alert        = (string)JData[id]["state"]["alert"];
                 bool   reachable    = (bool)JData[id]["state"]["reachable"];
                 string type         = (string)JData[id]["type"];
                 string name         = (string)JData[id]["name"];
                 string model        = (string)JData[id]["modelid"];
                 string manufacturer = (string)JData[id]["manufacturername"];
                 string uid          = (string)JData[id]["uniqueid"];
                 string swver        = (string)JData[id]["swversion"];
                 if (type.Contains("color") || type.Contains("Color"))
                 {
                     uint hue = (uint)JData[id]["state"]["hue"];
                     uint sat = (uint)JData[id]["state"]["sat"];
                     HueBridge.HueBulbs.Add(new HueBulb(id, on, bri, hue, sat, alert, reachable, type, name, model, manufacturer, uid, swver));
                 }
                 else
                 {
                     HueBridge.HueBulbs.Add(new HueBulb(id, on, bri, alert, reachable, type, name, model, manufacturer, uid, swver));
                 }
             }
             BulbNum = (ushort)HueBridge.HueBulbs.Count;
             CrestronConsole.PrintLine("{0} Bulbs discovered", BulbNum);
             return(1);
         }
         else
         {
             CrestronConsole.PrintLine("Bridge not authorized");
             return(0);
         }
     }
     catch (Exception e)
     {
         CrestronConsole.PrintLine("Error getting bulbs {0}", e);
         return(0);
     }
 }
        public void LightsVal(string settype, string lvltype, ushort val)
        {
            try
            {
                if (HueBridge.Authorized == true)
                {
                    String cmdval = "{\"" + lvltype + "\":" + val.ToString() + "}";
                    String json   = HueBridge.SetLvl(settype, BulbID, "state", cmdval);
                    if (json.Contains("success"))
                    {
                        JArray JData   = JArray.Parse(json);
                        string NodeVal = "/" + settype + "/" + BulbID + "/state/" + lvltype;
                        HueBridge.HueBulbs[BulbID - 1].Bri = (uint)JData[0]["success"][NodeVal];
                        switch (lvltype)
                        {
                        case "bri":
                        {
                            BulbBri = (ushort)HueBridge.HueBulbs[BulbID - 1].Bri;
                            break;
                        }

                        case "hue":
                        {
                            BulbHue = (ushort)HueBridge.HueBulbs[BulbID - 1].Hue;
                            break;
                        }

                        case "sat":
                        {
                            BulbSat = (ushort)HueBridge.HueBulbs[BulbID - 1].Sat;
                            break;
                        }

                        default:
                            break;
                        }
                    }
                }
                else
                {
                    CrestronConsole.PrintLine("Bridge not authorized");
                }
            }
            catch (Exception e)
            {
                CrestronConsole.PrintLine("Exception is {0}", e);
            }
        }
Exemple #14
0
        /// <summary>
        /// Sets a group to be on/off/scene select
        /// </summary>
        /// <param name="action">"true", "false", "scene"</param>
        public void GroupAction(string actiontype, string actioncmd, string effect)
        {
            try
            {
                if (HueBridge.Authorized == true && HueBridge.Populated == true)
                {
                    String json        = HueBridge.SetOnOff("groups", RoomID, actioncmd, "action", effect);
                    JArray JReturn     = JArray.Parse(json);
                    string tokenreturn = "/groups/" + RoomID + "/action/" + actiontype;
                    foreach (var Jobj in JReturn)
                    {
                        var    myaction   = Jobj["success"];
                        string whodidwhat = myaction.ToString();
                        if (whodidwhat.Contains(tokenreturn))
                        {
                            HueBridge.HueGroups[RoomID - 1].On = (bool)myaction[tokenreturn];
                            GroupIsOn = (ushort)(HueBridge.HueGroups[RoomID - 1].On ? 1 : 0);
                        }
                    }

                    /*
                     * for (int i = 0; i < JReturn.Count; i++)
                     * {
                     *  if (json.Contains("success"))
                     *  {
                     *      var JData = JReturn[i].SelectToken("success");
                     *      //string tokenreturn = "/groups/" + RoomID + "/action/" + actiontype;
                     *      string tokenreturn = "/groups/" + RoomID + "/action/on";
                     *      if (JData.Contains(tokenreturn))
                     *      {
                     *
                     *          break;
                     *      }
                     *  }
                     * }*/
                }
                else
                {
                    CrestronConsole.PrintLine("Bridge not authorized");
                }
            }
            catch (Exception e)
            {
                CrestronConsole.PrintLine("Exception is {0}", e);
            }
        }
Exemple #15
0
 public void XYVal(string settype, ushort xval, ushort yval)
 {
     try
     {
         if (HueBridge.Authorized == true && HueBridge.Populated == true)
         {
             decimal x      = (decimal)xval / 100;
             decimal y      = (decimal)yval / 100;
             String  cmdval = "{\"xy\":[" + x.ToString() + "," + y.ToString() + "]}";
             String  json   = HueBridge.SetLvl(settype, RoomID, "action", cmdval);
         }
     }
     catch (Exception e)
     {
         CrestronConsole.PrintLine("Exception is {0}", e);
     }
 }
Exemple #16
0
 /// <summary>
 /// Pulls all the scenes from the bridge and assigns them to their appropriate room based on the assigned bulbs
 /// </summary>
 ushort getScenes()
 {
     try
     {
         if (HueBridge.Authorized == true)
         {
             string  json  = HueBridge.GetBridgeInfo("scenes");
             JObject JData = JObject.Parse(json);
             HueBridge.HueScenes.Clear();
             foreach (var scene in JData)
             {
                 string id   = scene.Key;
                 string name = (string)JData[id]["name"];
                 string load = (string)JData[id]["lights"][0];
                 for (int x = 0; x < (HueBridge.HueGroups.Count); x++)
                 {
                     if (HueBridge.HueGroups[x].loads.Contains(load))
                     {
                         for (int y = 1; y < 20; y++)
                         {
                             if (HueBridge.HueGroups[x].SceneName[y] == null)
                             {
                                 HueBridge.HueGroups[x].SceneName[y] = name;
                                 HueBridge.HueGroups[x].SceneID[y]   = id;
                                 break;
                             }
                         }
                     }
                 }
             }
             CrestronConsole.PrintLine("{0} Scenes discovered", JData.Count);
             return(1);
         }
         else
         {
             CrestronConsole.PrintLine("Bridge not authorized");
             return(0);
         }
     }
     catch (Exception e)
     {
         CrestronConsole.PrintLine("Error getting scenes: {0}", e);
         return(0);
     }
 }
Exemple #17
0
 public void XYVal(ushort xval, ushort yval)
 {
     try
     {
         if (HueBridge.Authorized == true && HueBridge.Populated == true)
         {
             Payload payload = new Payload()
             {
                 SetType = "groups", Xval = xval, Yval = yval
             };
             string json = HueBridge.SetCmd(PayloadType.XY, payload, RoomId);
         }
     }
     catch (Exception e)
     {
         CrestronConsole.PrintLine("Exception is {0}", e);
     }
 }
Exemple #18
0
 /// <summary>
 /// Gets bridge data starting with lights
 /// </summary>
 public void getData()
 {
     try
     {
         if (HueBridge.Authorized)
         {
             HueBridge.GetBridgeInfo("lights");
         }
         else
         {
             CrestronConsole.PrintLine("Bridge not authorized");
         }
     }
     catch (Exception e)
     {
         CrestronConsole.PrintLine("Error getting bulbs {0}", e);
     }
 }
Exemple #19
0
        /// <summary>
        /// Pulls all the groups/rooms from the bridge
        /// </summary>
        ushort getRooms()
        {
            try
            {
                if (HueBridge.Authorized == true)
                {
                    string  json  = HueBridge.GetBridgeInfo("groups");
                    JObject JData = JObject.Parse(json);
                    HueBridge.HueGroups.Clear();
                    foreach (var group in JData)
                    {
                        string   id       = group.Key;
                        string   name     = (string)JData[group.Key]["name"];
                        string   load     = (string)JData[group.Key]["lights"][0];
                        JArray   LoadList = (JArray)JData[group.Key]["lights"];
                        string[] loads    = LoadList.ToObject <string[]>();
                        string   type     = (string)JData[group.Key]["type"];
                        bool     on       = (bool)JData[group.Key]["action"]["on"];
                        uint     bri      = (uint)JData[group.Key]["action"]["bri"];
                        string   alert    = (string)JData[group.Key]["action"]["alert"];
                        HueBridge.HueGroups.Add(new HueGroup(name, type, on, bri, alert, load, loads));
                    }
                    for (int i = 0; i < JData.Count; i++)
                    {
                        Array.Clear(HueBridge.HueGroups[i].SceneName, 0, 20);
                        Array.Clear(HueBridge.HueGroups[i].SceneID, 0, 20);
                    }

                    GroupNum = (ushort)HueBridge.HueGroups.Count;
                    CrestronConsole.PrintLine("{0} Rooms discovered", GroupNum);
                    return(1);
                }
                else
                {
                    CrestronConsole.PrintLine("Bridge not authorized");
                    return(0);
                }
            }
            catch (Exception e)
            {
                CrestronConsole.PrintLine("Error getting rooms: {0}", e);
                return(0);
            }
        }
        /// <summary>
        /// Pulls all the groups/rooms from the bridge
        /// </summary>
        public void ProcRooms(String jsondata)
        {
            try
            {
                JObject jData = JObject.Parse(jsondata);
                HueBridge.HueGroups.Clear();
                foreach (var group in jData)
                {
                    string   load;
                    JArray   LoadList;
                    string[] loads;
                    string   id   = group.Key;
                    string   name = (string)jData[group.Key]["name"];
                    if (jData[group.Key]["lights"].HasValues)
                    {
                        load     = (string)jData[group.Key]["lights"][0];
                        LoadList = (JArray)jData[group.Key]["lights"];
                        loads    = LoadList.ToObject <string[]>();
                    }
                    else
                    {
                        load  = "0";
                        loads = null;
                    }

                    string type  = (string)jData[group.Key]["type"];
                    bool   on    = (bool)jData[group.Key]["action"]["on"];
                    uint   bri   = (uint)jData[group.Key]["action"]["bri"];
                    string alert = (string)jData[group.Key]["action"]["alert"];
                    HueBridge.HueGroups.Add(new HueGroup(id, name, type, on, bri, alert, load, loads));
                }
                GroupNum = (ushort)HueBridge.HueGroups.Count;
                CrestronConsole.PrintLine("{0} Rooms discovered", GroupNum);
                HueBridge.GetBridgeInfo("scenes");
            }
            catch (Exception e)
            {
                CrestronConsole.PrintLine("Error getting rooms: {0}", e);
            }
        }
 /// <summary>
 /// Pulls all the bulbs and their current state from the bridge
 /// </summary>
 public void ProcBulbs(String jsondata)
 {
     try
     {
         JObject jData = JObject.Parse(jsondata);
         HueBridge.HueBulbs.Clear();
         foreach (var bulb in jData)
         {
             string id           = bulb.Key;
             bool   on           = (bool)jData[id]["state"]["on"];
             uint   bri          = (uint)jData[id]["state"]["bri"];
             string alert        = (string)jData[id]["state"]["alert"];
             bool   reachable    = (bool)jData[id]["state"]["reachable"];
             string type         = (string)jData[id]["type"];
             string name         = (string)jData[id]["name"];
             string model        = (string)jData[id]["modelid"];
             string manufacturer = (string)jData[id]["manufacturername"];
             string uid          = (string)jData[id]["uniqueid"];
             string swver        = (string)jData[id]["swversion"];
             if (type.Contains("color") || type.Contains("Color"))
             {
                 uint hue = (uint)jData[id]["state"]["hue"];
                 uint sat = (uint)jData[id]["state"]["sat"];
                 HueBridge.HueBulbs.Add(new HueBulb(id, on, bri, hue, sat, alert, reachable, type, name, model, manufacturer, uid, swver));
             }
             else
             {
                 HueBridge.HueBulbs.Add(new HueBulb(id, on, bri, alert, reachable, type, name, model, manufacturer, uid, swver));
             }
         }
         BulbNum = (ushort)HueBridge.HueBulbs.Count;
         CrestronConsole.PrintLine("{0} Bulbs discovered", BulbNum);
         HueBridge.GetBridgeInfo("groups");
     }
     catch (Exception e)
     {
     }
 }
 public void LightsOn()
 {
     try
     {
         if (HueBridge.Authorized == true)
         {
             String json = HueBridge.SetOnOff("lights", BulbID, "true", "state", "none");
             if (json.Contains("success"))
             {
                 HueBridge.HueBulbs[BulbID - 1].On = true;
                 BulbIsOn = 1;
             }
         }
         else
         {
             CrestronConsole.PrintLine("Bridge not authorized");
         }
     }
     catch (Exception e)
     {
         CrestronConsole.PrintLine("Exception is {0}", e);
     }
 }
Exemple #23
0
 public void RecallScene(ushort i)
 {
     try
     {
         if (HueBridge.Authorized == true && HueBridge.Populated == true)
         {
             String payload = String.Format("{0}\"scene\":\"{1}\"{2}", '{', SceneID[i], '}');
             String json    = HueBridge.SetScene(RoomID, payload);
             if (json.Contains("success"))
             {
                 CrestronConsole.PrintLine("Scene changed");
             }
         }
         else
         {
             CrestronConsole.PrintLine("Bridge not authorized");
         }
     }
     catch (Exception e)
     {
         CrestronConsole.PrintLine("Exception is {0}", e);
     }
 }
Exemple #24
0
 /// <summary>
 /// reset the api key from the datastore
 /// </summary>
 public void ResetAPI()
 {
     HueBridge.ResetDataStore();
 }
Exemple #25
0
        /// <summary>
        /// Pulls all the bulbs and their current state from the bridge
        /// </summary>
        public void ProcBulbs(string jsondata)
        {
            try
            {
                JObject json = JObject.Parse(jsondata);
                HueBridge.HueBulbs.Clear();
                uint   hue;
                uint   sat;
                uint   ct;
                uint   bri;
                string colormode;
                string type;
                string name;
                string manufacturer;
                string uid;
                string swver;
                bool   reachable;
                string model;
                bool   on;
                int    index = 0;
                foreach (var bulb in json)
                {
                    string id = bulb.Key;
                    hue          = 0;
                    sat          = 0;
                    ct           = 0;
                    bri          = 0;
                    colormode    = "";
                    type         = "";
                    name         = "";
                    manufacturer = "";
                    uid          = "";
                    swver        = "";
                    reachable    = false;
                    model        = "";
                    on           = false;
                    if (json[id]["state"].SelectToken("on") != null)
                    {
                        on = (bool)json[id]["state"]["on"];
                    }
                    if (json[id]["state"].SelectToken("reachable") != null)
                    {
                        reachable = (bool)json[id]["state"]["reachable"];
                    }
                    if (json[id].SelectToken("type") != null)
                    {
                        type = (string)json[id]["type"];
                    }
                    if (json[id].SelectToken("name") != null)
                    {
                        name = (string)json[id]["name"];
                    }
                    if (json[id].SelectToken("modelid") != null)
                    {
                        model = (string)json[id]["modelid"];
                    }
                    if (json[id].SelectToken("manufacturername") != null)
                    {
                        manufacturer = (string)json[id]["manufacturername"];
                    }
                    if (json[id].SelectToken("uniqueid") != null)
                    {
                        uid = (string)json[id]["uniqueid"];
                    }
                    if (json[id].SelectToken("swversion") != null)
                    {
                        swver = (string)json[id]["swversion"];
                    }
                    HueBridge.HueBulbs.Add(new HueBulb()
                    {
                        Id = id, On = on, Type = type, Name = name, Model = model, Manufacturer = manufacturer, Uid = uid, SwVer = swver, Reachable = reachable
                    });
                    index = HueBridge.HueBulbs.Count - 1;
                    if (json[id]["state"].SelectToken("bri") != null)
                    {
                        bri = (uint)json[id]["state"]["bri"];
                        HueBridge.HueBulbs[index].Bri = bri;
                    }
                    if (json[id]["state"].SelectToken("colormode") != null)
                    {
                        colormode = (string)json[id]["state"]["colormode"];
                        HueBridge.HueBulbs[index].ColorMode = colormode;
                        if (json[id]["state"].SelectToken("hue") != null)
                        {
                            hue = (uint)json[id]["state"]["hue"];
                            HueBridge.HueBulbs[index].Hue = hue;
                        }
                        if (json[id]["state"].SelectToken("sat") != null)
                        {
                            sat = (uint)json[id]["state"]["sat"];
                            HueBridge.HueBulbs[index].Sat = sat;
                        }

                        if (json[id]["state"].SelectToken("ct") != null)
                        {
                            ct = (uint)json[id]["state"]["ct"];
                            HueBridge.HueBulbs[index].Ct = ct;
                        }
                    }
                }

                /*
                 * foreach (var bulb in HueBridge.HueBulbs)
                 * {
                 *      CrestronConsole.PrintLine("Bulb Name: {0}, Bulb ID: {1}", bulb.Name, bulb.Id);
                 * }*/
                BulbNum = (ushort)HueBridge.HueBulbs.Count;
                CrestronConsole.PrintLine("{0} Bulbs discovered", BulbNum);
                if (Authorized == 1)
                {
                    HueBridge.GetBridgeInfo("groups");
                }
            }
            catch (Exception e)
            {
                CrestronConsole.PrintLine("Error getting bulbs: {0}", e);
            }
        }
Exemple #26
0
 /// <summary>
 /// gets bridge IP from the broker server www.meethue.com/api/nupnp
 /// </summary>
 public void getIP()
 {
     IPAddress = HueBridge.getIP();
 }