Last active
September 8, 2025 07:59
-
-
Save creaktive/d27d53c26e9508f404973ffe7a96388b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
# --- Config --- | |
DYSON_DEVICE=NN2-EU-XXXXXXXX | |
DYSON_TOKEN=XXXXXXXXXXXXXXXX | |
INFLUX_HOST=http://127.0.0.1:8086 | |
INFLUX_ORG=home | |
INFLUX_BUCKET=climate | |
INFLUX_TOKEN=XXXXXXXXXXXXXXX | |
UA='DysonLink/198668 CFNetwork/3860.100.1 Darwin/25.0.0' | |
ACCEPT_LANG='en-US,en;q=0.9' | |
# --- Helpers --- | |
post_influx() { | |
local precision="${1:-ns}" | |
gzip -c | curl -qsS -X POST \ | |
-H "Authorization: Token ${INFLUX_TOKEN}" \ | |
-H 'Content-Encoding: gzip' \ | |
-H 'Content-Type: text/plain; charset=utf-8' \ | |
-H 'Accept: application/json' \ | |
--data-binary @- \ | |
"${INFLUX_HOST}/api/v2/write?org=${INFLUX_ORG}&bucket=${INFLUX_BUCKET}&precision=${precision}" | |
} | |
hdrs=( | |
-H 'accept: application/json' | |
-H 'content-type: application/json' | |
-H "authorization: Bearer ${DYSON_TOKEN}" | |
-H 'cache-control: no-cache' | |
-H "user-agent: ${UA}" | |
-H 'priority: u=3, i' | |
-H "accept-language: ${ACCEPT_LANG}" | |
) | |
# --- 1) Daily history → line protocol (indoors) --- | |
curl -qsS --fail \ | |
"${hdrs[@]}" \ | |
"https://appapi.cp.dyson.com/v1/messageprocessor/devices/${DYSON_DEVICE}/environmentdailyhistory" \ | |
| jq --arg sensor_id "$DYSON_DEVICE" -r ' | |
def round(p): . * pow(10; p) | round / pow(10; p); | |
def ts_ns($date; $h): | |
($date + "T" + ("0\($h)"[-2:]) + ":00:00Z" | (fromdateiso8601 - 3600) * 1e9 | floor); | |
.[] as $day | |
| ($day.Temperature | to_entries[] | select(.value != null)) as $h | |
| ($day.Aqi[$h.key]) as $aqi | |
| ($day.Humidity[$h.key]) as $hum | |
| ($day.Usage[$h.key]) as $use | |
| select($aqi != null and $hum != null and $use != null) | |
| { | |
ts: ts_ns($day.Date; $h.key), | |
aqi: $aqi, | |
hum: $hum, | |
temp: (($day.Temperature[$h.key] / 10 - 273) | round(2)), | |
use: $use | |
} | |
| "indoors,sensor_id=\($sensor_id) aqi=\(.aqi),humidity=\(.hum),temperature=\(.temp),usage=\(.use) \(.ts)" | |
' \ | |
| post_influx ns >/dev/null | |
# --- 2) Current outdoor data → line protocol (single line) --- | |
curl -qsS --fail \ | |
"${hdrs[@]}" \ | |
"https://appapi.cp.dyson.com/v1/environment/devices/${DYSON_DEVICE}/data?language=en-US" \ | |
| jq --arg sensor_id "$DYSON_DEVICE" -r ' | |
"outdoors,sensor_id=\($sensor_id) " + | |
"aqi=\(.AqiValue),pm25=\(.Pm25Value),pm10=\(.Pm10Value),no2=\(.No2Value)," + | |
"humidity=\(.Humidity),temperature=\(.Temperature) " + | |
" \((.DateTime | fromdateiso8601 * 1e9 | floor))" | |
' \ | |
| post_influx ns >/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment