private void PublishZoneState(clsZone zone) { PublishAsync(zone.ToTopic(Topic.state), zone.ToState()); PublishAsync(zone.ToTopic(Topic.basic_state), zone.ToBasicState()); if (zone.IsTemperatureZone()) { PublishAsync(zone.ToTopic(Topic.current_temperature), zone.TempText()); } else if (zone.IsHumidityZone()) { PublishAsync(zone.ToTopic(Topic.current_humidity), zone.TempText()); } }
private void PublishZoneState(clsZone zone) { MqttClient.PublishAsync(zone.ToTopic(Topic.state), zone.ToState(), MqttQualityOfServiceLevel.AtMostOnce, true); MqttClient.PublishAsync(zone.ToTopic(Topic.basic_state), zone.ToBasicState(), MqttQualityOfServiceLevel.AtMostOnce, true); if (zone.IsTemperatureZone()) { MqttClient.PublishAsync(zone.ToTopic(Topic.current_temperature), zone.TempText(), MqttQualityOfServiceLevel.AtMostOnce, true); } else if (zone.IsHumidityZone()) { MqttClient.PublishAsync(zone.ToTopic(Topic.current_humidity), zone.TempText(), MqttQualityOfServiceLevel.AtMostOnce, true); } }
private void PublishZones() { log.Debug("Publishing {type}", "zones"); for (ushort i = 1; i <= OmniLink.Controller.Zones.Count; i++) { clsZone zone = OmniLink.Controller.Zones[i]; if (zone.DefaultProperties == true) { PublishAsync(zone.ToTopic(Topic.name), null); } else { PublishZoneState(zone); PublishAsync(zone.ToTopic(Topic.name), zone.Name); } if (zone.DefaultProperties == true || Global.mqtt_discovery_ignore_zones.Contains(zone.Number)) { PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/zone{i}/config", null); PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i}/config", null); PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/zone{i}/config", null); PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i}temp/config", null); PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i}humidity/config", null); continue; } PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/zone{i}/config", JsonConvert.SerializeObject(zone.ToConfig())); PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i}/config", JsonConvert.SerializeObject(zone.ToConfigSensor())); PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/zone{i}/config", JsonConvert.SerializeObject(zone.ToConfigSwitch())); if (zone.IsTemperatureZone()) { PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i}temp/config", JsonConvert.SerializeObject(zone.ToConfigTemp(OmniLink.Controller.TempFormat))); } else if (zone.IsHumidityZone()) { PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i}humidity/config", JsonConvert.SerializeObject(zone.ToConfigHumidity())); } } }
public static Sensor ToConfigHumidity(this clsZone 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 clsZone 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 ToConfigTemp(this clsZone zone, enuTempFormat format) { Sensor ret = new Sensor(); ret.unique_id = $"{Global.mqtt_prefix}zone{zone.Number.ToString()}temp"; 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 = (format == enuTempFormat.Fahrenheit ? "°F" : "°C"); return(ret); }
public static BinarySensor ToConfig(this clsZone zone) { BinarySensor ret = new BinarySensor(); ret.unique_id = $"{Global.mqtt_prefix}zone{zone.Number.ToString()}binary"; ret.name = Global.mqtt_discovery_name_prefix + zone.Name; Global.mqtt_discovery_override_zone.TryGetValue(zone.Number, out OverrideZone override_zone); if (override_zone != null) { ret.device_class = override_zone.device_class; } else { switch (zone.ZoneType) { case enuZoneType.EntryExit: case enuZoneType.X2EntryDelay: case enuZoneType.X4EntryDelay: ret.device_class = BinarySensor.DeviceClass.door; break; case enuZoneType.Perimeter: ret.device_class = BinarySensor.DeviceClass.window; break; case enuZoneType.Tamper: ret.device_class = BinarySensor.DeviceClass.problem; break; case enuZoneType.AwayInt: case enuZoneType.NightInt: ret.device_class = BinarySensor.DeviceClass.motion; break; case enuZoneType.Water: ret.device_class = BinarySensor.DeviceClass.moisture; break; case enuZoneType.Fire: ret.device_class = BinarySensor.DeviceClass.smoke; break; case enuZoneType.Gas: ret.device_class = BinarySensor.DeviceClass.gas; break; } } ret.state_topic = zone.ToTopic(Topic.basic_state); return(ret); }
private void HandleRequestZoneStatus(clsOmniLinkMessageQueueItem M, byte[] B, bool Timeout) { if (Timeout) { return; } clsOL2MsgExtendedStatus MSG = new clsOL2MsgExtendedStatus(OmniLink.Controller.Connection, B); for (byte i = 0; i < MSG.ZoneStatusCount(); i++) { clsZone zone = OmniLink.Controller.Zones[MSG.ObjectNumber(i)]; zone.CopyExtendedStatus(MSG, i); MqttClient.PublishAsync(zone.ToTopic(Topic.state), zone.ToState(), MqttQualityOfServiceLevel.AtMostOnce, true); } }
public static Sensor ToConfigSensor(this clsZone zone) { Sensor ret = new Sensor(); ret.unique_id = $"{Global.mqtt_prefix}zone{zone.Number.ToString()}"; ret.name = Global.mqtt_discovery_name_prefix + zone.Name; switch (zone.ZoneType) { case enuZoneType.EntryExit: case enuZoneType.X2EntryDelay: case enuZoneType.X4EntryDelay: ret.icon = "mdi:door"; break; case enuZoneType.Perimeter: ret.icon = "mdi:window-closed"; break; case enuZoneType.Tamper: ret.icon = "mdi:shield"; break; case enuZoneType.AwayInt: case enuZoneType.NightInt: ret.icon = "mdi:walk"; break; case enuZoneType.Water: ret.icon = "mdi:water"; break; case enuZoneType.Fire: ret.icon = "mdi:fire"; break; case enuZoneType.Gas: ret.icon = "mdi:gas-cylinder"; break; } ret.value_template = @"{{ value|replace(""_"", "" "")|title }}"; ret.state_topic = zone.ToTopic(Topic.state); return(ret); }