Case File: The Heating That Switched Off at Midnight
The night-time heating schedule of a depot office works every evening and switches off at midnight on Fridays. Decide which automation rules are active at a list of moments, with the exact rules for a window that crosses midnight (its morning part belongs to the day after the listed one), a start that is included and an end that is not, and a window with equal start and end that is empty. Find the most active rule and the overlaps. Run it on schedules that you cannot see. The rules are generated for you alone.
Sabi Logistics · Building 1
The Heating That Switched Off at Midnight
The office was cold on Saturday morning, and the Friday night heating was said to run all night
Amaka Facilities manager ·
Amaka. The depot office heating is on a schedule: from 22:00 to 06:00, for the days that the night shift works. On Saturday morning the office was freezing and the heating had been off since midnight. The schedule says Friday, from 22:00 to 06:00. The supplier says that it is “working as designed”.
I have the list of rules (name, days, start, end) and a list of moments that I want checked: a day and a time. Please tell me which rules are active at each moment. I need to be told the exact rule that you apply to a window that crosses midnight, because I think that is where our schedule breaks.
The brief
What you need to know first.
- Minutes since midnight.
minutes("22:30")is22 * 60 + 30 = 1350. Comparing numbers is far safer than comparing text, and it makes the arithmetic of windows easy. Days are numbers: 0 is Monday, 6 is Sunday. - A normal window. When
start < end(08:00 to 17:00), the rule is active on a listed day whenstart <= m < end: the start is included and the end is not. At 17:00 exactly the rule has already ended. - A window that crosses midnight. When
start > end(22:00 to 06:00) there are two parts. The evening part (from the start to midnight) belongs to the listed day. The morning part (from midnight to the end) belongs to the day after a listed day: a rule that starts on Friday evening is still running on Saturday at 05:59, even though Saturday is not in its list. The day before daydis(d + 6) % 7(Monday, 0, is preceded by Sunday, 6). - An empty window. When
start == endthe window is empty: never active. - Fill in
minutes,is_active,schedule(req)returning{"active": [sorted names for each query], "most_active", "n_overlaps"}, thenresultandn_crossing. The checks runscheduleon requests that you cannot see: Friday night into Saturday morning, an empty window, exactly the start and the end time, Monday morning for a rule that starts on Sunday, and an empty request.
The lab gives you the data for this case, invented and generated for you alone.
Preparing your data…
On the bench
The lab checked the rule with a script. These are the checks and measurements that show the same thing in a real building.
| You want to | Do this | What you see |
|---|---|---|
| test a schedule that crosses midnight | Set the test clock or the automation test mode to the start minute, the last minute, the end minute and the first minute of the next day, and read the device state each time | the state at each edge moment, to compare with your table |
| see which rules are active now | Open the automation trace or the log of the hub for the last day | which rule ran at which time and what it did |
| check the time zone of the controller | Read the time and time zone setting of the hub and compare it with a trusted clock | a controller on the wrong zone, which shifts every schedule |
Never work on mains wiring or on systems that you are not trained and permitted to touch.
Amaka: “The supplier’s schedule had the morning part on the same day as the start, so Friday’s window ended at midnight. How do I stop this kind of mistake on other schedules?”
🔒 The debrief unlocks when you close the case. Finish the lab above.
The debrief
Amaka: “So the rule for midnight must be tested, not assumed.”
What a senior building technician would do next. Test every schedule that crosses midnight with the four edge moments: the start minute, the minute before the end, the end minute, and the first minute of the next day, for the last listed day and for the day after it. Prefer to avoid windows that cross midnight in the first place: write the rule as two rules (22:00 to 24:00 and 00:00 to 06:00) or as “on at 22:00” and “off at 06:00” events, which are easier to read and to check. Remember time zones and daylight saving time: the day when the clock changes has 23 or 25 hours, and a schedule in local time may skip or repeat an hour (in Nigeria there is no daylight saving time, but a system that is hosted abroad may use UTC or its own zone). Keep one place for the schedule, not three (the thermostat, the app and the building controller). And show the schedule to the people who live with it, as a week table.
The trap. Giving the morning part of a midnight window to the same day as its start. Friday’s Saturday-morning hours are Friday’s.
Write the schedule note
Write the note for the facilities manager: the rules for a normal window and for a window that crosses midnight (start included, end excluded, the morning part belongs to the day after the listed day, an empty window is never active), which rules are active at the moments in the case and how many rules cross midnight, why the office was cold on Saturday morning (the supplier's schedule ended Friday's window at midnight), and how to prevent it (test the four edge moments, write two rules instead of one that crosses midnight, time zones and daylight saving, one place for the schedule, a visible week table).
🧪 Want to practise this on your own computer? See how to set up your lab →