// WILLR RETURN A LIST OF ALL THERMOSTATS WITH THIER NAME, STATE etc... public async Task<IEnumerable<Camera>> GetCameras() { var url = "https://developer-api.nest.com"; var fb = new Firebase(url, ACCESS_TOKEN); dynamic devices = await fb.GetAsync("devices/cameras"); // will return a string dynamic devicesJSON = JObject.Parse(devices); List<Camera> cameras = new List<Camera>(); foreach (dynamic device in devicesJSON) { // can use this to access properties of thermostat // i.e. device.First.humidity; var cameraJSON = device.First; Camera camera = new Camera(); camera.Device_Id = cameraJSON.device_id; camera.Name_Long = cameraJSON.name_long; camera.Is_Online = cameraJSON.is_online; camera.Is_Streaming = cameraJSON.is_streaming; cameras.Add(camera); } return cameras; }
// WILLR RETURN A LIST OF ALL THERMOSTATS WITH THIER NAME, STATE etc... public async Task<IEnumerable<SmokeCoAlarmVM>> GetCameras() { var url = "https://developer-api.nest.com"; var fb = new Firebase(url, ACCESS_TOKEN); dynamic devices = await fb.GetAsync("devices/smoke_co_alarms"); // will return a string dynamic devicesJSON = JObject.Parse(devices); List<SmokeCoAlarmVM> smokecoalarms = new List<SmokeCoAlarmVM>(); foreach (dynamic device in devicesJSON) { // can use this to access properties of thermostat // i.e. device.First.humidity; var smokecoalarmJSON = device.First; SmokeCoAlarmVM smokecoalarm = new SmokeCoAlarmVM(); smokecoalarm.Device_Id = smokecoalarmJSON.device_id; smokecoalarm.Name_Long = smokecoalarmJSON.name_long; smokecoalarm.Is_Online = smokecoalarmJSON.is_online; smokecoalarm.Smoke_Alarm_State= smokecoalarmJSON.smoke_alarm_state; smokecoalarm.Co_Alarm_State = smokecoalarmJSON.co_alarm_state; smokecoalarms.Add(smokecoalarm); } return smokecoalarms; }
// WILLR RETURN A LIST OF ALL THERMOSTATS WITH THIER NAME, STATE etc... public async Task<IEnumerable<ThermostatVM>> GetThermostats() { var url = "https://developer-api.nest.com"; var fb = new Firebase(url, ACCESS_TOKEN); dynamic devices = await fb.GetAsync("devices/thermostats"); // will return a string dynamic devicesJSON = JObject.Parse(devices); List<ThermostatVM> thermostats = new List<ThermostatVM>(); foreach(dynamic device in devicesJSON) { // can use this to access properties of thermostat // i.e. device.First.humidity; var thermostatJSON = device.First; ThermostatVM thermostat = new ThermostatVM(); thermostat.Device_Id = thermostatJSON.device_id; thermostat.Name_Long = thermostatJSON.name_long; thermostat.Current_Temperature = thermostatJSON.ambient_temperature_c; thermostat.Target_Temperature = thermostatJSON.target_temperature_c; thermostats.Add(thermostat); } return thermostats; }
public async Task <bool> AddNews(IEnumerable <ViewModels.News> news) { var rootUri = ConfigurationManager.AppSettings.Get("FirebaseUri"); var authToken = ConfigurationManager.AppSettings.Get("FirebaseAuthToken"); var fb = new FB.Firebase(rootUri, authToken); var data = await fb.PostAsync("news", JsonConvert.SerializeObject(news)); return(!string.IsNullOrEmpty(data)); }
private void Authentiate_Click(object sender, RoutedEventArgs e) { if (_resp != null) { _resp.Cancel(); } Firebase nest = new Firebase(new Uri("https://developer-api.nest.com"), TextNestAccessToken.Text); _resp = nest.GetStreaming("", Handler); }
private static void SubscribeToNestDeviceDataUpdates() { var firebaseClient = new Firebase("https://developer-api.nest.com", _accessToken); var response = firebaseClient.GetStreaming("devices", changed: (s, e) => { if (e.Path.Contains("ambient_temperature_f")) Console.WriteLine("Current temperature has been updated to: {0}.", e.Data); }); Console.WriteLine("Change the current temperature of the Nest Thermostat in the Nest Developer Chrome Extension to see the real-time updates."); }
public async Task<ThermostatVM> GetThermostat() { var url = "https://developer-api.nest.com"; var fb = new Firebase(url, ACCESS_TOKEN); dynamic devices = await fb.GetAsync("devices"); var jsonParsed = JsonConvert.DeserializeObject<dynamic>(devices); var thermostats = jsonParsed.thermostats; string dev_id = jsonParsed["thermostats"]["is8MQBKrH-h-UWxetdv7-o-BBzEt2ynq"].device_id; string name = jsonParsed["thermostats"]["is8MQBKrH-h-UWxetdv7-o-BBzEt2ynq"].name_long; string curr_temp = jsonParsed["thermostats"]["is8MQBKrH-h-UWxetdv7-o-BBzEt2ynq"].ambient_temperature_c; string tar_temp = jsonParsed["thermostats"]["is8MQBKrH-h-UWxetdv7-o-BBzEt2ynq"].target_temperature_c; ThermostatVM myThermostat = new ThermostatVM(dev_id, name, curr_temp, tar_temp); return myThermostat; }
/// <summary> /// Gets the news. /// </summary> /// <returns></returns> public async Task <IEnumerable <ViewModels.News> > GetNews() { var rootUri = ConfigurationManager.AppSettings.Get("FirebaseUri"); var authToken = ConfigurationManager.AppSettings.Get("FirebaseAuthToken"); var fb = new FB.Firebase(rootUri, authToken); var data = await fb.GetAsync("news"); try { var result = JsonConvert.DeserializeObject <IEnumerable <ViewModels.News> >(data); var select = result.Where(CurrentNews).OrderBy(s => s.Order); return(select); } catch (Exception exp) { } return(Enumerable.Empty <ViewModels.News>()); }
public async Task<JsonResult> SetThermostatTemp(string accessToken, string id, float temp) { // ambient_temperature_c var url = "https://developer-api.nest.com"; var fb = new Firebase(url, accessToken); /* string path = "/path"; string data = "{{\"value\": \"Hello!\"}}"; string id = fb.Post(path, data); */ string data = "{{\"ambient_tempeture_c\" : \"" + temp + "\"}}"; dynamic JSON = await fb.PostAsync("devices/thermostats/" + id , data); return Json(JSON, JsonRequestBehavior.AllowGet); }
//returns true if data has changed (used to try to determine when data streaming has stopped working) private Boolean GetNestData(string accessToken) { bool datachanged = false; if (!accessToken.Equals("")) { var firebaseClient = new Firebase("https://developer-api.nest.com", accessToken); //get structure data try { string structureData = firebaseClient.Get("structures"); dynamic data = JsonConvert.DeserializeObject<dynamic>(structureData); var myStructures = new List<Structure>(); foreach (var itemDynamic in data) myStructures.Add(JsonConvert.DeserializeObject<Structure>(((JProperty)itemDynamic).Value.ToString())); foreach (Structure structure in myStructures) { //if structure does not exist then add it if (!OSAEObjectManager.ObjectExists(structure.structure_id)) { Log.Debug("about to add structure: " + structure.name + " address: " + structure.structure_id + "."); OSAEObject _nameObject = OSAEObjectManager.GetObjectByName(structure.name); //OSAEObjectManager.GetObjectByAddress(structure.structure_id) if (_nameObject != null) Log.Error("Object with name: " + _nameObject.Name + " exists but it's address doesn't match - objects address: " + _nameObject.Address + ". - device_id from nest:" + structure.structure_id + "."); OSAEObjectManager.ObjectAdd(structure.name,"", structure.name, "NEST STRUCTURE", structure.structure_id, "",30, true); } string objectName = OSAEObjectManager.GetObjectByAddress(structure.structure_id).Name; //load current data into structure object Structure currentdata = new Structure(); currentdata.loadData(objectName); //compare structure data to data we have if (!structure.SameData(currentdata)) { datachanged = true; // list the changes temporarily to see how it is working List<Variance> variances = structure.DetailedCompare(currentdata); foreach (Variance v in variances) Log.Debug(v.Prop + " value changed from " + v.valB.ToString() + " to " + v.valA.ToString()); } //update structure data OSAEObjectStateManager.ObjectStateSet(objectName, structure.away, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Id", structure.structure_id, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Name", structure.name, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Country Code", structure.country_code, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Postal Code", structure.postal_code, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Peak Start Time", structure.peak_period_start_time, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Peak End Time", structure.peak_period_end_time, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Time Zone", structure.time_zone, pName); } } catch (Exception e) { string[] lines = e.ToString().Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); Log.Error("error getting structure data. " + lines[0]); } //get thermostat data try { string thermostatData = firebaseClient.Get("devices/thermostats"); dynamic data = JsonConvert.DeserializeObject<dynamic>(thermostatData); var myThermostats = new List<Thermostat>(); foreach (var itemDynamic in data) myThermostats.Add(JsonConvert.DeserializeObject<Thermostat>(((JProperty)itemDynamic).Value.ToString())); foreach (Thermostat thermostat in myThermostats) { //if thermostat does not exist then add it if (!OSAEObjectManager.ObjectExists(thermostat.device_id)) { Log.Debug("about to add thermostat: " + thermostat.name_long + " address: " + thermostat.device_id); OSAEObject _nameObject = OSAEObjectManager.GetObjectByName(thermostat.name); if (_nameObject != null) Log.Error("Object with name: " + _nameObject.Name + " exists but it's address doesn't match - objects address: " + _nameObject.Address + ". - device_id from nest:" + thermostat.structure_id + "."); OSAEObjectManager.ObjectAdd(thermostat.name,"", thermostat.name_long, "NEST THERMOSTAT", thermostat.device_id, "", 30, true); } string objectName = OSAEObjectManager.GetObjectByAddress(thermostat.device_id).Name; //load current data into thermostat object Thermostat currentdata = new Thermostat(); currentdata.loadData(objectName); //compare thermostat data to data we have thermostat.tempToScale(); // set all temps to current scale for comparision since we don't save both in OSA object (will have to load current scale into both _c and _f fields) thermostat.convertLastConnection(); //converts last connection to current time zone and to the same format that OSA will return for comaprison if (!thermostat.SameData(currentdata)) { datachanged = true; // list the changes temporarily to see how it is working List<Variance> variances = thermostat.DetailedCompare(currentdata); Log.Debug("Number of fields changed: " + variances.Count); foreach (Variance v in variances) Log.Debug(v.Prop + " value changed from " + v.valB.ToString() + " to " + v.valA.ToString()); } //update structure data if (thermostat.is_online) OSAEObjectStateManager.ObjectStateSet(objectName, thermostat.hvac_mode, pName); else OSAEObjectStateManager.ObjectStateSet(objectName, "Offline", pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Id", thermostat.device_id, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Name", thermostat.name, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Name Long", thermostat.name_long, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Ambient Temperature", (thermostat.temperature_scale == "F") ? thermostat.ambient_temperature_f.ToString() : thermostat.ambient_temperature_c.ToString(), pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Humidity", thermostat.humidity.ToString(), pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Target Temperature", (thermostat.temperature_scale == "F") ? thermostat.target_temperature_f.ToString() : thermostat.target_temperature_c.ToString(), pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Target Temperature High", (thermostat.temperature_scale == "F") ? thermostat.target_temperature_high_f.ToString() : thermostat.target_temperature_high_c.ToString(), pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Target Temperature Low", (thermostat.temperature_scale == "F") ? thermostat.target_temperature_low_f.ToString() : thermostat.target_temperature_low_c.ToString(), pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Away Temperature High", (thermostat.temperature_scale == "F") ? thermostat.away_temperature_high_f.ToString() : thermostat.away_temperature_high_c.ToString(), pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Away Temperature Low", (thermostat.temperature_scale == "F") ? thermostat.away_temperature_low_f.ToString() : thermostat.away_temperature_low_c.ToString(), pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Has Leaf", thermostat.has_leaf.ToString(), pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Temperature Scale", thermostat.temperature_scale, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Locale", thermostat.locale, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Software Version", thermostat.software_version, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Structure ID", thermostat.structure_id, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Last Connection", thermostat.last_connection, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Is Online", thermostat.is_online.ToString(), pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Can Cool", thermostat.can_cool.ToString(), pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Can Heat", thermostat.can_heat.ToString(), pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Using Emergency Heat", thermostat.is_using_emergency_heat.ToString(), pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Has Fan", thermostat.has_fan.ToString(), pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Fan Timer Active", thermostat.fan_timer_active.ToString(), pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Fan Timer Timeout", thermostat.fan_timer_timeout, pName); } } catch (Exception e) { string[] lines = e.ToString().Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); Log.Error("error getting thermostat data. " + lines[0]); } //get smokealarm data try { string smokeData = firebaseClient.Get("devices/smoke_co_alarms"); dynamic data = JsonConvert.DeserializeObject<dynamic>(smokeData); var mySmokeAlarms = new List<SmokeAlarm>(); foreach (var itemDynamic in data) mySmokeAlarms.Add(JsonConvert.DeserializeObject<SmokeAlarm>(((JProperty)itemDynamic).Value.ToString())); foreach (SmokeAlarm smokealarm in mySmokeAlarms) { //if smokealarm does not exist then add it if (!OSAEObjectManager.ObjectExists(smokealarm.device_id)) { Log.Debug("about to add nest protect: " + smokealarm.name_long + " address: " + smokealarm.device_id); OSAEObject _nameObject = OSAEObjectManager.GetObjectByName(smokealarm.name); if (_nameObject != null) Log.Error("Object with name: " + _nameObject.Name + " exists but it's address doesn't match - objects address: " + _nameObject.Address + ". - device_id from nest:" + smokealarm.structure_id + "."); OSAEObjectManager.ObjectAdd(smokealarm.name,"", smokealarm.name_long, "NEST PROTECT", smokealarm.device_id, "", 30, true); } string objectName = OSAEObjectManager.GetObjectByAddress(smokealarm.device_id).Name; //load current data into smokealarm object SmokeAlarm currentdata = new SmokeAlarm(); smokealarm.convertLastConnection(); currentdata.loadData(objectName); //compare smokealarm data to data we have if (!smokealarm.SameData(currentdata)) { datachanged = true; // list the changes temporarily to see how it is working List<Variance> variances = smokealarm.DetailedCompare(currentdata); Log.Debug("Number of fields changed: " + variances.Count); foreach (Variance v in variances) Log.Debug(v.Prop + " value changed from " + v.valB.ToString() + " to " + v.valA.ToString()); } //update structure data if (smokealarm.is_online) { if (smokealarm.smoke_alarm_state.Equals("emergency")) OSAEObjectStateManager.ObjectStateSet(objectName, "Smoke Emergency", pName); else if (smokealarm.co_alarm_state.Equals("emergency")) OSAEObjectStateManager.ObjectStateSet(objectName, "CO Emergency", pName); else if (smokealarm.smoke_alarm_state.Equals("warning")) OSAEObjectStateManager.ObjectStateSet(objectName, "Smoke Warning", pName); else if (smokealarm.co_alarm_state.Equals("warning")) OSAEObjectStateManager.ObjectStateSet(objectName, "CO Warning", pName); else if (smokealarm.battery_health.Equals("replace")) OSAEObjectStateManager.ObjectStateSet(objectName, "Battery Replace", pName); else OSAEObjectStateManager.ObjectStateSet(objectName, "Online", pName); } else OSAEObjectStateManager.ObjectStateSet(objectName, "Offline", pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Id", smokealarm.device_id, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Name", smokealarm.name, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Name Long", smokealarm.name_long, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Battery Health", smokealarm.battery_health, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "CO Alarm State", smokealarm.co_alarm_state, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Smoke Alarm State", smokealarm.smoke_alarm_state, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Manual Test Active", smokealarm.is_manual_test_active.ToString(), pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Last Manual Test", smokealarm.last_manual_test_time, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "UI Color State", smokealarm.ui_color_state, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Locale", smokealarm.locale, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Software Version", smokealarm.software_version, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Structure ID", smokealarm.structure_id, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Last Connection", smokealarm.last_connection, pName); OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Is Online", smokealarm.is_online.ToString(), pName); } } catch (Exception e) { string[] lines = e.ToString().Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); Log.Debug("error getting smokealarm data. " + lines[0]); } firebaseClient.Dispose(); } return datachanged; }
private void SubscribeToNestDataUpdates(string accessToken) { if (!accessToken.Equals("")) { var firebaseClient = new Firebase("https://developer-api.nest.com", accessToken); //suscribe to structure data try { var response_structure = firebaseClient.GetStreaming("structures", changed: (s, e) => { if (!e.Data.Equals(e.OldData) || e.Data == null || e.OldData == null) { string[] parts = e.Path.Split('/'); string deviceid = parts[parts.Count() - 2]; string dataelement = parts[parts.Count() - 1]; Log.Debug("device(" + deviceid + ") " + dataelement + " changed from " + e.OldData + " to " + e.Data + "."); string objectName = OSAEObjectManager.GetObjectByAddress(deviceid).Name; if (dataelement.Equals("away")) OSAEObjectStateManager.ObjectStateSet(objectName, e.Data, pName); if (dataelement.Equals("name")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Name", e.Data, pName); if (dataelement.Equals("country_code")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Country Code", e.Data, pName); if (dataelement.Equals("postal_code")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Postal Code", e.Data, pName); if (dataelement.Equals("time_zone")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Time Zone", e.Data, pName); if (dataelement.Equals("peak_period_start_time")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Peak Start Time", e.Data, pName); if (dataelement.Equals("peak_period_end_time")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Peak End Time", e.Data, pName); } }); } catch (Exception) { Log.Error("error getting structure updates"); } //suscribe to device data try { var response_thermostat = firebaseClient.GetStreaming("devices", changed: (s, e) => { if (!e.Data.Equals(e.OldData) || e.Data == null || e.OldData == null) { string[] parts = e.Path.Split('/'); string deviceid = parts[parts.Count() - 2]; string dataelement = parts[parts.Count() - 1]; Log.Debug("device(" + deviceid + ") " + dataelement + " changed from " + e.OldData + " to " + e.Data + "."); string objectName = OSAEObjectManager.GetObjectByAddress(deviceid).Name; string objectType = OSAEObjectManager.GetObjectByAddress(deviceid).Type; string tempScale = OSAEObjectPropertyManager.GetObjectPropertyValue(objectName, "Temperature Scale").Value; if (objectType.Equals("NEST THERMOSTAT")) { if (dataelement.Equals("hvac_mode")) OSAEObjectStateManager.ObjectStateSet(objectName, e.Data, pName); if (dataelement.Equals("is_online") && e.Data.Equals("False")) OSAEObjectStateManager.ObjectStateSet(objectName, "OFFLINE", pName); if (dataelement.Equals("name")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Name", e.Data, pName); if (dataelement.Equals("name_long")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Name Long", e.Data, pName); if (dataelement.Equals("device_id")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "ID", e.Data, pName); if (dataelement.Equals("locale")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Locale", e.Data, pName); if (dataelement.Equals("software_version")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Software Version", e.Data, pName); if (dataelement.Equals("structure_id")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Structure ID", e.Data, pName); if (dataelement.Equals("last_connection")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Last Connection", convertDate(e.Data), pName); if (dataelement.Equals("is_online")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Is Online", e.Data, pName); if (dataelement.Equals("can_cool")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Can Cool", e.Data, pName); if (dataelement.Equals("can_heat")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Can Heat", e.Data, pName); if (dataelement.Equals("is_using_emergency_heat")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Using Emergency Heat", e.Data, pName); if (dataelement.Equals("has_fan")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Has Fan", e.Data, pName); if (dataelement.Equals("fan_timer_active")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Fan Timer Active", e.Data, pName); if (dataelement.Equals("fan_timer_timeout")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Fan Timer Timeout", e.Data, pName); if (dataelement.Equals("has_leaf")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Has Leaf", e.Data, pName); if (dataelement.Equals("temperature_scale")) { OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Temperature Scale", e.Data, pName); GetNestData(accessToken); // redownload all data so temps will be displayed in new scale } if (dataelement.Equals("target_temperature_f") && tempScale.Equals("F")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Target Temperature", e.Data, pName); if (dataelement.Equals("target_temperature_c") && tempScale.Equals("C")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Target Temperature", e.Data, pName); if (dataelement.Equals("target_temperature_high_f") && tempScale.Equals("F")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Target Temperature High", e.Data, pName); if (dataelement.Equals("target_temperature_high_c") && tempScale.Equals("C")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Target Temperature High", e.Data, pName); if (dataelement.Equals("target_temperature_low_f") && tempScale.Equals("F")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Target Temperature Low", e.Data, pName); if (dataelement.Equals("target_temperature_low_c") && tempScale.Equals("C")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Target Temperature Low", e.Data, pName); if (dataelement.Equals("away_temperature_high_f") && tempScale.Equals("F")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Away Temperature High", e.Data, pName); if (dataelement.Equals("away_temperature_high_c") && tempScale.Equals("C")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Away Temperature High", e.Data, pName); if (dataelement.Equals("away_temperature_low_f") && tempScale.Equals("F")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Away Temperature Low", e.Data, pName); if (dataelement.Equals("away_temperature_low_c") && tempScale.Equals("C")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Away Temperature Low", e.Data, pName); if (dataelement.Equals("ambient_temperature_f")) { if (tempScale.Equals("F")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Ambient Temperature", e.Data, pName); } if (dataelement.Equals("ambient_temperature_c")) { if (tempScale.Equals("C")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Ambient Temperature", e.Data, pName); } if (dataelement.Equals("humidity")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Humidity", e.Data, pName); } if (objectType.Equals("NEST PROTECT")) { if (dataelement.Equals("smoke_alarm_state") && e.Data.Equals("emergency")) OSAEObjectStateManager.ObjectStateSet(objectName, "SMOKE EMERGENCY", pName); if (dataelement.Equals("smoke_alarm_state") && e.Data.Equals("warning")) OSAEObjectStateManager.ObjectStateSet(objectName, "SMOKE WARNING", pName); if (dataelement.Equals("co_alarm_state") && e.Data.Equals("emergency")) OSAEObjectStateManager.ObjectStateSet(objectName, "CO EMERGENCY", pName); if (dataelement.Equals("co_alarm_state") && e.Data.Equals("warning")) OSAEObjectStateManager.ObjectStateSet(objectName, "CO WARNING", pName); if (dataelement.Equals("battery_health") && e.Data.Equals("replace")) OSAEObjectStateManager.ObjectStateSet(objectName, "BATTERY REPLACE", pName); if (dataelement.Equals("is_online") && e.Data.Equals("False")) OSAEObjectStateManager.ObjectStateSet(objectName, "OFFLINE", pName); if (dataelement.Equals("device_id")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "ID", e.Data, pName); if (dataelement.Equals("locale")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Locale", e.Data, pName); if (dataelement.Equals("software_version")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Software Version", e.Data, pName); if (dataelement.Equals("structure_id")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Structure ID", e.Data, pName); if (dataelement.Equals("name")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Name", e.Data, pName); if (dataelement.Equals("name_long")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Name Long", e.Data, pName); if (dataelement.Equals("last_connection")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Last Connection", convertDate(e.Data), pName); if (dataelement.Equals("is_online")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Is Online", e.Data, pName); if (dataelement.Equals("battery_health")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Battery Health", e.Data, pName); if (dataelement.Equals("co_alarm_state")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "CO Alarm State", e.Data, pName); if (dataelement.Equals("smoke_alarm_state")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Smoke Alarm State", e.Data, pName); if (dataelement.Equals("is_manual_test_active")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Manual Test Active", e.Data, pName); if (dataelement.Equals("last_manual_test_time")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "Last Manual Test", e.Data, pName); if (dataelement.Equals("ui_color_state")) OSAEObjectPropertyManager.ObjectPropertySet(objectName, "UI Color State", e.Data, pName); //set state to online if no waring state is active and device is not offline if (OSAEObjectPropertyManager.GetObjectPropertyValue(objectName, "Smoke Alarm State").Value.Equals("ok") && OSAEObjectPropertyManager.GetObjectPropertyValue(objectName, "CO Alarm State").Value.Equals("ok") && OSAEObjectPropertyManager.GetObjectPropertyValue(objectName, "Battery Health").Value.Equals("ok") && OSAEObjectPropertyManager.GetObjectPropertyValue(objectName, "Is Online").Value.Equals("True")) OSAEObjectStateManager.ObjectStateSet(objectName, "ONLINE", pName); } } }); } catch (Exception) { Log.Error("error getting device updates"); } } }
public void SetThermostatName(string accessToken, string id) { // ambient_temperature_c var url = "https://developer-api.nest.com"; var fb = new Firebase(url, accessToken); /* string path = "/path"; string data = "{{\"value\": \"Hello!\"}}"; string id = fb.Post(path, data); */ string data = "{{\"value\" : \"Jim\"}}"; fb.PostAsync("devices/thermostats/" + id + "/name_long", data); }
public async Task<JsonResult> GetThermoStatTemp(string accessToken, string id ) { var url = "https://developer-api.nest.com"; var fb = new Firebase(url, accessToken); dynamic devices = await fb.GetAsync("devices/thermostats/" + id ); return Json(devices, JsonRequestBehavior.AllowGet); }
public async Task<JsonResult> GetSmokeAlarmData(string accessToken) { var url = "https://developer-api.nest.com"; var fb = new Firebase(url, accessToken); dynamic devices = await fb.GetAsync("devices/smoke_co_alarms"); return Json(devices, JsonRequestBehavior.AllowGet); }
public async Task<string> GetDeviceData(string accessToken) { // CREATE A CLIENT WE CAN ACCESS DATA THROUGH var url = "https://developer-api.nest.com"; var fb = new Firebase(url, accessToken); dynamic devices = await fb.GetAsync("devices"); var jsonParsed = JsonConvert.DeserializeObject<dynamic>(devices); var thermostats = jsonParsed.thermostats; string dev_id = jsonParsed["thermostats"]["5TN0NLa65q3XoSjECHNUvI-BBzEt2ynq"].device_id; string name = jsonParsed["thermostats"]["5TN0NLa65q3XoSjECHNUvI-BBzEt2ynq"].name_long; string curr_temp = jsonParsed["thermostats"]["5TN0NLa65q3XoSjECHNUvI-BBzEt2ynq"].ambient_temperature_c; string tar_temp = jsonParsed["thermostats"]["5TN0NLa65q3XoSjECHNUvI-BBzEt2ynq"].target_temperature_c; Thermostat myThermostat = new Thermostat(dev_id, name, curr_temp, tar_temp); //return Json(devices, JsonRequestBehavior.AllowGet); return myThermostat.ToString(); }
public ConversationRepository(Firebase fb) { _fb = fb; }
private string UpdateNestData(string type, string id, string data, string accessToken) { string r=""; if (!accessToken.Equals("")) { string path = type + "/" + id; Log.Debug("about to send update to nest: path=" + path + ", value=" + data + ""); var firebaseClient = new Firebase("https://developer-api.nest.com", accessToken); try { r = firebaseClient.Put(path, data); } catch (Exception e) { string[] lines = e.ToString().Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); r = "Error updating firebase: " + lines[0]; } firebaseClient.Dispose(); } return r; }
private static void SubscribeToNestDeviceDataUpdates() { var thermostats = new List<Thermostat>(); Thermostat myThermostat = new Thermostat(); var firebaseClient = new Firebase("https://developer-api.nest.com", _accessToken); var response = firebaseClient.GetStreaming("devices", //changed: (s, args) => UpdatedItem(args) changed: (s, e) => { /* if (e.Path.EndsWith("name")) //myThermostat.name = e.Data; Console.WriteLine("Name: {0}.", e.Data); if (e.Path.Contains("last_connection")) //myThermostat.last_connection = e.Data; Console.WriteLine("Last connection: {0}.", e.Data); if (e.Path.Contains("ambient_temperature_f")) //myThermostat.ambient_temperature_f = e.Data; Console.WriteLine("Current temperature: {0}.", e.Data); if (e.Path.Contains("target_temperature_f")) //myThermostat.target_temperature_f = e.Data; Console.WriteLine("Target temperature: {0}.", e.Data); if (e.Path.Contains("humidity")) //myThermostat.Humidity = e.Data; Console.WriteLine("Humidity: {0}.", e.Data); if (e.Path.Contains("hvac_state")) //myThermostat.hvac_state = e.Data; Console.WriteLine("Current mode: {0}.", e.Data); //thermostats.Add(myThermostat); var JSON = JsonConvert.SerializeObject(e.Data); //Console.WriteLine(JSON); */ var JSON = JsonConvert.SerializeObject(e.Data); Console.WriteLine(JSON); //Console.WriteLine(e.Path.Remove(0, 54) + "-" + e.Data); } ); Console.WriteLine("Change the current temperature of the Nest Thermostat in the Nest Developer Chrome Extension to see the real-time updates."); }