Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ A Home Assistant dashboard card to view and edit the weekly time programs of a V

- **Heating zones 1–3, hot water and circulation**, each on its own tab
- **Edit several days at once**: quick selection for Mo–Fr, Sa–Su or all days
- **Up to 3 slots per day** in 10-minute steps, with a temperature per slot
- **Up to 12 slots per day** for heating zones, 3 for hot water and circulation, in 10-minute steps, with a
temperature per slot
- **Checks before writing**: overlaps, end before start, temperatures out of range
- **Verified writes**: every day is read back from the controller; retry, continue or restore if one doesn't match
- **Read-only preview mode** for a compact week overview, with a marker for the current time
Expand All @@ -35,7 +36,7 @@ The card needs a working ebusd setup first. Hardware and configuration all come
[ebusd wiki](https://github.com/john30/ebusd/wiki) for installation (also available as Home Assistant add-on)
- the **message definitions** from [john30/ebusd-configuration](https://github.com/john30/ebusd-configuration)
as a **local copy with additions**: upstream reads only the first time slot of each day and hot water without
temperature. The card needs all three slots, see
temperature. The card needs all slots of each day, see
[ebusd configuration](https://citoki.github.io/ebusd-time-program/ebusd-config/)
- **MQTT** in ebusd with Home Assistant discovery (`mqtt-hassio.cfg`), see the
[MQTT integration wiki](https://github.com/john30/ebusd/wiki/MQTT-integration)
Expand Down
4 changes: 2 additions & 2 deletions dev/scenarios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { programEntityIds } from "../src/adapters/mqtt.js";
import { entityId, type ResolvedConfig } from "../src/config.js";
import type { HassEntity } from "../src/hass.js";
import { readMessage } from "../src/model/payload.js";
import { MAX_SLOTS, PROGRAMS } from "../src/model/programs.js";
import { PROGRAMS } from "../src/model/programs.js";
import type { Day, ProgramSpec } from "../src/model/types.js";
import type { FakeEbusd } from "../test/fake-ebusd.js";
import { sampleStates } from "../test/fixtures/hass-states.js";
Expand Down Expand Up @@ -37,7 +37,7 @@ function setAll(states: Record<string, HassEntity>, cfg: ResolvedConfig, spec: P
/** The slot sensors of some days (count stays known), like ebusd not having read them yet. */
function setDays(states: Record<string, HassEntity>, cfg: ResolvedConfig, spec: ProgramSpec, days: Day[], state: string) {
for (const day of days) {
for (let s = 0; s < MAX_SLOTS; s++) {
for (let s = 0; s < spec.maxSlots; s++) {
const msg = readMessage(spec, day, s);
for (const field of ["htm", "htm_1", "slottemp"]) {
const id = entityId(cfg, msg, field);
Expand Down
14 changes: 10 additions & 4 deletions docs/ebusd-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ automatically. For the time programs they are not complete yet, so you need a **
- read only the **first slot** of each day (`Z1Timer_Monday0`, but no `…Monday1` and `…Monday2`),
- read and write hot water slots **without a temperature**.

The controller has up to three slots per day, with a temperature for zones and hot water. The card needs all
of them, otherwise a program stays at **Waiting for values from eBUSd**.
The controller has up to 12 slots per day for zones and 3 for hot water and circulation, with a temperature
for zones and hot water. The card needs every slot a day uses, otherwise a program stays at
**Waiting for values from eBUSd**.

## 1. Use a local copy of the definitions

Expand Down Expand Up @@ -73,11 +74,16 @@ Each program needs three kinds of messages in `15.ctlv2.csv`. `<P>` is the progr
| Message | Direction | Fields the card uses |
|---|---|---|
| `<P>_Timeslots` (older configs: `_Timeframes`) | read, polled | `slotcount`, `slotcount_1` … `slotcount_6` (Monday … Sunday) |
| `<P>_<Day>0`, `<P>_<Day>1`, `<P>_<Day>2` | read, polled | `htm` (start), `htm_1` (end), `slottemp` (not for circulation) |
| `<P>_<Day>0`, `<P>_<Day>1`, `<P>_<Day>2` (zones up to `<P>_<Day>11`) | read, polled | `htm` (start), `htm_1` (end), `slottemp` (not for circulation) |
| `<P>_<Day>` | write | `slotindex`, `slotcount`, `htm`, `htm_1`, `slottemp` (circulation: a constant instead) |

So per program: one count message, 21 read messages (7 days × 3 slots) and 7 write messages.

Heating zones can have up to **12 slots** per day (hot water and circulation: 3). If you use more than 3 slots on a
zone, add the read messages `<P>_<Day>3` … `<P>_<Day>11` (slot bytes `03` … `0b`) as far as you need them; a day
with more slots than read messages stays at **Waiting for values from eBUSd**. The write message is the same for
any number of slots.

### Example: zone 1, Monday

These are the lines from the tested configuration. The other days only differ in the name and in one byte of the
Expand Down Expand Up @@ -106,7 +112,7 @@ All timer messages use `b555`. The id encodes program, day and slot:
| `ZZ` zone | `00` zone 1, `01` zone 2, `02` zone 3 (hot water and circulation: `00`) |
| `TT` type | `00` heating, `02` hot water, `03` circulation |
| `DD` day | `00` Monday … `06` Sunday |
| `SS` slot | `00`, `01`, `02` |
| `SS` slot | `00` … `02` (zones: up to `0b`) |

For example hot water: `HwcTimer_Timeslots` = `a40002`, `HwcTimer_Monday0` = `a500020000`,
`HwcTimer_Monday` = `a6000200`. Zone 2: `Z2Timer_Monday0` = `a501000000`.
Expand Down
6 changes: 3 additions & 3 deletions docs/ebusd.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ You need:
[Home Assistant add-on](https://github.com/LukasGrebe/ha-addons), with MQTT enabled
- Home Assistant MQTT discovery in ebusd (`--mqttint=/etc/ebusd/mqtt-hassio.cfg`), see the
[ebusd MQTT wiki](https://github.com/john30/ebusd/wiki/MQTT-integration)
- the controller's message definitions, e.g. `15.ctlv2.csv` for the VRC 720, with **all three slots per day**
- the controller's message definitions, e.g. `15.ctlv2.csv` for the VRC 720, with **all slots per day**
of the `…Timer_<Day>` messages. The upstream definitions don't have them yet, see
[ebusd configuration](ebusd-config.md)

## What the card reads

For each program and day the controller has up to three slots. ebusd exposes each slot as one message, and
For each program and day the controller has up to 12 slots (zones) or 3 slots (hot water, circulation). ebusd exposes each slot as one message, and
discovery turns its fields into sensors. With the defaults (`mqtt_prefix: ebusd`, `circuit: ctlv2`):

| Entity | Content |
|---|---|
| `sensor.ebusd_ctlv2_z1timer_monday0_htm` | start of slot 0 on Monday, e.g. `06:00` |
| `sensor.ebusd_ctlv2_z1timer_monday0_htm_1` | end of slot 0 |
| `sensor.ebusd_ctlv2_z1timer_monday0_slottemp` | temperature of slot 0 (zones and hot water) |
| `sensor.ebusd_ctlv2_z1timer_monday1_…`, `…monday2_…` | slots 1 and 2 |
| `sensor.ebusd_ctlv2_z1timer_monday1_…` … `…monday11_…` | slots 1 … 11 (hot water and circulation: up to 2) |
| `sensor.ebusd_ctlv2_z1timer_timeslots_slotcount` | number of slots on Monday |
| `sensor.ebusd_ctlv2_z1timer_timeslots_slotcount_1` … `_6` | number of slots Tuesday … Sunday |
| `sensor.ebusd_ctlv2_z1setbacktemp` | set-back temperature of zone 1, shown in the info text (optional; `number.…` when writes are discovered too; older configs: `…_z1nighttemp`) |
Expand Down
3 changes: 2 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ checks each day against what the controller reports back.
- **Heating zones 1–3, hot water and circulation**, each on its own tab
- **Edit several days at once**: quick selection for Mo–Fr, Sa–Su or all days; days with different programs are
pointed out before you overwrite them
- **Up to 3 slots per day** in 10-minute steps, with a temperature per slot for zones and hot water
- **Up to 12 slots per day** for heating zones and 3 for hot water and circulation, in 10-minute steps, with a
temperature per slot for zones and hot water
- **Checks before writing**: overlaps, end before start, temperatures out of range, touching slots that could be merged
- **Verified writes**: every day is read back from the controller; if one doesn't match, retry, continue or restore
- **Week preview** with a marker for the current time, and a read-only [preview mode](usage.md#preview-mode)
Expand Down
4 changes: 3 additions & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ the program of one of them; pick which day to start from, or **Start empty**. Wh

## Edit time slots

Each day has up to **3 slots**. Times are set in 10-minute steps, `24:00` is allowed as an end time. Some controllers
Each day has up to **12 slots** for heating zones and up to **3 slots** for hot water and circulation. These are
the controller's limits: the VRC 720 documentation allows 12 slots for zones, even though the myVAILLANT app only
offers 3. Times are set in 10-minute steps, `24:00` is allowed as an end time. Some controllers
(e.g. Saunier Duval BASS3) also accept single minutes, such as `17:22` written directly via eBUS: the card shows
and keeps such times; changing one moves it to the next 10-minute step.

Expand Down
7 changes: 3 additions & 4 deletions src/adapters/mqtt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { COUNT_MESSAGE_CANDIDATES, entityId, type ResolvedConfig } from "../conf
import type { Hass } from "../hass.js";
import { parseCount, parseDay, type RawSlot } from "../model/parse.js";
import { readMessage } from "../model/payload.js";
import { MAX_SLOTS } from "../model/programs.js";
import { DAYS, type Day, type ProgramSpec, type Slot } from "../model/types.js";

/**
Expand Down Expand Up @@ -46,7 +45,7 @@ export function programEntityIds(cfg: ResolvedConfig, spec: ProgramSpec, countMe
const ids: string[] = [];
DAYS.forEach((day, i) => {
ids.push(entityId(cfg, `${spec.messagePrefix}_${countMessage}`, countField(i)));
for (let s = 0; s < MAX_SLOTS; s++) {
for (let s = 0; s < spec.maxSlots; s++) {
const msg = readMessage(spec, day, s);
ids.push(entityId(cfg, msg, FIELD.start), entityId(cfg, msg, FIELD.end));
if (spec.temp) ids.push(entityId(cfg, msg, FIELD.temp));
Expand All @@ -69,9 +68,9 @@ export function readProgram(hass: Hass, cfg: ResolvedConfig, spec: ProgramSpec):
const state = (id: string) => hass.states[id]?.state;
const days = { ...empty };
DAYS.forEach((day, i) => {
const count = parseCount(state(entityId(cfg, `${spec.messagePrefix}_${countMessage}`, countField(i))));
const count = parseCount(state(entityId(cfg, `${spec.messagePrefix}_${countMessage}`, countField(i))), spec);
const raw: RawSlot[] = [];
for (let s = 0; s < MAX_SLOTS; s++) {
for (let s = 0; s < spec.maxSlots; s++) {
const msg = readMessage(spec, day, s);
const slot: RawSlot = {
start: state(entityId(cfg, msg, FIELD.start)),
Expand Down
3 changes: 1 addition & 2 deletions src/components/slot-list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { html, nothing, svg, type TemplateResult } from "lit";
import { formatTemp, issueMessage, UI } from "../i18n/index.js";
import { MAX_SLOTS } from "../model/programs.js";
import type { ProgramSpec, Slot } from "../model/types.js";
import type { Issue } from "../model/validate.js";
import { tempBand } from "./colors.js";
Expand Down Expand Up @@ -170,7 +169,7 @@ function renderMerge(p: SlotListProps, i: number): TemplateResult {
}

function renderAdd(p: SlotListProps, count: number): TemplateResult {
const left = MAX_SLOTS - count;
const left = p.spec.maxSlots - count;
return html`<div class="add-row">
<button class="add" ?disabled=${p.addBlocked !== null} @click=${p.onAdd}>${icon(ICON_ADD)} ${UI.addSlot}</button>
<span class="add-note">${p.addBlocked ?? UI.slotsLeft(left)}</span>
Expand Down
3 changes: 1 addition & 2 deletions src/ebusd-time-program-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { accentStyle, COUNT_MESSAGE_CANDIDATES, DEFAULTS, isServiceSource, resol
import type { Hass } from "./hass.js";
import { formatTemp, programName, setLanguage, UI } from "./i18n/index.js";
import { clampTemp, defaultTemp, openTime, mergedSlot, mergeNeedsTemp, mergeSlots, removeSlot, sortSlots, suggestSlot, updateSlot } from "./model/edit.js";
import { MAX_SLOTS } from "./model/programs.js";
import { fromMinutes, toMinutes } from "./model/time.js";
import { DAYS, type Day, type ProgramSpec, type Slot, type Week } from "./model/types.js";
import { validateDay, validateSelection, type Issue } from "./model/validate.js";
Expand Down Expand Up @@ -869,7 +868,7 @@ function sheetPatch(sheet: SheetState): Partial<Slot> {
}

function addBlocked(slots: readonly Slot[], spec: ProgramSpec): string | null {
if (slots.length >= MAX_SLOTS) return UI.issues.too_many_slots({ max: MAX_SLOTS });
if (slots.length >= spec.maxSlots) return UI.issues.too_many_slots({ max: spec.maxSlots });
return suggestSlot(slots, spec) ? null : UI.noGap;
}

Expand Down
6 changes: 3 additions & 3 deletions src/model/edit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MAX_SLOTS, TIME_STEP } from "./programs.js";
import { TIME_STEP } from "./programs.js";
import { perSlotTemp } from "./week.js";
import { fromMinutes, isOnGrid, MINUTES_PER_DAY, roundToStep, toMinutes } from "./time.js";
import type { ProgramSpec, Slot, TempRange } from "./types.js";
Expand Down Expand Up @@ -133,10 +133,10 @@ const NEW_SLOT_GAP = 60;
/**
* Proposal for "Add time slot": one hour, one hour after the last slot; if
* that doesn't fit, the first free gap of the day. The temperature is copied
* from the last slot. Returns null when the day is full (3 slots or no gap).
* from the last slot. Returns null when the day is full (`spec.maxSlots` or no gap).
*/
export function suggestSlot(slots: readonly Slot[], spec: ProgramSpec): Slot | null {
if (slots.length >= MAX_SLOTS) return null;
if (slots.length >= spec.maxSlots) return null;
const ranges = sortSlots(slots)
.map((s) => ({ start: toMinutes(s.start), end: toMinutes(s.end) }))
.filter((r): r is { start: number; end: number } => r.start !== null && r.end !== null && r.end > r.start);
Expand Down
7 changes: 3 additions & 4 deletions src/model/parse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { MAX_SLOTS } from "./programs.js";
import { toMinutes } from "./time.js";
import type { ProgramSpec, Slot } from "./types.js";

Expand All @@ -13,11 +12,11 @@ export interface RawSlot {
temp?: string | undefined;
}

/** Parse a slot-count sensor state (`"2"`) into 0..MAX_SLOTS, or null if unusable. */
export function parseCount(state: string | undefined): number | null {
/** Parse a slot-count sensor state (`"2"`) into 0..spec.maxSlots, or null if unusable. */
export function parseCount(state: string | undefined, spec: ProgramSpec): number | null {
if (state === undefined) return null;
const n = Number(state);
return Number.isInteger(n) && n >= 0 && n <= MAX_SLOTS ? n : null;
return Number.isInteger(n) && n >= 0 && n <= spec.maxSlots ? n : null;
}

/**
Expand Down
13 changes: 11 additions & 2 deletions src/model/programs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import type { ProgramId, ProgramSpec } from "./types.js";

/** Vaillant limit: at most 3 slots per day. Fixed, not configurable. */
export const MAX_SLOTS = 3;
/**
* Slots per day of the heating zones. The VRC 720 documentation allows up to 12
* (the myVAILLANT app only offers 3); BASS3 confirms 12 on eBUS (issue #18).
*/
export const ZONE_MAX_SLOTS = 12;

/** Slots per day of hot water and circulation: 3 (issue #18). */
export const HWC_MAX_SLOTS = 3;

/** Grid of the controller / myVAILLANT app in minutes. Fixed, not configurable. */
export const TIME_STEP = 10;
Expand All @@ -14,6 +20,7 @@ const zone = (n: 1 | 2 | 3): ProgramSpec => ({
id: `z${n}`,
messagePrefix: `Z${n}Timer`,
temp: { min: 5, max: 30, step: 0.5 },
maxSlots: ZONE_MAX_SLOTS,
lowTempWarning: 15,
defaultTemp: 20,
setbackMessages: [`Z${n}SetbackTemp`, `Z${n}NightTemp`],
Expand All @@ -27,12 +34,14 @@ export const PROGRAMS: Record<ProgramId, ProgramSpec> = {
id: "hwc",
messagePrefix: "HwcTimer",
temp: { min: 35, max: 70, step: 0.5 },
maxSlots: HWC_MAX_SLOTS,
defaultTemp: 50,
sharedTempMessages: ["HwcTempDesired"],
},
cc: {
id: "cc",
messagePrefix: "CcTimer",
temp: null,
maxSlots: HWC_MAX_SLOTS,
},
};
2 changes: 2 additions & 0 deletions src/model/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export interface ProgramSpec {
messagePrefix: string;
/** null = slots carry no temperature (CC). */
temp: TempRange | null;
/** Controller limit of slots per day: 12 for zones, 3 for HWC and CC. Fixed, not configurable. */
maxSlots: number;
/** Below this a warning is shown (does not block). */
lowTempWarning?: number;
/** Temperature of a new slot when there is no previous slot to copy. */
Expand Down
5 changes: 2 additions & 3 deletions src/model/validate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { MAX_SLOTS } from "./programs.js";
import { isOnStep, roundToStep, toMinutes } from "./time.js";
import type { Day, ProgramSpec, Slot } from "./types.js";
import { perSlotTemp } from "./week.js";
Expand Down Expand Up @@ -41,8 +40,8 @@ export const hasErrors = (issues: readonly Issue[]): boolean =>
export function validateDay(slots: readonly Slot[], spec: ProgramSpec): Issue[] {
const issues: Issue[] = [];

if (slots.length > MAX_SLOTS) {
issues.push({ level: "error", code: "too_many_slots", params: { max: MAX_SLOTS } });
if (slots.length > spec.maxSlots) {
issues.push({ level: "error", code: "too_many_slots", params: { max: spec.maxSlots } });
}

const parsed: { idx: number; start: number; end: number; temp: number | undefined }[] = [];
Expand Down
3 changes: 3 additions & 0 deletions test/edit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ describe("suggestSlot", () => {
{ start: "05:00", end: "06:00" },
];
expect(suggestSlot(three, cc)).toBeNull();
expect(suggestSlot(three.map((s) => ({ ...s, temp: 20 })), z1)).not.toBeNull();
const twelve: Slot[] = Array.from({ length: 12 }, (_, i) => ({ start: `${String(i + 1).padStart(2, "0")}:00`, end: `${String(i + 1).padStart(2, "0")}:30`, temp: 20 }));
expect(suggestSlot(twelve, z1)).toBeNull();
expect(suggestSlot([{ start: "00:00", end: "24:00" }], cc)).toBeNull();
});

Expand Down
6 changes: 3 additions & 3 deletions test/fake-ebusd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { countField, detectCountMessage, FIELD, readProgram } from "../src/adapt
import { entityId, type ResolvedConfig } from "../src/config.js";
import type { Hass, HassEntity } from "../src/hass.js";
import { readMessage, writeMessage } from "../src/model/payload.js";
import { MAX_SLOTS, PROGRAMS } from "../src/model/programs.js";
import { PROGRAMS } from "../src/model/programs.js";
import { DAYS, type Day, type ProgramSpec, type Slot } from "../src/model/types.js";

/**
Expand Down Expand Up @@ -225,7 +225,7 @@ export class FakeEbusd {
/** Message names ebusd reads for a program: the count message, then each day's slots. */
readMessages(spec: ProgramSpec): string[] {
const count = `${spec.messagePrefix}_${detectCountMessage(this.hass(), this.cfg, spec) ?? "Timeframes"}`;
return [count, ...DAYS.flatMap((day) => Array.from({ length: MAX_SLOTS }, (_, s) => readMessage(spec, day, s)))];
return [count, ...DAYS.flatMap((day) => Array.from({ length: spec.maxSlots }, (_, s) => readMessage(spec, day, s)))];
}

private onGet(message: string): void {
Expand All @@ -241,7 +241,7 @@ export class FakeEbusd {
});
}
for (const day of DAYS) {
for (let s = 0; s < MAX_SLOTS; s++) {
for (let s = 0; s < spec.maxSlots; s++) {
const msg = readMessage(spec, day, s);
if (msg !== message) continue;
const slot = this.controllerDay(spec, day)[s];
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/hass-states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { countField, FIELD } from "../../src/adapters/mqtt.js";
import { entityId, resolveConfig } from "../../src/config.js";
import type { HassEntity } from "../../src/hass.js";
import { readMessage } from "../../src/model/payload.js";
import { MAX_SLOTS, PROGRAMS } from "../../src/model/programs.js";
import { PROGRAMS } from "../../src/model/programs.js";
import { DAYS, type ProgramId, type Slot, type Week } from "../../src/model/types.js";

/**
Expand Down Expand Up @@ -61,7 +61,7 @@ export function sampleStates(weeks: Partial<Record<ProgramId, Week>> = SAMPLE_WE
DAYS.forEach((day, i) => {
set(entityId(cfg, `${spec.messagePrefix}_Timeframes`, countField(i)), String(days[day].length));
// ebusd reads unused slots as 00:00–00:00 without a temperature
for (let s = 0; s < MAX_SLOTS; s++) {
for (let s = 0; s < spec.maxSlots; s++) {
const slot = days[day][s];
const msg = readMessage(spec, day, s);
set(entityId(cfg, msg, FIELD.start), slot?.start ?? "00:00");
Expand Down
Loading