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
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# heating-control

A small web page to adjust the heating per room from a phone on the home network: change a room's target temperature, or mark a window as open so the room doesn't heat. It controls Sonoff TRVZB thermostats through Zigbee2MQTT.
A small web page to adjust the heating per room from a phone on the home network: change a room's target temperature, mark a window as open so the room doesn't heat, or lower every room while away and get the old targets back on their own. It controls Sonoff TRVZB thermostats through Zigbee2MQTT.

<img src="docs/screenshot.png" alt="The heating page at phone width: a green All OK status in the top right, then Office and Bedroom cards, each with the room temperature, whether it is heating, the target, buttons to change it, and Air 5, 15, 30 and 60 buttons" width="375">

Expand All @@ -17,6 +17,15 @@ Airing is saved, so it carries on after a restart or release: a room that should
- Commands repeat until the thermostat confirms them, every 30 s for about 5 minutes. A target then gives up and shows the thermostat's value. Off and heat-again keep trying every 5 minutes and show a problem on the page, because giving up would mean heating with the window open or a cold room.
- A thermostat that is off with no airing is left alone, because someone may have turned it off on purpose. The page offers "Heat again" for it.

## Away

"Away…" lowers every room to one target until a date and time, then raises each room back to the target it had before, on its own. The page suggests 17 °C and the next day; the end can be at most 30 days ahead. While away, the page shows when it ends and what each room gets back, and "Back now" ends it early.

- Only rooms whose target is known take part. A room whose target someone changed during away is left alone at the end.
- Starting away again during away sets a new end and target, and keeps the targets from before.
- Raising the target back follows the rules for the end of airing: it repeats until the thermostat confirms it and never gives up, and the page shows a problem if it takes longer than about 5 minutes. A thermostat that is off then gets the target once it heats again, and a room airing at the end gets it when airing ends.
- Away is saved, so it carries on after a restart. If the end passed while the service was down, the targets come back as soon as it runs again.

## Requirements

| Needs | Why | Tested with |
Expand All @@ -36,11 +45,11 @@ It also needs a writable directory that survives a restart, `dataDir`: the chart

## Saved state

The service keeps one SQLite database, `heating-control.db` in `dataDir`. It holds only what can't come back from the thermostats: for each room that is airing, when airing ends, the mode to go back to, and a target chosen during airing. A room's row is deleted once its thermostat confirms it is heating again, so the file is a few kilobytes. Everything else is in memory and comes back from the thermostats' reports. Migrations are part of the binary and run at start; an older binary refuses a newer database.
The service keeps one SQLite database, `heating-control.db` in `dataDir`. It holds only what can't come back from the thermostats: for each room that is airing, when airing ends, the mode to go back to, and a target chosen during airing; and for each room that is away, when away ends, the away target and the target to go back to. A room's rows are deleted once its thermostat confirms it is heating again or has its target back, so the file is a few kilobytes. Everything else is in memory and comes back from the thermostats' reports. Migrations are part of the binary and run at start; an older binary refuses a newer database.

A request is answered only once its change is saved. If saving fails, the change isn't made and the page shows "Not changed". When airing ends while the database can't be written, the room still gets heat back, and the database catches up later.

If the file is lost, nothing unsafe happens: a room that was airing stays off until someone taps "Heat again" (the `TrvStuckOffWarning` alert fires after 2 hours), and a target chosen during airing is lost. Because of that, restoring a backup is optional: an old copy may even hold airing that is long over, which then simply ends at once. The service starts with an empty database if there is none, but refuses to start if it can't open or migrate the file.
If the file is lost, nothing unsafe happens: a room that was airing stays off until someone taps "Heat again" (the `TrvStuckOffWarning` alert fires after 2 hours), a target chosen during airing is lost, and rooms that are away stay at the away target until someone raises them. Because of that, restoring a backup is optional: an old copy may even hold airing or away that is long over, which then simply ends at once. The service starts with an empty database if there is none, but refuses to start if it can't open or migrate the file.

To copy the database while the service runs:

Expand Down
Loading