# dyried `dyried` is a lightweight daemon written in Go that passively streams Dyson Pure Cool fan telemetry via local MQTT and publishes structured events to [Riemann](https://riemann.io). Designed to run continuously on low-power devices like a Raspberry Pi. --- ## Features * **Passive Streaming with Watchdog Poll**: Listens for continuous sensor pushes from the Dyson fan; if no message is received within the watchdog timeout window (default 60s), it sends a poll command (`REQUEST-PRODUCT-ENVIRONMENT-CURRENT-SENSOR-DATA` and `REQUEST-CURRENT-STATE`). * **Metric Units**: Temperature converted from tenths of Kelvin to Celsius. Relative humidity, PM2.5, PM10, VOC, NO2, and filter life percentages. * **Riemann Tagging & Service Hierarchy**: Emits events using the fan's serial number as the Riemann `host`, organized with clean service names and categorization tags: * `dyson/temperature` (tags: `dyson`, `purecool`, `env`) * `dyson/humidity` (tags: `dyson`, `purecool`, `env`) * `dyson/pm25` (tags: `dyson`, `purecool`, `env`) * `dyson/pm10` (tags: `dyson`, `purecool`, `env`) * `dyson/voc` (tags: `dyson`, `purecool`, `env`) * `dyson/no2` (tags: `dyson`, `purecool`, `env`) * `dyson/hepa` (tags: `dyson`, `purecool`, `filter`) * `dyson/carbon` (tags: `dyson`, `purecool`, `filter`) * `dyson/fan-speed` (tags: `dyson`, `purecool`, `fan`) * `dyson/fan-power` (tags: `dyson`, `purecool`, `fan`) * `dyson/fan-auto` (tags: `dyson`, `purecool`, `fan`) * `dyson/fan-oscillation` (tags: `dyson`, `purecool`, `fan`) * `dyson/continuous-monitoring` (tags: `dyson`, `purecool`, `fan`) * **12-Factor App Configuration**: Configure via environment variables or command-line flags. * **TCP and UDP Riemann Transports**: Defaults to TCP with automatic reconnection and failover handling, and supports UDP. * **Closed-Loop Control via Riemann SSE**: Subscribes to Riemann's Server-Sent Events (SSE) feed to receive automation control commands (`fan-power`, `fan-speed`, `fan-auto`, `fan-oscillation`, `night-mode`) and dispatches MQTT `STATE-SET` messages to the fan with zero external dependencies. --- ## Configuration | Command-line Flag | Environment Variable | Default Value | Description | |:---------------------|:---------------------------|:-----------------------|:------------------------------------------| | `-mqtt-broker` | `DYRIED_MQTT_BROKER` | `tcp://127.0.0.1:1883` | Dyson MQTT broker address | | `-mqtt-username` | `DYRIED_MQTT_USERNAME` | *(required)* | Fan serial number (used as MQTT username) | | `-mqtt-password` | `DYRIED_MQTT_PASSWORD` | *(required)* | Dyson local MQTT credential hash | | `-mqtt-topic-root` | `DYRIED_MQTT_TOPIC_ROOT` | `438` | Dyson product type code | | `-mqtt-client-id` | `DYRIED_MQTT_CLIENT_ID` | `dyried` | MQTT Client ID | | `-riemann-endpoint` | `DYRIED_RIEMANN_ENDPOINT` | `127.0.0.1:5555` | Riemann server address (`host:port`) | | `-riemann-transport` | `DYRIED_RIEMANN_TRANSPORT` | `tcp` | Transport protocol (`tcp` or `udp`) | | `-riemann-ttl` | `DYRIED_RIEMANN_TTL` | `60s` | Riemann event TTL | | `-riemann-sse-url` | `DYRIED_RIEMANN_SSE_URL` | `""` *(disabled)* | Riemann SSE URL (e.g. `http://127.0.0.1:5556/index`) | | `-riemann-sse-query` | `DYRIED_RIEMANN_SSE_QUERY` | `service =~ "^dyson/control/" or tagged "control"` | Riemann SSE query filter | | `-host` | `DYRIED_HOST` | *(MQTT username)* | Hostname reported in Riemann events | | `-poll-timeout` | `DYRIED_POLL_TIMEOUT` | `60s` | Fallback watchdog timeout to poll fan | | `-service-prefix` | `DYRIED_SERVICE_PREFIX` | `dyson/` | Metric service name prefix | | `-model-tag` | `DYRIED_MODEL_TAG` | `purecool` | Base model tag | | `-verbose` | `DYRIED_VERBOSE` | `false` | Enable verbose debug logging | --- ## Building & Testing ### Build ```bash make build # Binary created in bin/dyried ``` ### Run Tests ```bash make test ``` ### Run Locally (Testing with Forwarded Port) ```bash ./bin/dyried \ -verbose \ -mqtt-broker "tcp://127.0.0.1:1883" \ -mqtt-username "NN2-US-AAA0000A" \ -mqtt-password "YOUR_BASE64_PASSWORD_HASH" \ -riemann-endpoint "127.0.0.1:5555" ``` --- ## Deployment on Raspberry Pi 1. Build for Raspberry Pi (if cross-compiling from another machine): ```bash GOOS=linux GOARCH=arm64 go build -o bin/dyried ./cmd/dyried # or GOARCH=arm for 32-bit Raspbian ``` 2. Copy the binary to `/usr/local/bin/dyried`: ```bash sudo cp bin/dyried /usr/local/bin/dyried sudo chmod 755 /usr/local/bin/dyried ``` 3. Install configuration file: ```bash sudo cp packaging/dyried.env /etc/default/dyried # Edit /etc/default/dyried with your fan IP (e.g. tcp://192.168.1.100:1883) ``` 4. Install systemd service: ```bash sudo cp packaging/dyried.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable --now dyried ``` 5. Check logs: ```bash journalctl -u dyried -f ``` --- ## Controlling the Fan from Riemann When `-riemann-sse-url` is configured, `dyried` subscribes to Riemann's SSE stream and listens for events targeting control services. ### Supported Control Services | Service | State / Metric | Action | | :--- | :--- | :--- | | `dyson/control/fan-power` | `state: "on"` / `metric: 1` | Turns fan power ON | | `dyson/control/fan-power` | `state: "off"` / `metric: 0` | Turns fan power OFF | | `dyson/control/fan-speed` | `metric: 1..10` | Sets fan speed level (and turns ON) | | `dyson/control/fan-speed` | `metric: 0` | Turns fan OFF | | `dyson/control/fan-auto` | `state: "on"` / `metric: 1` | Enables Auto mode | | `dyson/control/fan-auto` | `state: "off"` / `metric: 0` | Disables Auto mode | | `dyson/control/fan-oscillation` | `state: "on"` / `metric: 1` | Enables oscillation | | `dyson/control/fan-oscillation` | `state: "off"` / `metric: 0` | Disables oscillation | | `dyson/control/fan-night-mode` | `state: "on"` / `metric: 1` | Enables Night mode | ### Example Riemann Configuration In your `riemann.config`: ```clojure ;; Enable SSE server (if not already enabled) (sse-server {:host "127.0.0.1" :port 5556}) (streams ;; When PM10 exceeds 15 ug/m3, turn on the fan and set speed to 5 (where (and (service "dyson/pm10") (> metric 15)) (reinject {:host (:host event) :service "dyson/control/fan-speed" :metric 5 :state "on" :tags ["control"]})) ;; When air quality returns to normal (PM10 <= 5), switch fan back to auto (where (and (service "dyson/pm10") (<= metric 5)) (reinject {:host (:host event) :service "dyson/control/fan-auto" :metric 1 :state "on" :tags ["control"]}))) ```