private void PublishThermostats() { log.Debug("Publishing {type}", "thermostats"); for (ushort i = 1; i <= OmniLink.Controller.Thermostats.Count; i++) { clsThermostat thermostat = OmniLink.Controller.Thermostats[i]; if (thermostat.DefaultProperties == true) { PublishAsync(thermostat.ToTopic(Topic.name), null); PublishAsync($"{Global.mqtt_discovery_prefix}/climate/{Global.mqtt_prefix}/thermostat{i}/config", null); PublishAsync($"{Global.mqtt_discovery_prefix}/number/{Global.mqtt_prefix}/thermostat{i}humidify/config", null); PublishAsync($"{Global.mqtt_discovery_prefix}/number/{Global.mqtt_prefix}/thermostat{i}dehumidify/config", null); PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i}temp/config", null); PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i}humidity/config", null); continue; } PublishThermostatState(thermostat); PublishAsync(thermostat.ToTopic(Topic.name), thermostat.Name); PublishAsync($"{Global.mqtt_discovery_prefix}/climate/{Global.mqtt_prefix}/thermostat{i}/config", JsonConvert.SerializeObject(thermostat.ToConfig(OmniLink.Controller.TempFormat))); PublishAsync($"{Global.mqtt_discovery_prefix}/number/{Global.mqtt_prefix}/thermostat{i}humidify/config", JsonConvert.SerializeObject(thermostat.ToConfigHumidify())); PublishAsync($"{Global.mqtt_discovery_prefix}/number/{Global.mqtt_prefix}/thermostat{i}dehumidify/config", JsonConvert.SerializeObject(thermostat.ToConfigDehumidify())); PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i}temp/config", JsonConvert.SerializeObject(thermostat.ToConfigTemp(OmniLink.Controller.TempFormat))); PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i}humidity/config", JsonConvert.SerializeObject(thermostat.ToConfigHumidity())); } }
private void PublishThermostatState(clsThermostat thermostat) { MqttClient.PublishAsync(thermostat.ToTopic(Topic.current_operation), thermostat.ToOperationState(), MqttQualityOfServiceLevel.AtMostOnce, true); MqttClient.PublishAsync(thermostat.ToTopic(Topic.current_temperature), thermostat.TempText(), MqttQualityOfServiceLevel.AtMostOnce, true); MqttClient.PublishAsync(thermostat.ToTopic(Topic.current_humidity), thermostat.HumidityText(), MqttQualityOfServiceLevel.AtMostOnce, true); MqttClient.PublishAsync(thermostat.ToTopic(Topic.temperature_heat_state), thermostat.HeatSetpointText(), MqttQualityOfServiceLevel.AtMostOnce, true); MqttClient.PublishAsync(thermostat.ToTopic(Topic.temperature_cool_state), thermostat.CoolSetpointText(), MqttQualityOfServiceLevel.AtMostOnce, true); MqttClient.PublishAsync(thermostat.ToTopic(Topic.humidify_state), thermostat.HumidifySetpointText(), MqttQualityOfServiceLevel.AtMostOnce, true); MqttClient.PublishAsync(thermostat.ToTopic(Topic.dehumidify_state), thermostat.DehumidifySetpointText(), MqttQualityOfServiceLevel.AtMostOnce, true); MqttClient.PublishAsync(thermostat.ToTopic(Topic.mode_state), thermostat.ModeText().ToLower(), MqttQualityOfServiceLevel.AtMostOnce, true); MqttClient.PublishAsync(thermostat.ToTopic(Topic.fan_mode_state), thermostat.FanModeText().ToLower(), MqttQualityOfServiceLevel.AtMostOnce, true); MqttClient.PublishAsync(thermostat.ToTopic(Topic.hold_state), thermostat.HoldStatusText().ToLower(), MqttQualityOfServiceLevel.AtMostOnce, true); }
private void PublishThermostatState(clsThermostat thermostat) { PublishAsync(thermostat.ToTopic(Topic.current_operation), thermostat.ToOperationState()); PublishAsync(thermostat.ToTopic(Topic.current_temperature), thermostat.TempText()); PublishAsync(thermostat.ToTopic(Topic.current_humidity), thermostat.HumidityText()); PublishAsync(thermostat.ToTopic(Topic.temperature_heat_state), thermostat.HeatSetpointText()); PublishAsync(thermostat.ToTopic(Topic.temperature_cool_state), thermostat.CoolSetpointText()); PublishAsync(thermostat.ToTopic(Topic.humidify_state), thermostat.HumidifySetpointText()); PublishAsync(thermostat.ToTopic(Topic.dehumidify_state), thermostat.DehumidifySetpointText()); PublishAsync(thermostat.ToTopic(Topic.mode_state), thermostat.ModeText().ToLower()); PublishAsync(thermostat.ToTopic(Topic.fan_mode_state), thermostat.FanModeText().ToLower()); PublishAsync(thermostat.ToTopic(Topic.hold_state), thermostat.HoldStatusText().ToLower()); }
public static Sensor ToConfigHumidity(this clsThermostat zone) { Sensor ret = new Sensor(); ret.name = $"{Global.mqtt_discovery_name_prefix}{zone.Name} Humidity"; ret.device_class = Sensor.DeviceClass.humidity; ret.state_topic = zone.ToTopic(Topic.current_humidity); ret.unit_of_measurement = "%"; return(ret); }
public static Sensor ToConfigTemp(this clsThermostat zone) { Sensor ret = new Sensor(); ret.name = $"{Global.mqtt_discovery_name_prefix}{zone.Name} Temp"; ret.device_class = Sensor.DeviceClass.temperature; ret.state_topic = zone.ToTopic(Topic.current_temperature); ret.unit_of_measurement = "°F"; return(ret); }
public static Sensor ToConfigHumidity(this clsThermostat thermostat) { Sensor ret = new Sensor(); ret.unique_id = $"{Global.mqtt_prefix}thermostat{thermostat.Number.ToString()}humidity"; ret.name = $"{Global.mqtt_discovery_name_prefix}{thermostat.Name} Humidity"; ret.device_class = Sensor.DeviceClass.humidity; ret.state_topic = thermostat.ToTopic(Topic.current_humidity); ret.unit_of_measurement = "%"; return(ret); }
public static Sensor ToConfigTemp(this clsThermostat thermostat, enuTempFormat format) { Sensor ret = new Sensor(); ret.unique_id = $"{Global.mqtt_prefix}thermostat{thermostat.Number.ToString()}temp"; ret.name = $"{Global.mqtt_discovery_name_prefix}{thermostat.Name} Temp"; ret.device_class = Sensor.DeviceClass.temperature; ret.state_topic = thermostat.ToTopic(Topic.current_temperature); ret.unit_of_measurement = (format == enuTempFormat.Fahrenheit ? "°F" : "°C"); return(ret); }
public static Climate ToConfig(this clsThermostat thermostat) { Climate ret = new Climate(); ret.name = Global.mqtt_discovery_name_prefix + thermostat.Name; ret.current_temperature_topic = thermostat.ToTopic(Topic.current_temperature); ret.temperature_low_state_topic = thermostat.ToTopic(Topic.temperature_heat_state); ret.temperature_low_command_topic = thermostat.ToTopic(Topic.temperature_heat_command); ret.temperature_high_state_topic = thermostat.ToTopic(Topic.temperature_cool_state); ret.temperature_high_command_topic = thermostat.ToTopic(Topic.temperature_cool_command); ret.mode_state_topic = thermostat.ToTopic(Topic.mode_state); ret.mode_command_topic = thermostat.ToTopic(Topic.mode_command); ret.fan_mode_state_topic = thermostat.ToTopic(Topic.fan_mode_state); ret.fan_mode_command_topic = thermostat.ToTopic(Topic.fan_mode_command); ret.hold_state_topic = thermostat.ToTopic(Topic.hold_state); ret.hold_command_topic = thermostat.ToTopic(Topic.hold_command); return(ret); }
public static Climate ToConfig(this clsThermostat thermostat, enuTempFormat format) { Climate ret = new Climate(); if (format == enuTempFormat.Celsius) { ret.min_temp = "7"; ret.max_temp = "35"; } ret.unique_id = $"{Global.mqtt_prefix}thermostat{thermostat.Number.ToString()}"; ret.name = Global.mqtt_discovery_name_prefix + thermostat.Name; ret.current_temperature_topic = thermostat.ToTopic(Topic.current_temperature); ret.temperature_low_state_topic = thermostat.ToTopic(Topic.temperature_heat_state); ret.temperature_low_command_topic = thermostat.ToTopic(Topic.temperature_heat_command); ret.temperature_high_state_topic = thermostat.ToTopic(Topic.temperature_cool_state); ret.temperature_high_command_topic = thermostat.ToTopic(Topic.temperature_cool_command); ret.mode_state_topic = thermostat.ToTopic(Topic.mode_state); ret.mode_command_topic = thermostat.ToTopic(Topic.mode_command); ret.fan_mode_state_topic = thermostat.ToTopic(Topic.fan_mode_state); ret.fan_mode_command_topic = thermostat.ToTopic(Topic.fan_mode_command); ret.hold_state_topic = thermostat.ToTopic(Topic.hold_state); ret.hold_command_topic = thermostat.ToTopic(Topic.hold_command); return(ret); }