/// <summary> /// Sets the device value. /// </summary> /// <param name="refId">The device reference identifier.</param> /// <param name="value">The value/status of the device.</param> /// <param name="trigger">if set to <c>true</c> process triggers normally, otherwise only change the value.</param> public virtual void SetDeviceValue(int refId, double value, bool trigger = true) { hs.SetDeviceValueByRef(refId, value, trigger); }
static internal void Update_ThermostatDevice(Thermostat thermostat, Structures structure, DeviceDataPoint ddPoint) { string name; string id = GetDeviceKeys(ddPoint.device, out name); /* * if (name.Contains("thermostat")) // if the device is a structure thermostat * name = "thermostat"; */ switch (name) { case "Is Online": { if (thermostat.is_online) { hs.SetDeviceValueByRef(ddPoint.dvRef, 1, true); } else { hs.SetDeviceValueByRef(ddPoint.dvRef, 0, true); } break; } case "HVAC Mode": { switch (thermostat.hvac_mode) { case "off": hs.SetDeviceValueByRef(ddPoint.dvRef, 0, true); break; case "heat-cool": 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; case "eco": hs.SetDeviceValueByRef(ddPoint.dvRef, 4, true); break; } break; } case "Status": { hs.SetDeviceString(ddPoint.dvRef, thermostat.hvac_state, true); break; } case "Target Temperature": { if (thermostat.temperature_scale == "F") { hs.SetDeviceValueByRef(ddPoint.dvRef, thermostat.target_temperature_f, true); } else { hs.SetDeviceValueByRef(ddPoint.dvRef, thermostat.target_temperature_c, true); } ddPoint.device.set_ScaleText(hs, thermostat.temperature_scale); break; } case "Target Temperature High": { double temp; if (thermostat.temperature_scale == "F") { if (thermostat.hvac_mode.Equals("eco")) { temp = thermostat.eco_temperature_high_f; } else { temp = thermostat.target_temperature_high_f; } } else { if (thermostat.hvac_mode.Equals("eco")) { temp = thermostat.eco_temperature_high_c; } else { temp = thermostat.target_temperature_high_c; } } hs.SetDeviceValueByRef(ddPoint.dvRef, temp, true); ddPoint.device.set_ScaleText(hs, thermostat.temperature_scale); break; } case "Target Temperature Low": { double temp; if (thermostat.temperature_scale == "F") { if (thermostat.hvac_mode.Equals("eco")) { temp = thermostat.eco_temperature_low_f; } else { temp = thermostat.target_temperature_low_f; } } else { if (thermostat.hvac_mode.Equals("eco")) { temp = thermostat.eco_temperature_low_c; } else { temp = thermostat.target_temperature_low_c; } } hs.SetDeviceValueByRef(ddPoint.dvRef, temp, true); ddPoint.device.set_ScaleText(hs, thermostat.temperature_scale); break; } case "Ambient Temperature": { if (thermostat.temperature_scale == "F") { hs.SetDeviceValueByRef(ddPoint.dvRef, thermostat.ambient_temperature_f, true); } else { hs.SetDeviceValueByRef(ddPoint.dvRef, thermostat.ambient_temperature_c, true); } ddPoint.device.set_ScaleText(hs, thermostat.temperature_scale); break; } case "Humidity": { hs.SetDeviceValueByRef(ddPoint.dvRef, thermostat.humidity, true); break; } case "Battery Health": { if (!thermostat.is_using_emergency_heat) { hs.SetDeviceValueByRef(ddPoint.dvRef, 1, true); } else { hs.SetDeviceValueByRef(ddPoint.dvRef, 0, true); } break; } } }
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; } } }