> For the complete documentation index, see [llms.txt](https://docs.dephy.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.dephy.io/dephy-stream/for-data-providers.md).

# For Data Providers

This section covers **simulation** and **real Home Assistant bridging**.

***

#### 🧪 **A. Simulate Device Data (Recommended First Step)**

Before using real Home Assistant, test your setup with the built-in simulator.

**👌 1. Clone and Prepare**

```bash
git clone git@github.com:dephy-io/hass2nostr.git
```

**👌 2. Install** [**Deno**](https://deno.land/manual/getting_started/installation)

**👌 3. Configure Environment**

```bash
cp .env.example .env
```

Then edit `.env` and fill in your **Nostr secret key**:

```
DEPHY_SECRET_KEY=<your_nostr_secret_key>
```

> 💡 **Note:** When running the **simulator**, only `DEPHY_SECRET_KEY` is required. You don’t need `DEPHY_HA_TOKEN` — that token is only necessary later when running the **bridge** with a real Home Assistant connection.

**👌 4. Run the Simulator**

```bash
deno task run simulate \
  -w chunmi_tsa1 \
  -r wss://canary-relay.dephy.dev \
  -o playground \
  -m cdb9247ec7ab3302fd12450ae7453ab9f833639f109833f06c5d909991d62a3c
```

**Flag Reference**

| Flag | Description                  |
| ---- | ---------------------------- |
| `-r` | Relay WebSocket endpoint     |
| `-w` | Device type(s) to simulate   |
| `-o` | Target Topic name            |
| `-i` | Interval (ms) between events |
| `-m` | Controller pubkey to mention |

***

#### 🏠 **B. Bridge to Real Home Assistant**

This section explains connecting a real HASS instance and running the bridge.

***

**👌 1. Run Home Assistant via Docker**

```bash
sudo docker pull homeassistant/home-assistant
docker run -d \
  --name homeassistant \
  --privileged \
  --restart=unless-stopped \
  -v /data/homeassistant:/config \
  --network=host \
  homeassistant/home-assistant
```

***

**👌 2. Install HACS & Xiaomi Integrations**

```bash
sudo docker exec -it homeassistant bash
wget -O - https://get.hacs.xyz | bash -
exit
sudo docker restart homeassistant
```

Then in the web UI (`http://192.168.x.x:8123`):

1. **Settings → Devices & Services → Integrations**
2. Click **Add Integration** → Search for **HACS**
3. Authorize GitHub, restart if prompted
4. In HACS: **Explore & Download Repositories → Search “Xiaomi Home” (or “Xiaomi Miot”)** → **Download**
5. Restart Home Assistant
6. **Settings → Devices & Services → Add Integration → Xiaomi Home**
7. If redirect URL fails (`homeassistant.local`), replace with your IP (e.g. `http://192.168.x.x:8123/...`)

***

**👌 3. Generate a Long-Lived Access Token**

1. Click your **user profile** (bottom-left).
2. Scroll to **Long-Lived Access Tokens**.
3. Click **Create Token**, name it, and **copy** immediately.
4. Store it securely — it’s shown only once.

Add it to `.env` as:

```
DEPHY_HA_TOKEN=<your_token>
```

***

**👌 4. Configure the Bridge Environment**

1. **Clone the repo** (if not already):

   ```bash
   git clone git@github.com:dephy-io/hass2nostr.git
   ```
2. **Install Deno** (see [deno.land](https://deno.land)).
3. **Add `.env`:**

   ```
   DEPHY_SECRET_KEY=<your_nostr_secret_key>
   DEPHY_HA_TOKEN=<your_home_assistant_long_lived_token>
   ```
4. Verify the needed device type exists in `src/device-types/`.
   * If not, create or adapt one per developer section above.

***

**👌 5. Run the Bridge**

Default controller pubkey:

```
cdb9247ec7ab3302fd12450ae7453ab9f833639f109833f06c5d909991d62a3c
```

Run:

```bash
deno task run bridge \
  -r wss://canary-relay.dephy.dev \
  -w qingping_air_monitor \
  -o qingping_air_monitor \
  -i 300000 \
  -m cdb9247ec7ab3302fd12450ae7453ab9f833639f109833f06c5d909991d62a3c
```

**Flag Reference**

| Flag | Description                                 |
| ---- | ------------------------------------------- |
| `-r` | Relay WebSocket endpoint                    |
| `-w` | Device type module (in `src/device-types/`) |
| `-o` | Target Topic name                           |
| `-i` | Publish interval (ms)                       |
| `-m` | Controller pubkey to mention/notify         |

**Runtime Notes**

* The bridge polls `/api/states` from HASS, filters by your module’s `entityPrefixes` and `allowedEntitySuffixes`, truncates attributes, and publishes to the relay as Nostr events.
* If a value is non-numeric, that entity will be skipped automatically.

***

**👌 6. Monitor Your Stream**

1. Open your Topic in the frontend.
2. Ensure Access Mode and grants/subscriptions are valid.
3. Wait for one auth epoch (\~5 min).
4. Events will appear if you are authorized and the bridge is publishing successfully.

***
