

# AlgoPIN Codes

AlgoPIN generates valid PIN codes for a lock without WiFi, cellular, or remote access to the lock.

## How It Works

```mermaid
sequenceDiagram
  Note over Your Server, Our Server: igloohome API
  Your Server->>Our Server: Request AlgoPIN
  Our Server-->>Your Server: AlgoPIN code
  Your Server->>Guest: AlgoPIN code
  Guest->>Lock: Enter AlgoPIN code
  Lock->>Lock: Unlock
```

## Types of AlgoPIN Codes

| Type | Validity | Variances | API |
| --- | --- | --- | --- |
| One-Time (OTP) | Single use | 10 | [Create a One-Time AlgoPIN](/home/api_access#create-a-one-time-algopin) |
| Permanent | No end date | 10 | [Create a Permanent AlgoPIN](/home/api_access#create-a-permanent-algopin) |
| Duration (Hourly) | 1 to 672 hours | 3 | [Create an Hourly AlgoPIN](/home/api_access#create-an-hourly-algopin) |
| Duration (Daily) | 29 to 367 days | 3 | [Create a Daily AlgoPIN](/home/api_access#create-a-daily-algopin) |
| Passage | 1 to 12 hours | 1 | [Create a Passage AlgoPIN](/home/api_access#create-a-passage-algopin) |

A Passage AlgoPIN unlocks the lock and keeps it unlocked for the chosen number of hours. Passage requires newer lock firmware.

## Activation

AlgoPIN codes valid for more than 24 hours need activation on the lock. The first time the code is used on the lock, it is activated. That first use must happen within the 24-hour activation window, which starts when the code's validity starts.

The example below uses a code valid from 00:00, 1 Oct to 00:00, 5 Oct. The activation window is the first 24 hours of validity, from 00:00, 1 Oct to 00:00, 2 Oct. The timelines are not drawn to scale.

<svg viewBox="0 0 640 170" width="100%" role="img" aria-labelledby="algopin-act-1-title algopin-act-1-desc" xmlns="http://www.w3.org/2000/svg" style="display: block; max-width: 640px; margin: 12px 0 28px; font-family: Manrope, sans-serif;">
  <title id="algopin-act-1-title">Code validity</title>
  <desc id="algopin-act-1-desc">The code is valid from 00:00 on 1 Oct to 00:00 on 5 Oct. The first 24 hours form the activation window.</desc>
  <rect width="640" height="170" rx="12" fill="#F8F8F8"/>
  <text x="32" y="32" font-size="16" font-weight="700" fill="#1C1C1C">Code validity</text>
  <rect x="60" y="84" width="520" height="36" rx="6" fill="#1C1C1C"/>
  <text x="405" y="107" font-size="15" fill="#FFFFFF" text-anchor="middle">AlgoPIN code validity</text>
  <rect x="60" y="84" width="170" height="36" rx="6" fill="#D95A4C"/>
  <text x="145" y="107" font-size="14" font-weight="700" fill="#FFFFFF" text-anchor="middle">24-hour window</text>
  <text x="60" y="150" font-size="14" fill="#676767">00:00, 1 Oct</text>
  <text x="230" y="150" font-size="14" fill="#676767">00:00, 2 Oct</text>
  <text x="400" y="150" font-size="14" fill="#676767">00:00, 3 Oct</text>
  <text x="580" y="150" font-size="14" fill="#676767" text-anchor="end">00:00, 5 Oct</text>
</svg>

**First use within the activation window.** The code is activated, unlocks the lock, and stays valid until 00:00, 5 Oct.

<svg viewBox="0 0 640 204" width="100%" role="img" aria-labelledby="algopin-act-2-title algopin-act-2-desc" xmlns="http://www.w3.org/2000/svg" style="display: block; max-width: 640px; margin: 12px 0 28px; font-family: Manrope, sans-serif;">
  <title id="algopin-act-2-title">First use within the window</title>
  <desc id="algopin-act-2-desc">The code is used for the first time inside the 24-hour window. The lock unlocks and the code is activated.</desc>
  <rect width="640" height="204" rx="12" fill="#F8F8F8"/>
  <text x="32" y="32" font-size="16" font-weight="700" fill="#1C1C1C">First use within the window</text>
  <rect x="60" y="84" width="520" height="36" rx="6" fill="#1C1C1C"/>
  <text x="405" y="107" font-size="15" fill="#FFFFFF" text-anchor="middle">AlgoPIN code validity</text>
  <rect x="60" y="84" width="170" height="36" rx="6" fill="#D95A4C"/>
  <text x="145" y="107" font-size="14" font-weight="700" fill="#FFFFFF" text-anchor="middle">24-hour window</text>
  <circle r="7" cx="145" cy="134" fill="#D95A4C" stroke="#FFFFFF" stroke-width="2">
    <animate attributeName="r" values="7;9;7" dur="1.6s" repeatCount="indefinite"/>
  </circle>
  <text x="159" y="139" font-size="13" font-weight="700" fill="#D95A4C">Used here</text>
  <g opacity="0">
    <animate attributeName="opacity" from="0" to="1" dur="0.4s" begin="0.8s" fill="freeze"/>
    <rect x="300" y="146" width="300" height="34" rx="6" fill="#FFFFFF" stroke="#E2E2E2"/>
    <path d="M314 163 l5 5 l10 -10" fill="none" stroke="#1C1C1C" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"/>
    <text x="336" y="168" font-size="15" font-weight="700" fill="#1C1C1C">Unlocks. Activated until 5 Oct.</text>
  </g>
  <text x="60" y="196" font-size="14" fill="#676767">00:00, 1 Oct</text>
  <text x="580" y="196" font-size="14" fill="#676767" text-anchor="end">00:00, 5 Oct</text>
</svg>

**First use after the activation window.** The code was not activated in the window. The lock does not unlock, even though the code is still within its validity period.

<svg viewBox="0 0 640 204" width="100%" role="img" aria-labelledby="algopin-act-3-title algopin-act-3-desc" xmlns="http://www.w3.org/2000/svg" style="display: block; max-width: 640px; margin: 12px 0 28px; font-family: Manrope, sans-serif;">
  <title id="algopin-act-3-title">First use after the window</title>
  <desc id="algopin-act-3-desc">The code is used for the first time after the 24-hour window. The lock does not unlock because the code was not activated.</desc>
  <rect width="640" height="204" rx="12" fill="#F8F8F8"/>
  <text x="32" y="32" font-size="16" font-weight="700" fill="#1C1C1C">First use after the window</text>
  <rect x="60" y="84" width="520" height="36" rx="6" fill="#1C1C1C"/>
  <text x="405" y="107" font-size="15" fill="#FFFFFF" text-anchor="middle">AlgoPIN code validity</text>
  <rect x="60" y="84" width="170" height="36" rx="6" fill="#D95A4C"/>
  <text x="145" y="107" font-size="14" font-weight="700" fill="#FFFFFF" text-anchor="middle">24-hour window</text>
  <circle r="7" cx="340" cy="134" fill="#D95A4C" stroke="#FFFFFF" stroke-width="2">
    <animate attributeName="r" values="7;9;7" dur="1.6s" repeatCount="indefinite"/>
  </circle>
  <text x="354" y="139" font-size="13" font-weight="700" fill="#D95A4C">Used here</text>
  <g opacity="0">
    <animate attributeName="opacity" from="0" to="1" dur="0.4s" begin="0.8s" fill="freeze"/>
    <rect x="300" y="146" width="300" height="34" rx="6" fill="#FFFFFF" stroke="#E2E2E2"/>
    <path d="M314 158 l10 10 M324 158 l-10 10" fill="none" stroke="#D95A4C" stroke-width="1.75" stroke-linecap="round"/>
    <text x="336" y="168" font-size="15" font-weight="700" fill="#1C1C1C">Does not unlock. Not activated.</text>
  </g>
  <text x="60" y="196" font-size="14" fill="#676767">00:00, 1 Oct</text>
  <text x="580" y="196" font-size="14" fill="#676767" text-anchor="end">00:00, 5 Oct</text>
</svg>

## AlgoPIN Limitations

| Limitation | Explanation |
| --- | --- |
| AlgoPIN-supported devices only | The device has to support AlgoPIN. See [Supported Devices](/home/supported-devices). |
| Paired devices | Pair the device with the igloohome app first. |
| 24-hour activation | AlgoPIN codes valid for more than 24 hours need activation on the lock. The first use must be within the first 24 hours of validity. See [Activation](#activation). |
| 256 rule | You can't delete an AlgoPIN whose start date is more than 256 hours after its creation. |
| 199 rule | The lock's whitelist and blacklist hold at most 199 PIN codes in total (AlgoPIN and Bluetooth PIN codes). |
| PINs per duration | For one duration, you can generate only as many PINs as the type's [variances](#variance-multiple-algopin-codes-for-the-same-duration). |

## Variance: Multiple AlgoPIN Codes for the Same Duration

For a given duration, each variance returns a different PIN code. The Types table above lists the number of variances per type.

One-Time and Permanent support 10 variances on locks with newer firmware. Some older locks gain this with a firmware update; others support 5.

Example of hourly PIN codes for one lock, three variances each:

| Start time | End time | PIN codes (variance 1, 2, 3) | deviceId |
| --- | --- | --- | --- |
| 2PM | 3PM | 511093918, 945844647, 052368115 | IGB403fe3b9d |
| 2PM | 4PM | 633654730, 437755350, 337288611 | IGB403fe3b9d |
| 3PM | 5PM | 297248165, 196981787, 384522901 | IGB403fe3b9d |
| 3PM | 5PM | 948950871, 142404925, 817840781 | IGP114cde456 |

The following request returns a unique PIN code (e.g. `4642226`):

```bash
curl --request POST \
  --url https://api.igloohome.co/home/devices/IGP101abc123/algopin/onetime \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer abcdef' \
  --data '{
  "variance": 1,
  "startDate": "2022-01-01T00:00:00+08:00",
  "accessName": "Maintenance guy"
}'
```

Changing the variance returns a second unique PIN code (e.g. `1419472`) for the same duration:

```bash
curl --request POST \
  --url https://api.igloohome.co/home/devices/IGP101abc123/algopin/onetime \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer abcdef' \
  --data '{
  "variance": 2,
  "startDate": "2022-01-01T00:00:00+08:00",
  "accessName": "Maintenance guy 2"
}'
```
