# Quick start

> Run Hour Advantage on your own machine. Use curl to pretend to be a ZKTeco clock, and see a device, a punch and a command, with no clock hardware.

In this guide you run Hour Advantage on your own machine. You see a real event in a few minutes. You need no clock hardware, because `curl` plays the part of a ZKTeco clock.

Hour Advantage fits several business models. You can run your own company's time and attendance. You can run a multi-tenant service for your customers. You can look after clocks as a dealer. Or you can build one engine into your own platform. [Business models](/docs/business-models/) shows how each one fits.

You need:

- The Hour Advantage programs and the official package bundles. Both come with the Hour Advantage distribution.
- Docker, for a throwaway Postgres database.
- `curl`. On Windows, use `curl.exe`. It comes with Windows 10 and later.

Ports `8080`, `9090` and `55432` on `127.0.0.1` must be free.

## 1. Get Hour Advantage

The Hour Advantage distribution gives you:

| | |
|---|---|
| The programs | Three programs for your platform. `hourd` is the server. `hourctl` is the command line client. It also builds and tests packages on your machine. `houradm` handles installation and maintenance. This guide uses `hourd` and `hourctl`. Put them on your `PATH`. |
| The official package bundles | One `.tar.gz` file for each package, ready to push. You use them in step 4. |
| The `houradvantage` container image | The same three programs, running as a non-root user, with the official package bundles inside. [Deploy](/docs/deploy/#containers) shows how to run it. |

The sources of the example packages are in the public repository `hour-advantage-examples`. [Packages](/docs/packages/) explains how to build bundles from them.

Check the programs:

```sh
hourd --version
```

## 2. Start Postgres

Start a throwaway Postgres 17 database named `houradvantage-quickstart`. It listens on port `55432` of loopback only:

```sh
docker run -d --name houradvantage-quickstart -e POSTGRES_USER=houradvantage -e POSTGRES_PASSWORD=houradvantage -e POSTGRES_DB=houradvantage -p 127.0.0.1:55432:5432 postgres:17-alpine -c tcp_keepalives_idle=10 -c tcp_keepalives_interval=5 -c tcp_keepalives_count=3 -c tcp_user_timeout=30s
```

The three `-c` settings are limits the gateway asks of its database. The gateway refuses to start without them. See [Operations, Database role settings](/docs/operations/#database-role-settings).

## 3. Run the gateway

In a terminal of its own:

```powershell
# PowerShell
$env:HOURADVANTAGE_DATABASE_URL = "postgres://houradvantage:houradvantage@127.0.0.1:55432/houradvantage"
hourd run
```

```sh
# bash
export HOURADVANTAGE_DATABASE_URL=postgres://houradvantage:houradvantage@127.0.0.1:55432/houradvantage
hourd run
```

The gateway waits for Postgres to accept connections. Then it creates its tables and opens the admin API on `127.0.0.1:9090`. An admin API on loopback needs no login. So `hourctl` on this machine reaches it with no settings. Leave the gateway running.

The log warns that `HOURADVANTAGE_SECRET_KEY` is not set. That is fine for this guide, because it keeps no secret. But the gateway refuses to store your first secret until the key is set. A secret can be a delivery key, a sink's `secret` for Time and Attendance, or a broker password. When you go on, make a key first with `houradm gen-secret-key`. Give it to `hourd run` as `HOURADVANTAGE_SECRET_KEY`. See [secrets at rest](/docs/operations/#secrets-at-rest).

In a second terminal, check it:

```sh
hourctl status
```

```text
gateway    running at http://127.0.0.1:9090, version 0.1.0, instance <host>
listeners  0 (0 running, 0 stopped, 0 failed)
endpoints  0 (0 stopped)
devices    0 (0 allowed, 0 pending, 0 blocked)
sinks      0 (0 events waiting, 0 failing)
```

## 4. Push the packages

A fresh database has no packages. Push the official bundles and activate them. Run this in the folder that holds the distribution's bundles, the `.tar.gz` files:

```powershell
# PowerShell
hourctl pkg push --activate (Get-ChildItem *.tar.gz).FullName
hourctl pkg list
```

```sh
# bash
hourctl pkg push --activate *.tar.gz
hourctl pkg list
```

You can use bundles built from the example packages instead. Build them in a checkout of `hour-advantage-examples`. Building runs each package's scenarios. Then push them:

```powershell
# PowerShell
hourctl pkg build . -o dist
hourctl pkg push --activate (Get-ChildItem dist\*.tar.gz).FullName
```

```sh
# bash
hourctl pkg build . -o dist
hourctl pkg push --activate dist/*.tar.gz
```

`hourctl pkg list` shows each package line and the revision that runs. One of them is `zk-push@3.4`. [Packages](/docs/packages/) covers bundles, revisions and lines.

## 5. Set up a listener and an endpoint

Save this as `quickstart.toml`:

```toml
[[listener]]
id = "devices"
type = "http"
listen = "127.0.0.1:8080"

[[endpoint]]
id = "office"
listener = "devices"
path = "/office"
package = "zk-push@3.4"
new_devices = "allow"
options = { timezone = "America/Chicago" }
```

The listener takes HTTP on `127.0.0.1:8080`. The endpoint `office` serves every request under `/office`. It uses the ZK PUSH 3.4 package and the `America/Chicago` time zone. It lets in any device that calls, because of `new_devices = "allow"`. Outside a trial, use `"hold"`. See [devices](/docs/devices/). Apply it:

```sh
hourctl apply quickstart.toml
```

```text
listener devices: created
endpoint office: created
warning: port 8080 is one no listener of this setup used before: a load balancer or a published port that clocks reach it by needs it too (docker compose: a haproxy.cfg frontend and a ports: line; Kubernetes: the devices Service; `hourctl export lb` prints them). Another tenant's listener cannot share the port
applied on 1/1 instances (config version 13)
```

The warning is for deployments behind a load balancer or published ports. You have none here. The config version is your gateway's own count of changes, so your number differs.

In a third terminal, follow the events as the gateway stores them:

```sh
hourctl events --follow
```

## 6. Be a clock

Now a ZK clock with serial number `TEST0001` calls in. Each request below is what a real clock sends to a server set to `127.0.0.1`, port `8080`, path `/office`.

```powershell
# PowerShell
# First contact: the clock asks for its options.
curl.exe -s "http://127.0.0.1:8080/office/iclock/cdata?SN=TEST0001&options=all&pushver=3.4.0"
# Heartbeat: "anything for me?"
curl.exe -s "http://127.0.0.1:8080/office/iclock/getrequest?SN=TEST0001"
# A punch: user 1001 checks in by fingerprint.
curl.exe -s --data-binary "1001`t2026-10-01 08:00:00`t0`t1`t0`t0`t0`n" "http://127.0.0.1:8080/office/iclock/cdata?SN=TEST0001&table=ATTLOG&Stamp=2026-10-01T08:00:00"
```

```sh
# bash
# First contact: the clock asks for its options.
curl -s "http://127.0.0.1:8080/office/iclock/cdata?SN=TEST0001&options=all&pushver=3.4.0"
# Heartbeat: "anything for me?"
curl -s "http://127.0.0.1:8080/office/iclock/getrequest?SN=TEST0001"
# A punch: user 1001 checks in by fingerprint.
printf '1001\t2026-10-01 08:00:00\t0\t1\t0\t0\t0\n' | curl -s --data-binary @- "http://127.0.0.1:8080/office/iclock/cdata?SN=TEST0001&table=ATTLOG&Stamp=2026-10-01T08:00:00"
```

The first answer is the clock's settings: `GET OPTION FROM: TEST0001`, `TimeZone=-05:00`, the upload stamps, and more. The heartbeat and the punch are each answered `OK`. The gateway stored the punch before it told the clock so.

## 7. See what happened

The device registered itself. List devices:

```sh
hourctl devices
```

```text
ENDPOINT  DEVICE    STATUS   KEY   PRESENTED  LAST SEEN                 REMOTE IP  MESSAGES  ERRORS  LABELS
office    TEST0001  allowed  none  none       2026-10-04T18:00:26.747Z  127.0.0.1  3         0       -
```

The events terminal shows three events:

- A `device.new` event.
- A `device.joined` event. The clock was let in, so it joined its tenant and its endpoint's group.
- The punch.

Each line shows the event's sequence number, when it was stored, its type, the endpoint and device, and its data. `hourctl events` lists them again. They come after the `package.updated` events, ids 1 to 7, that pushing the bundles' policy packages made:

```text
8   2026-10-04T18:00:26.702959Z  device.new     office/TEST0001  {"device_id":1,"key_presented":"none","remote_ip":"127.0.0.1","status":"allowed"}
9   2026-10-04T18:00:26.703114Z  device.joined  office/TEST0001  {"device_id":1,"group":"office"}
10  2026-10-04T18:00:26.752848Z  punch          office/TEST0001  {"dst_ambiguous":false,"local_time":"2026-10-01 08:00:00","state_name":"check_in","time":"2026-10-01T08:00:00-05:00","time_zone":"America/Chicago","user_id":"1001", ... ,"verify_name":"fingerprint", ...}
```

The punch uses neutral terms: `user_id`, `time`, `state_name` and `verify_name`. What the clock said in its own terms is under `vendor.zk`. [Events](/docs/reference/events/) describes every field.

## 8. Send the clock an action

Ask the clock to report what it is. Use the standard action `get_info`:

```sh
hourctl action office TEST0001 get_info
```

```text
action #1 get_info for office/TEST0001: queued (commands #1136802001)
```

The command waits until the clock next calls in. Send another heartbeat, the same `getrequest` as in step 6. This time the answer is the command, with its id:

```text
C:1136802001:INFO
```

A real clock carries out the command and posts the result. Play that part too. Use the id from your own answer in place of `1136802001`:

```powershell
# PowerShell
curl.exe -s --data-binary "ID=1136802001&Return=0&CMD=INFO`n~DeviceName=Demo Clock`nFWVersion=Ver 1.0.0`nUserCount=1`n" "http://127.0.0.1:8080/office/iclock/devicecmd?SN=TEST0001"
```

```sh
# bash
printf 'ID=1136802001&Return=0&CMD=INFO\n~DeviceName=Demo Clock\nFWVersion=Ver 1.0.0\nUserCount=1\n' | curl -s --data-binary @- "http://127.0.0.1:8080/office/iclock/devicecmd?SN=TEST0001"
```

The answer is `OK`. The action is done. The events terminal shows a `command.result` event and an `action.result` event. The device's record holds what the clock reported:

```sh
hourctl actions office TEST0001
hourctl device show office TEST0001
```

```text
ID  ACTION    STATUS  STEPS  LANE         CREATED
1   get_info  done    1      interactive  2026-10-04T18:00:29.971Z
```

`device show` lists the reported values on its `info` line:

```text
info            firmware=Ver 1.0.0, model=Demo Clock, push_version=3.4.0, user_count=1
```

## Clean up

Stop the gateway with Ctrl-C in its terminal. Then remove the database:

```sh
docker rm -f houradvantage-quickstart
```

## Next steps

| | |
|---|---|
| [Deploy](/docs/deploy/) | Run Hour Advantage as a container, as a Docker Compose cluster, on Kubernetes, or as a service. |
| [Networking](/docs/networking/) | Listeners, endpoints, ports and the load balancer in front. |
| [Devices](/docs/devices/) | Letting devices in, keys, and `new_devices = "hold"`. |
| [Packages](/docs/packages/) | Building, pushing and activating packages; [ZKTeco PUSH](/docs/packages/zk/) for ZK clocks. |
| [Actions](/docs/actions/) | Every standard action, and how actions reach devices. |
| [Jobs](/docs/jobs/) | One action over many devices, in waves. |
| [Sync groups](/docs/sync/) | Keeping people, access and punches the same on clocks of any vendor. |
| [Admin API](/docs/reference/admin-api/) | The HTTP API `hourctl` uses. |
| [Command line](/docs/reference/cli/) | Every `hourd`, `hourctl` and `houradm` command. |
