Refreshed logic to allow users to toggle hot water preparation. Introduced new `input_boolean.boiler_prepare_hot_water` and updated config, services, and tests to ensure water readiness only when required.
4.8 KiB
name, overview, todos, isProject
| name | overview | todos | isProject | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Water Heater Preparation Decision | Add a new input_boolean so the user can decide whether to prepare hot water. When ON, the system ensures water is ready by the deadline using cheap intervals. When OFF, preparation is skipped and the boiler is turned off if running. |
|
false |
Water Heater Preparation Decision
Goal
Add a new input_boolean.boiler_prepare_hot_water so the user can decide whether to prepare hot water. When ON: ensure water is ready by the deadline (current behavior). When OFF: skip preparation entirely and turn off the boiler if it is running.
Current Flow
flowchart LR
subgraph config [Config]
DailyHours[BoilerDailyHours]
PriceCap[BoilerPriceCap]
ReadyBy[BoilerReadyBy]
end
subgraph logic [Logic]
Cheapest[CheapestIntervalsFinder]
BoilerControl[BoilerControlService]
end
subgraph decision [Decision]
isCheap[isNowCheap]
waterReady[waterReady]
end
subgraph action [Action]
TurnOn[Turn On]
TurnOff[Turn Off]
end
DailyHours --> Cheapest
PriceCap --> Cheapest
ReadyBy --> Cheapest
Cheapest --> isCheap
isCheap --> BoilerControl
waterReady --> BoilerControl
BoilerControl --> TurnOn
BoilerControl --> TurnOff
Proposed Changes
1. New Home Assistant Entity
User action: Add to configuration.yaml or via UI:
input_boolean:
boiler_prepare_hot_water:
name: "Prepare hot water"
icon: mdi:water-thermometer
Then run dotnet tool run nd-codegen to regenerate HomeAssistant.Entities/EntityGeneration/HomeAssistantGenerated.cs so the new entity is available in code.
2. Add Prepare Hot Water to NordPoolInit
File: NordPool.Manager/NordPoolInit.cs
- Inject
InputBooleanEntity BoilerPrepareHotWaterEntityfromentities.InputBoolean.BoilerPrepareHotWater(after codegen) - Read
BoilerPrepareHotWaterEntity.StateinUpdateEntitiesAsyncbefore callingBoilerControlService - Parse as boolean:
"on"= true,"off"or null = false. For backward compatibility when entity does not exist yet, treat null/unknown as true - Pass
prepareHotWatertoDetermineAction
3. Extend BoilerControlService and IBoilerControlService
Files: NordPool.Manager/Interface/IBoilerControlService.cs, NordPool.Manager/BoilerControlService.cs
- Add
bool prepareHotWateras first parameter toDetermineAction - When
prepareHotWater == false: returnBoilerAction.TurnOffif boiler is on, elseNoChange - When
prepareHotWater == true: keep current logic (cheap + not water ready)
Interface change:
BoilerAction DetermineAction(bool prepareHotWater, bool isNowCheap, bool waterReady, string? currentSwitchState);
4. Update EntityUpdateContext
File: NordPool.Manager/Models/EntityUpdateContext.cs
- Add
bool PrepareHotWater { get; init; }for UI/attributes
5. Update NordPoolEntityService
File: NordPool.Manager/NordPoolEntityService.cs
- Add
prepare_hot_watertosensor.nordpool_cheapest_intervalsattributes so the user can see the decision state in HA
6. Unit Tests
File: NordPool.Manager.Tests/BoilerControlServiceTests.cs
- Add tests for
prepareHotWater == false: always TurnOff when on, NoChange when off - Add tests for
prepareHotWater == true: existing behavior unchanged
Logic Summary
| Prepare Hot Water | isNowCheap | waterReady | Switch State | Action |
|---|---|---|---|---|
| OFF | any | any | on | TurnOff |
| OFF | any | any | off | NoChange |
| ON | true | false | off | TurnOn |
| ON | true | false | on | NoChange |
| ON | false | any | on | TurnOff |
| ON | any | true | on | TurnOff |
Backward Compatibility
- If
BoilerPrepareHotWaterEntitydoes not exist yet (before HA config): use a fallback or skip the entity read - If state is null or unknown: treat as
true(prepare hot water) to preserve current behavior until the user adds the entity