feat: migrate boiler control implementation to BoilerMonitor namespace and add budget handling logic
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
namespace BoilerMonitor.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Boiler scheduling configuration read from Home Assistant entity state.
|
||||
/// </summary>
|
||||
public sealed class BoilerConfig
|
||||
{
|
||||
public required int IntervalCount { get; init; }
|
||||
|
||||
public required double PriceCap { get; init; }
|
||||
|
||||
public required DateTime Deadline { get; init; }
|
||||
|
||||
public required bool SkipPriceCap { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>BoilerMonitor.Models</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HomeAssistant.Models\HomeAssistant.Models.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NetDaemon.Extensions.Mqtt" Version="26.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,67 @@
|
||||
namespace BoilerMonitor.Models;
|
||||
|
||||
public static class BoilerMonitorConsts
|
||||
{
|
||||
public const int DefaultPollIntervalSeconds = 30;
|
||||
|
||||
/// <summary>
|
||||
/// Power threshold in watts below which the boiler is considered to have finished heating (water ready).
|
||||
/// Also used as the default threshold above which the boiler is considered actively heating.
|
||||
/// </summary>
|
||||
public const double DefaultHeatingPowerThresholdWatts = 5.0;
|
||||
|
||||
/// <summary>
|
||||
/// Grace period after the boiler switch is turned on, during which
|
||||
/// low power readings are ignored for "water ready" detection.
|
||||
/// This prevents false positives caused by the heating element ramp-up delay.
|
||||
/// </summary>
|
||||
public static readonly TimeSpan WarmUpGracePeriod = TimeSpan.FromMinutes(2);
|
||||
|
||||
/// <summary>
|
||||
/// Cooldown period after the water has been detected as ready,
|
||||
/// during which the boiler will not be turned back on.
|
||||
/// This prevents wasteful on/off cycling when water is already heated.
|
||||
/// </summary>
|
||||
public static readonly TimeSpan WaterReadyCooldownPeriod = TimeSpan.FromHours(1);
|
||||
|
||||
public const int MinPollIntervalSeconds = 5;
|
||||
public const int MaxPollIntervalSeconds = 300;
|
||||
public const int PollIntervalStepSeconds = 5;
|
||||
|
||||
public const double MinHeatingThresholdWatts = 1.0;
|
||||
public const double MaxHeatingThresholdWatts = 100.0;
|
||||
public const double HeatingThresholdStepWatts = 0.5;
|
||||
|
||||
public const string ConfigPowerEntityId = "text.boilermonitor_config_power_entity_id";
|
||||
public const string ConfigSwitchEntityId = "text.boilermonitor_config_switch_entity_id";
|
||||
public const string ConfigPollIntervalEntityId = "number.boilermonitor_config_poll_interval";
|
||||
public const string ConfigHeatingThresholdEntityId = "number.boilermonitor_config_heating_threshold";
|
||||
|
||||
public const string CleanupButtonEntityId = "button.boilermonitor_cleanup";
|
||||
public const string StatusEntityId = "sensor.boilermonitor_status";
|
||||
|
||||
public const string WaterReadyEntityId = "sensor.boilermonitor_water_ready";
|
||||
public const string SkipPriceCapEntityId = "switch.boilermonitor_skip_price_cap";
|
||||
public const string TodayRuntimeEntityId = "sensor.boilermonitor_today_runtime";
|
||||
public const string RemainingTimeEntityId = "sensor.boilermonitor_remaining_time";
|
||||
public const string BudgetPercentageEntityId = "sensor.boilermonitor_budget_percentage";
|
||||
public const string BudgetExhaustedEntityId = "binary_sensor.boilermonitor_budget_exhausted";
|
||||
public const string SessionCountEntityId = "sensor.boilermonitor_session_count";
|
||||
public const string BudgetOverrideEntityId = "switch.boilermonitor_budget_override";
|
||||
|
||||
public const string NordPoolCheapestIntervalsEntityId = "sensor.nordpool_cheapest_intervals";
|
||||
|
||||
public const string BoilerDailyHoursEntityId = "input_number.boiler_daily_hours";
|
||||
public const string BoilerPriceCapEntityId = "input_number.boiler_price_cap";
|
||||
public const string BoilerReadyByEntityId = "input_datetime.boiler_ready_by";
|
||||
|
||||
public const string StatusConfigured = "configured";
|
||||
public const string StatusAwaitingConfiguration = "awaiting_configuration";
|
||||
public const string StatusCleanedUp = "cleaned_up";
|
||||
|
||||
public const string SwitchOnState = "on";
|
||||
|
||||
public const string DeviceIdentifier = "boiler_monitor";
|
||||
public const string DeviceName = "Boiler Monitor";
|
||||
public const string DeviceManufacturer = "HomeAssistant App Daemon";
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using HomeAssistant.Models;
|
||||
using NetDaemon.Extensions.MqttEntityManager;
|
||||
|
||||
namespace BoilerMonitor.Models;
|
||||
|
||||
public class BoilerMonitorEntity : EntityCreateModel
|
||||
{
|
||||
public string Domain { get; set; }
|
||||
public string Identifier { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public BoilerMonitorEntity(string domain, string identifier, string name)
|
||||
{
|
||||
Domain = domain;
|
||||
Identifier = identifier;
|
||||
EntityId = $"{Domain}.{Identifier}";
|
||||
Name = string.IsNullOrWhiteSpace(name) ? identifier : name;
|
||||
|
||||
Options = new EntityCreationOptions
|
||||
{
|
||||
UniqueId = EntityId,
|
||||
Name = Name
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace BoilerMonitor.Models.Enums;
|
||||
|
||||
public enum BoilerAction
|
||||
{
|
||||
NoChange,
|
||||
TurnOn,
|
||||
TurnOff
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace BoilerMonitor.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Reads the boiler scheduling configuration from Home Assistant entity state.
|
||||
/// </summary>
|
||||
public interface IBoilerConfigReader
|
||||
{
|
||||
BoilerConfig ReadConfig();
|
||||
}
|
||||
Reference in New Issue
Block a user