From d975957fc9aedbd571288a3851ec3d28553c21e0 Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Thu, 31 Aug 2023 14:02:39 +0200 Subject: [PATCH] Add more signals to Luxtronik --- src/HomeBlaze.Luxtronik/LuxtronikDevice.cs | 45 ++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/src/HomeBlaze.Luxtronik/LuxtronikDevice.cs b/src/HomeBlaze.Luxtronik/LuxtronikDevice.cs index 62924f9d..78346c2c 100644 --- a/src/HomeBlaze.Luxtronik/LuxtronikDevice.cs +++ b/src/HomeBlaze.Luxtronik/LuxtronikDevice.cs @@ -31,9 +31,13 @@ public class LuxtronikDevice : BackgroundService, private ClientWebSocket? _webSocket; private bool _isRunning = true; private bool _isInitialized = false; - private DateTimeOffset? _totalCoolingOperatingTimeChange = null; private XDocument? _metadataXml; + private DateTimeOffset? _totalHeatPumpOperatingTimeChange = null; + private DateTimeOffset? _totalHeatingOperatingTimeChange = null; + private DateTimeOffset? _totalWaterHeatingOperatingTimeChange = null; + private DateTimeOffset? _totalCoolingOperatingTimeChange = null; + public string? Title => DisplayTitle; public string IconName => "fa-solid fa-fire"; @@ -163,9 +167,19 @@ public decimal? TotalCoefficientOfPerformance public TimeSpan? TotalCoolingOperatingTime { get; private set; } + [State(IsEstimated = true)] + public bool IsHeatPumpOperating { get; private set; } + + [State(IsEstimated = true)] + public bool IsHeating { get; private set; } + + [State(IsEstimated = true)] + public bool IsWaterHeating { get; private set; } + [State(IsEstimated = true)] public bool IsCooling { get; private set; } + public LuxtronikDevice(IThingManager thingManager, ILogger logger) { _thingManager = thingManager; @@ -326,19 +340,43 @@ private void ProcessValues(XDocument xmlDocument) FlowRate = GetDecimal(allValues, incoming, new[] { "Durchfluss" }); + var previousTotalHeatPumpOperatingTime = TotalHeatPumpOperatingTime; + var previousTotalHeatingOperatingTime = TotalHeatingOperatingTime; + var previousTotalWaterHeatingOperatingTime = TotalWaterHeatingOperatingTime; + var previousTotalCoolingOperatingTime = TotalCoolingOperatingTime; + TotalHeatPumpOperatingTime = GetTimeSpan(allValues, operatingHours, new[] { "Betriebstunden WP" }); TotalHeatingOperatingTime = GetTimeSpan(allValues, operatingHours, new[] { "Betriebstunden Heiz." }); TotalWaterHeatingOperatingTime = GetTimeSpan(allValues, operatingHours, new[] { "Betriebstunden WW" }); - - var previousTotalCoolingOperatingTime = TotalCoolingOperatingTime; TotalCoolingOperatingTime = GetTimeSpan(allValues, operatingHours, new[] { "Betriebstunden Kuehl" }); + if (previousTotalHeatPumpOperatingTime != null && + previousTotalHeatPumpOperatingTime != TotalHeatPumpOperatingTime) + { + _totalHeatPumpOperatingTimeChange = DateTimeOffset.Now; + } + + if (previousTotalHeatingOperatingTime != null && + previousTotalHeatingOperatingTime != TotalHeatingOperatingTime) + { + _totalHeatingOperatingTimeChange = DateTimeOffset.Now; + } + + if (previousTotalWaterHeatingOperatingTime != null && + previousTotalWaterHeatingOperatingTime != TotalWaterHeatingOperatingTime) + { + _totalWaterHeatingOperatingTimeChange = DateTimeOffset.Now; + } + if (previousTotalCoolingOperatingTime != null && previousTotalCoolingOperatingTime != TotalCoolingOperatingTime) { _totalCoolingOperatingTimeChange = DateTimeOffset.Now; } + IsHeatPumpOperating = DateTimeOffset.Now - _totalHeatPumpOperatingTimeChange < TimeSpan.FromMinutes(65); + IsHeating = DateTimeOffset.Now - _totalHeatingOperatingTimeChange < TimeSpan.FromMinutes(65); + IsWaterHeating = DateTimeOffset.Now - _totalWaterHeatingOperatingTimeChange < TimeSpan.FromMinutes(65); IsCooling = DateTimeOffset.Now - _totalCoolingOperatingTimeChange < TimeSpan.FromMinutes(65); TotalProducedHeatEnergy = GetDecimal(allValues, heatEnergy, new[] { "Heizung" }) * 1000; @@ -363,6 +401,7 @@ private void ProcessValues(XDocument xmlDocument) } private decimal? _previousTotalConsumedEnergy; + private DateTimeOffset? _previousTotalConsumedEnergyTime; private void RecalculatePowerConsumption()