
> [Sleep Class Reference](https://obniz.github.io/obniz/obnizjs/classes/obnizcore.obnizsystemmethods.html#sleep)
> [Sleep API Reference](https://www.google.com/search?q=/reference/websocket/system%23request-sleepseconds)

On devices equipped with obniz Board 1Y or OS7 (and later), you can reduce power consumption by putting the device into a sleep state. This enables battery-powered, cable-free operation.

For more details on sleep behavior for each OS, please refer to the [OS Sleep Page](https://www.google.com/search?q=../obnizos-for-esp32/sleep).


![](images/obniz_board_1y_sleep-1.jpg)

## How Sleep Mode Works

When the device enters sleep mode, all functions are suspended to achieve ultra-low power consumption (see the bottom of this page for actual current consumption). This includes the deactivation of Wi-Fi and the onboard display.

The device will automatically wake up and restart based on a specific "Trigger" defined when entering sleep mode. You can specify the following triggers:

1. **Elapsed Time (Seconds):** From 1 second up to 64,800 seconds (18 hours).
2. **Elapsed Time (Minutes):** From 1 minute up to 64,800 minutes (45 days).
3. **IO0 Rising Edge (obniz Board 1Y only):** Wakes up when the voltage on pin `io0` rises. (Threshold is TTL level, depending on the supplied voltage).
4. **IO0 Falling Edge (obniz Board 1Y only):** Wakes up when the voltage on pin `io0` falls. (Threshold is TTL level, depending on the supplied voltage).

When the sleep period ends or a trigger is activated, the device reboots and reconnects to the cloud, just as if it were power-cycled. If you manually turn the power off and on during sleep, the device will wake up and start immediately.

## obniz.sleepSeconds(number)
## obniz.sleepMinute(number)

You can trigger a timed sleep using [obniz.sleepSeconds()](https://www.google.com/search?q=https://obniz.github.io/obniz/obnizjs/classes/obnizcore.obniz.html%23sleepseconds) or [obniz.sleepMinute()](https://www.google.com/search?q=https://obniz.github.io/obniz/obnizjs/classes/obnizcore.obniz.html%23sleepminute). Additionally, [obniz.sleep()](https://www.google.com/search?q=https://obniz.github.io/obniz/obnizjs/classes/obnizcore.obniz.html%23sleep) allows you to use a `Date` object to specify a precise wakeup time.

```javascript
// Javascript Example

obniz.sleepSeconds(60); // Sleep for 60 seconds (1 min)

obniz.sleepMinute(60 * 24); // Sleep for one day

const dt = new Date();
dt.setHours(dt.getHours() + 1, 0, 0, 0); // Wake up at the start of the next hour
obniz.sleep(dt);

```

## obniz.sleepIoTrigger(boolean)

For the obniz Board 1Y, in addition to time-based triggers, you can use [obniz.sleepIoTrigger()](https://www.google.com/search?q=https://obniz.github.io/obniz/obnizjs/classes/obnizcore.obniz.html%23sleepiotrigger) to remain in sleep mode until a change is detected on pin `io0`.

```javascript
// Javascript Example

obniz.sleepIoTrigger(true);  // Wake up on a rising edge on io0

```

## Battery Life Estimation (For obniz Board 1Y)

Battery life varies depending on the device; please refer to the specific documentation for your hardware. For example, the current consumption of the obniz Board 1Y during sleep is approximately **20uA - 40uA (at 5V)**. You can estimate the total runtime based on the average active power consumption (approx. 120mA) as follows:

```javascript
// Simple calculation (ignoring battery self-discharge and voltage drop):

// S: Average active time per hour (minutes)
// Q: Battery capacity (mAh)

// Formula:
// Runtime (hours) = Q / ( (S/60 * 120) + ((60-S)/60 * 0.04) )

/* Example:
Using 3x AA Alkaline batteries (approx. 2000mAh):
If the device wakes up once a day for 2 minutes and sleeps for the rest of the time,
it will last for approximately 1 year.
*/

```
