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); } }
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); } }
/// <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); } }
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); } }
/// <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); } }
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); } }