---
sidebar_position: 0
---

# power

The `sos.management.power` API groups together methods related to the power state of the device. Such as rebooting, shutting down,
setting timers.

<details>
    <summary>Power Management Capabilities</summary>
		| Capability | Description |
		|:------------|:-------------|
		| `SYSTEM_REBOOT` | If device supports system reboot power action |
		| `APP_RESTART` | If device supports app restart power action |
		| `TIMERS_PROPRIETARY` | If device supports proprietary timers |
		| `TIMERS_NATIVE` | If device supports native timers |
		| `SCHEDULE_POWER_ACTION` | If device supports scheduled power actions |

		If you want to check if the device supports those capabilities, use [`sos.management.supports()`](https://developers.signageos.io/sdk/sos_management/#supports).
</details>

## Methods

### appRestart()

The `appRestart()` method initializes a restart of the signageOS app.

```ts expandable
appRestart(): Promise<void>;
```

#### Return value

Resolves when the app restart is initiated.

#### Example

```ts
await sos.management.power.appRestart();
```

<Separator />

### clearScheduledReboots()

Removes all scheduled reboot rules from the device.

```ts expandable
clearScheduledReboots(): Promise<void>;
```

#### Return value

Resolves when all scheduled reboots are cleared.

#### Example

```ts
await sos.management.power.clearScheduledReboots();
```

<Separator />

### getProprietaryTimers()

The `getProprietaryTimers()` method returns a list of currently set
[proprietary timers](https://docs.signageos.io/hc/en-us/articles/4416384202642-Timers#h_01HCD14GEDP96AZV58NRSN2HNQ).

```ts expandable
getProprietaryTimers(): Promise<IProprietaryTimer[]>;
// show-more
interface IProprietaryTimer {
    type: ProprietaryTimerType;
    timeOn: string | null;
    timeOff: string | null;
    weekdays: ShortWeekdayType[];
}

type ShortWeekdayType = 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat';

```

#### Return value

Resolves with an array of proprietary timers.

#### Possible errors

If the timers cannot be retrieved.

#### Example

```ts
const timers = await sos.management.power.getProprietaryTimers();
```

<Separator />

### getScheduledReboots()

Returns all scheduled reboot rules on the device set by the `setScheduledReboot()` method.

```ts expandable
getScheduledReboots(): Promise<IScheduledRebootAction<IScheduledRebootRule>[]>;
// show-more
interface IScheduledRebootAction<TRule extends IScheduledRebootRuleRaw | IScheduledRebootRule> {
    id: string;
    rule: TRule;
}

interface IScheduledRebootRuleRaw {
    weekdays: WeekdayNumberType[];
    time: string;
}

type WeekdayNumberType = 0 | 1 | 2 | 3 | 4 | 5 | 6;

interface IScheduledRebootRule {
    weekdays: WeekdayType[];
    shortWeekdays: ShortWeekdayType[];
    time: string;
}

type WeekdayType = 'SUNDAY' | 'MONDAY' | 'TUESDAY' | 'WEDNESDAY' | 'THURSDAY' | 'FRIDAY' | 'SATURDAY';

type ShortWeekdayType = 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat';

```

#### Return value

Resolves with an array of scheduled reboot actions.

#### Example

```ts
await sos.management.power.getScheduledReboots();
```

<Separator />

### getTimers()

The `getTimers()` method returns a list of currently set native timers.

```ts expandable
getTimers(): Promise<ITimer[]>;
// show-more
interface ITimer {
    type: keyof typeof TimerType;
    timeOn: string | null;
    timeOff: string | null;
    weekdays: ShortWeekdayType[];
    volume: number;
}

type ShortWeekdayType = 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat';

```

#### Return value

Resolves with an array of timers.

#### Example

```ts
await sos.management.power.getTimers();
```

<Separator />

### removeScheduledReboot()

Removes scheduled reboot rule from the device (if it exists).

```ts expandable
removeScheduledReboot(id: string): Promise<void>;
```

#### Params

| Name | Type     | Required         | Description                   |
|------|----------|------------------|-------------------------------|
| `id` | `string` |  <div>Yes</div>  | ID of the rule to be removed. |

#### Return value

Resolves when the scheduled reboot is removed.

#### Possible errors

If the `id` is not a string or is empty.

#### Example

```ts
// Get scheduled reboots
const scheduledReboots = await sos.management.power.getScheduledReboots();

// Remove scheduled reboot on the first position
await sos.management.power.removeScheduledReboot(scheduledReboots[0].id);
```

<Separator />

### setProprietaryTimer()

The `setProprietaryTimer()` method creates or updates a
[proprietary timer](https://docs.signageos.io/hc/en-us/articles/4416384202642-Timers#h_01HCD14GEDP96AZV58NRSN2HNQ).

```ts expandable
setProprietaryTimer(type: ProprietaryTimerType, timeOn: string | null, timeOff: string | null, weekdays: (ShortWeekdayType | AnyString)[], keepAppletRunning?: boolean): Promise<void>;
// show-more
type ShortWeekdayType = 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat';

type AnyString = string & {};

```

#### Params

| Name                | Type                                | Required         | Description                                                                             |
|---------------------|-------------------------------------|------------------|-----------------------------------------------------------------------------------------|
| `type`              | ``TIMER_${number}``                 |  <div>Yes</div>  | The type of the timer (`TIMER_1`, ..., `TIMER_7`).                                      |
| `timeOn`            | `string \| null`                    |  <div>Yes</div>  | The time when the device should turn on.                                                |
| `timeOff`           | `string \| null`                    |  <div>Yes</div>  | The time when the device should turn off.                                               |
| `weekdays`          | `(AnyString \| ShortWeekdayType)[]` |  <div>Yes</div>  | The days of the week when the timer should be active (`mon`, ..., `sun`).               |
| `keepAppletRunning` | `boolean`                           |  <div>No</div>   | If `true`, the applet will be kept running when the timer is active on certain devices. |

#### Return value

Resolves when the proprietary timer is set.

#### Possible errors


- If the timer type is invalid or if the time format is incorrect.
- If the weekdays array contains an invalid weekday.
- If the `keepAppletRunning` parameter is not a boolean.
- If the `timeOn` or `timeOff` parameters do not match the expected time format (`HH:mm:ss`).
- If the `weekdays` parameter is not an array of strings.
- If the `weekdays` array contains an invalid weekday.
- If the `timeOn` or `timeOff` parameters do not match the expected time format (`HH:mm:ss`).
- If the `type` parameter is not a valid timer type (e.g., `TIMER_1`, `TIMER_2`, ..., `TIMER_7`).

#### Example

```ts
await sos.management.power.setProprietaryTimer("TIMER_2", "08:00:00", "22:00:00", ["mon", "tue", "wed", "thu", "fri", "sat", "sun"], false);
```

<Separator />

### setScheduledReboot()

Schedule an automatic reboot on the device. Calling this function will create one rule.
It is possible to set multiple rules, which can be later obtained by the `getScheduledReboots` function.

:::note
- Setting a new scheduled reboot on the device might take up to 10 minutes to show in the Box.
- Every new scheduled reboot rule gets a unique identifier generated by the device, which might be later returned by `getScheduledReboots()`.
:::

```ts expandable
setScheduledReboot(weekdays: (ShortWeekdayType | AnyString)[], time: string): Promise<void>;
// show-more
type ShortWeekdayType = 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat';

type AnyString = string & {};

```

#### Params

| Name       | Type                                | Required         | Description                                                           |
|------------|-------------------------------------|------------------|-----------------------------------------------------------------------|
| `weekdays` | `(AnyString \| ShortWeekdayType)[]` |  <div>Yes</div>  | `WeekdayType[]` Array of weekdays when the reboot should be executed. |
| `time`     | `string`                            |  <div>Yes</div>  | Time when the reboot should be executed. Format is `HH:mm:ss`.        |

#### Return value

Resolves when the scheduled reboot is set.

#### Possible errors


- If the `weekdays` parameter is not an array of strings.
- If the `time` parameter does not match the expected time format (`HH:mm:ss`).
- If the `weekdays` array contains an invalid weekday.
- If the `time` parameter is not a string or does not match the expected format (`HH:mm:ss`).
- If the `weekdays` array is empty or contains invalid values.

#### Example

```ts
// Schedule reboot every Monday at 3:00 AM
await sos.management.power.setScheduledReboot(["MONDAY"], "03:00:00");

// Schedule reboot every Monday and Friday at 7:30 PM / 19:30
await sos.management.power.setScheduledReboot(["MONDAY", "FRIDAY"], "19:30:00");
```

<Separator />

### setTimer()

The `setTimer()` method creates or updates a native timer.

```ts expandable
setTimer(type: keyof typeof TimerType, timeOn: string | null, timeOff: string | null, weekdays: (ShortWeekdayType | AnyString)[], volume: number): Promise<void>;
// show-more
type ShortWeekdayType = 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat';

type AnyString = string & {};

```

#### Params

| Name       | Type                                                                                      | Required         | Description                                                               |
|------------|-------------------------------------------------------------------------------------------|------------------|---------------------------------------------------------------------------|
| `type`     | `"TIMER_1" \| "TIMER_2" \| "TIMER_3" \| "TIMER_4" \| "TIMER_5" \| "TIMER_6" \| "TIMER_7"` |  <div>Yes</div>  | The type of the timer (`TIMER_1`, ..., `TIMER_7`).                        |
| `timeOn`   | `string \| null`                                                                          |  <div>Yes</div>  | The time when the device should turn on.                                  |
| `timeOff`  | `string \| null`                                                                          |  <div>Yes</div>  | The time when the device should turn off.                                 |
| `weekdays` | `ShortWeekdayType`                                                                        |  <div>Yes</div>  | The days of the week when the timer should be active (`mon`, ..., `sun`). |
| `volume`   | `number`                                                                                  |  <div>Yes</div>  | The volume level set when the device is turned on.                        |

#### Return value

Resolves when the timer is set.

#### Possible errors


- If the timer type is invalid.
- If the time format is incorrect.
- If the weekdays array contains an invalid weekday.
- If the `volume` parameter is not a number between 0 and 100.
- If the `timeOn` or `timeOff` parameters do not match the expected time format (`HH:mm:ss`).
- If the `weekdays` parameter is not an array of strings.
- If the `type` parameter is not a valid timer type (e.g., `TIMER_1`, `TIMER_2`, ..., `TIMER_7`).

#### Example

```ts
await sos.management.power.setTimer("TIMER_1", "08:00:00", "22:00:00", ["mon", "tue", "wed", "thu", "fri", "sat", "sun"], 30);
```

:::note[GitHub Example]

- [ Applet Example for Native Timers](https://github.com/signageos/applet-examples/tree/master/examples/management-js-api/timer)

:::

<Separator />

### systemReboot()

The `systemReboot()` method initializes a system reboot.

```ts expandable
systemReboot(): Promise<void>;
```

#### Return value

Resolves when the system reboot is initiated.

#### Example

```ts
await sos.management.power.systemReboot();
```

:::note[GitHub Example]

- [ Applet Example for System Reboot](https://github.com/signageos/applet-examples/tree/master/examples/management-js-api/system-reboot)

:::

<Separator />

### unsetProprietaryTimer()

The `unsetProprietaryTimer()` method removes the specified
[proprietary timer](https://docs.signageos.io/hc/en-us/articles/4416384202642-Timers#h_01HCD14GEDP96AZV58NRSN2HNQ).

```ts expandable
unsetProprietaryTimer(type: ProprietaryTimerType): Promise<void>;
```

#### Params

| Name   | Type                | Required         | Description                                        |
|--------|---------------------|------------------|----------------------------------------------------|
| `type` | ``TIMER_${number}`` |  <div>Yes</div>  | The type of the timer (`TIMER_1`, ..., `TIMER_7`). |

#### Return value

Resolves when the proprietary timer is removed.

#### Possible errors

If the timer type is invalid.

#### Example

```ts
await sos.management.power.unsetProprietaryTimer("TIMER_2");
```

<Separator />

### unsetTimer()

The `unsetTimer()` method removes the specified native timer.

```ts expandable
unsetTimer(type: keyof typeof TimerType): Promise<void>;
```

#### Params

| Name   | Type                                                                                      | Required         | Description                                        |
|--------|-------------------------------------------------------------------------------------------|------------------|----------------------------------------------------|
| `type` | `"TIMER_1" \| "TIMER_2" \| "TIMER_3" \| "TIMER_4" \| "TIMER_5" \| "TIMER_6" \| "TIMER_7"` |  <div>Yes</div>  | The type of the timer (`TIMER_1`, ..., `TIMER_7`). |

#### Return value

Resolves when the timer is removed.

#### Possible errors

If the timer type is invalid.

#### Example

```ts
await sos.management.power.unsetTimer("TIMER_2");
```