> For the complete documentation index, see [llms.txt](https://wiki.inels.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.inels.com/inels-bus/inels-design-manager-idm3/tutorial-time-control-and-schedules.md).

# Tutorial 7 — time control

*Part 2 — Tutorials. Continues the project from* [*Tutorial 6*](/inels-bus/inels-design-manager-idm3/tutorial-heating-and-cooling.md)*.*

***

## What you will build

* Outside lights that switch on at dusk and off at dawn, all year, with no schedule to maintain
* A garden watering system that runs on selected days
* A holiday mode that runs between two dates

***

## 11.1 Programs are actors

Everything so far has been triggered by a person pressing something. A **program** is triggered by time — and once defined, it behaves exactly like any other actor. You drag a wire from it and give that wire an action and a function, just as you did with a button.

Programs have two actions:

| Action                     | Fires when                 |
| -------------------------- | -------------------------- |
| `Program value switch ON`  | the program becomes active |
| `Program value switch OFF` | it becomes inactive        |

That is the whole idea. A program turns "it is 07:00 on a Tuesday" into something you can wire.

### The three kinds

| Type           | Shape                          | Use for                                    |
| -------------- | ------------------------------ | ------------------------------------------ |
| **Periodical** | a moment, repeating            | watering at 06:00 on Mondays and Thursdays |
| **Two-state**  | on/off stretches across a week | night-time setback, weekday-only equipment |
| **Continuous** | one stretch between two dates  | holiday mode, seasonal switching           |

Heating uses two more — **Heating/Cooling - week** and **Heating/Cooling day** — which you already met in [Tutorial 6](/inels-bus/inels-design-manager-idm3/tutorial-heating-and-cooling.md).

All of them live in **Managers → System manager → System programs**.

***

## 11.2 Dusk to dawn, without a schedule

The best schedule for outside lights is no schedule. Sunset moves by three hours across the year; any fixed time you pick will be wrong for ten months.

The **Astronomical-Module** calculates sunrise and sunset from the date and your location, and presents them as ordinary digital inputs you can wire.

### Add the module

1. **Project** → **Device manager**.
2. Select the **central unit**, then click **New slave**.
3. Choose **Astronomical-Module** → **OK**.

Only **one** astronomical module is allowed per project, and its address is fixed.

### Tell it where the building is

Select the module and open **Parameters**:

| Field                        | What to do                                                               |
| ---------------------------- | ------------------------------------------------------------------------ |
| **Description**              | `Sun and moon`                                                           |
| **Use city**                 | tick it, then pick the nearest of **50 predefined cities** from **City** |
| **Longitude** / **Latitude** | *or* untick **Use city** and type the coordinates to two decimals        |

Coordinates are more accurate; a city is faster and close enough for lighting.

### What it gives you

| Device                                | Meaning                                         |
| ------------------------------------- | ----------------------------------------------- |
| **Sunshine-DIN1** … **Sunshine-DIN4** | daylight — `ON` from sunrise, `OFF` from sunset |
| **New-Moon-DIN**                      | `ON` when less than 25 % of the moon is lit     |
| **Moon-First-Quarter-DIN**            | `ON` between 25 % and 75 %                      |
| **Full-Moon-DIN**                     | `ON` at 75 % or more                            |
| **Moon-Third-Quarter-DIN**            | `ON` between 25 % and 75 %                      |

**There are four sunshine inputs because each can carry its own offset.** That is the useful part:

| Field              | Range                   | Meaning                                                    |
| ------------------ | ----------------------- | ---------------------------------------------------------- |
| **Sunrise Offset** | −82801 … +82801 seconds | negative = before the calculated sunrise, positive = after |
| **Sunset Offset**  | −82801 … +82801 seconds | the same, for sunset                                       |

So `Sunshine-DIN1` can be true daylight, `Sunshine-DIN2` can switch 30 minutes before sunset (`Sunset Offset = -1800`) for the drive lights, and `Sunshine-DIN3` can switch an hour after sunrise for something else.

### Wire the outside light

1. **Device manager** → expand the astronomical module and give `Sunshine-DIN2` a **Sunset Offset** of `-1800` and a **Sunrise Offset** of `0`.
2. **Design** workspace tab → drag an input icon onto the plan → **Connect** it to `Sunshine-DIN2` → name it `Daylight`.
3. **Function** workspace tab → **Add connection** → drag `Daylight` → your outside light (reuse `Stair light` if you have no outdoor circuit).
4. **Wire manager** → name it `Outside light — dusk to dawn` → add two functions:
   * **Action:** `Digital IN switch OFF` → **User function:** `DIGITAL_ON`
   * **Action:** `Digital IN switch ON` → **User function:** `DIGITAL_OFF`
5. Close, save, upload.

Read it carefully — the logic is inverted on purpose. The input is *daylight*, so: **daylight ends → light on**, **daylight begins → light off**.

> **Sunrise, sunset and moon phase are calculated when the project is saved to the central unit.** They are not recalculated live from an internet source, so the CU's clock and time zone must be right. Check them in **CU configuration** ([Chapter 22](/inels-bus/inels-design-manager-idm3/idm3-central-unit-configuration.md)).

***

## 11.3 A periodical program — watering

A **periodical** program fires at a moment, repeatedly.

1. **Managers** → **System manager** → **System programs** → **+**.
2. Choose **Periodical** → **OK**.
3. Fill in:
   * **Program name:** `WATERING_MORNING`
   * **Activation time/dispersion:** `06:00`
4. Choose one of three repeat modes:

| Mode                | Repeats | Tick boxes select        |
| ------------------- | ------- | ------------------------ |
| **Every week**      | weekly  | which days of the week   |
| **Every month**     | monthly | which days of the month  |
| **Selected months** | daily   | which months of the year |

5. Pick **Every week** and tick **Monday** and **Thursday**.
6. Click **✓**.

> **You must tick at least one day or month.** With none selected, the confirm button stays unavailable. It is easy to miss and looks like the dialog is broken.

Now wire it:

7. **Design** tab → drag a program icon onto the plan and assign it `WATERING_MORNING`.
8. **Function** tab → **Add connection** → drag the program → your watering valve output.
9. **Wire manager** → name it `Watering` → **+**:
   * **Action:** `Program value switch ON`
   * **User function:** a `Digital_Impulse_ON` of your chosen duration — say a 20-minute `DIGITAL_IMPULSE_20MIN` you define in Function manager
10. Save, upload.

The impulse does the timing, so you need no "off" program at all.

> **Connecting programs, timers and counters.** These live inside the central unit rather than on a bus, so you may find yourself dragging a wire **from the central unit icon**. When you do, a **Select devices to create wires** dialog opens and you choose which timer, counter or program you meant.

***

## 11.4 A two-state program — night setback

A **two-state** program is on for some stretches of the week and off for others — the same style of weekly graph you drew for heating.

1. **System programs** → **+** → **Two-state** → **OK**.
2. **Program name:** `NIGHT`
3. Select a day and place time stamps, up to **16 per day**:
   * **Mark** adds a single time stamp
   * **Mark** then **Window** adds a pair — use this for a "from 22:00 to 06:00" block
4. Set each stretch on or off by clicking below the stamps. **Green is ON, red is OFF.**
5. Right-click the day label → tick target days or use **Working days** / **Weekend** / **All week** → **Copy actual program**.
6. **✓**.

Wire `Program value switch ON` → dim the corridor lights to 10 %, and `Program value switch OFF` → back to normal. The building now has a night mode.

> Two-state programs, like heating time plans, can be **edited live** after the first upload — change the graph and confirm with **✓**.

***

## 11.5 A continuous program — holiday mode

A **continuous** program is a single stretch between two dates.

1. **System programs** → **+** → **Continuous** → **OK**.
2. Fill in **Program name**, **Start** date and **Stop** date.
3. **✓**.

It switches **ON at 00:00:00 on the start date** and **OFF at 23:59:00 on the stop date**.

Wire `Program value switch ON` → `HEATING_COOLING_HOLIDAY_PLAN` on your heating area, and `Program value switch OFF` → `HEATING_COOLING_NORMAL_PLAN`. Set the dates before the client leaves and the house looks after itself.

***

## 11.6 Choosing the right one

| You want                                        | Use                                                                                                                     |
| ----------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| Something at a fixed clock time, on chosen days | **Periodical**                                                                                                          |
| Something on for stretches of the week          | **Two-state**                                                                                                           |
| Something between two calendar dates            | **Continuous**                                                                                                          |
| Something that tracks the sun through the year  | **Astronomical module**                                                                                                 |
| Temperature by hour of the week                 | **Heating/Cooling - week** ([Ch. 10](/inels-bus/inels-design-manager-idm3/tutorial-heating-and-cooling.md))             |
| A delay after an event                          | not a program — a **timer** ([Ch. 12](/inels-bus/inels-design-manager-idm3/tutorial-timers-counters-and-conditions.md)) |

The last row matters. Programs answer *"what time is it?"*. Timers answer *"how long since something happened?"*. Reaching for a program when you needed a timer is a common wrong turn.

***

## What you learned

* A program is an **actor**, with `Program value switch ON` / `OFF` as its actions
* **Periodical** = a repeating moment · **Two-state** = weekly on/off stretches · **Continuous** = between two dates
* The **astronomical module** gives sunrise, sunset and moon phase as digital inputs
* Four sunshine inputs, each with its own **Sunrise/Sunset Offset** in seconds
* Sun times are calculated **at upload**, so the CU clock and time zone must be correct
* Programs need at least one day or month ticked before they can be saved

***

## Try this before moving on

1. Give `Sunshine-DIN3` a **Sunrise Offset** of `+3600` and use it for something that should start an hour after dawn.
2. Build a two-state program that only allows the doorbell to sound between 08:00 and 21:00 — you will use it as a **condition** in the next chapter.
3. Set up a continuous program for the summer and use it to disable your heating boost button.

***

**Next:** [Chapter 12 — Tutorial 8: logic and conditions](/inels-bus/inels-design-manager-idm3/tutorial-timers-counters-and-conditions.md) — timers, counters, system bits, and rules that fire only sometimes.
