Skip to main content

Archive Tuya and Smart Life telemetry locally in SQLite, JSONL, or CSV.

Project description

Tuya Telemetry Archive

CI

Keep more than seven days of Tuya temperature and humidity history locally.

Tuya Telemetry Archive copies recent Tuya and Smart Life sensor logs into a local archive. Repeated collections are deduplicated. If Tuya changes a previously reported reading, the local record is updated.

The collector currently recognizes devices in category wsdcg with the temp_current and humidity_value data points. It requires Python 3.11 or newer.

Why this exists

Tuya's free Device Log service retains seven days of history. Run the collector regularly to copy readings before they expire from Tuya's service.

Install

Install from PyPI in a virtual environment:

python3 -m venv .venv
source .venv/bin/activate
python -m pip install tuya-telemetry-archive
tuya-archive --help

Set up and collect

Follow the Tuya Cloud setup guide to create a Smart Home cloud project, link a Tuya Smart or Smart Life account, authorize log access, and choose the correct regional endpoint.

Then run:

tuya-archive setup
tuya-archive doctor
tuya-archive collect
tuya-archive status

A successful collection looks like this:

success: 1/1 devices, 48 fetched, 48 inserted, 0 corrected.

Run tuya-archive collect at least once every seven days. Daily collection leaves enough overlap to tolerate a missed run.

Archive storage

SQLite is the default archive backend. JSONL and CSV are available when a text-readable archive is more useful.

Set the backend during setup or with TUYA_STORAGE_BACKEND in the protected environment file:

TUYA_STORAGE_BACKEND=sqlite

Choose sqlite, jsonl, or csv. SQLite remains the default.

Backend Use it for Trade-off
SQLite Normal long-running archives Requires SQLite-aware tools for direct inspection
JSONL Small archives that should remain text-readable Rewrites the file when changes are committed
CSV Portable archives for spreadsheets and data tools Uses several related files and rewrites changed yearly partitions

The CSV backend is a directory named archive-csv. Device and collection-run records have their own CSV files. Observations are partitioned by UTC calendar year as observations-YYYY.csv, so corrections only rewrite the affected yearly partition. The files work together as one archive and should be backed up or moved as a directory.

Hourly CSV reports

Run this after collecting data:

tuya-archive export

By default, the command writes one hourly CSV per UTC calendar year in the private data directory:

csv/hourly-2026.csv
csv/hourly-2027.csv

Choose another directory for the annual files:

tuya-archive export --output-dir ./annual-csv

Or write one combined file:

tuya-archive export --output ./tuya-hourly.csv

Each row includes the device label and pseudonym, data-point code, unit, sample count, and hourly minimum, mean, maximum, first, and last values. UTC and local timestamps are both included. The local timestamp includes its UTC offset so repeated daylight-saving hours remain distinct.

Optional macOS scheduler

Scheduling is optional. You can run tuya-archive collect from cron, another scheduler, or your own automation.

On macOS, the project can install a daily user LaunchAgent:

tuya-archive schedule install
tuya-archive schedule status

Remove it with:

tuya-archive schedule uninstall

The default interval is 86,400 seconds. To choose another interval:

tuya-archive schedule install --interval-seconds 43200

The LaunchAgent uses the Python interpreter that installed it. Reinstall the schedule after moving or rebuilding that virtual environment. See the macOS scheduling guide for details.

Local files and privacy

On macOS, files are stored under:

~/Library/Application Support/tuya-telemetry-archive/
├── config/config.env
└── data/
    ├── identity.key
    ├── archive.sqlite3  (or archive.jsonl or archive-csv/)
    └── csv/

Other platforms follow XDG conventions. Override the defaults with TUYA_ARCHIVE_CONFIG_DIR and TUYA_ARCHIVE_DATA_DIR.

Raw Tuya device IDs are not written to the archive. They are replaced with stable HMAC pseudonyms using the local identity.key. The archive still contains device labels, timestamps, and sensor readings, so it should be treated as private household data.

Back up identity.key with the archive. If the key is lost, future readings from the same device will receive a different pseudonym. See SECURITY.md for reporting and handling guidance.

Tested devices and current limitations

Collection has been tested with the SENCKIT 4-Pack WiFi Temperature Humidity Sensor (Amazon ASIN B0B5DQZTG9). These sensors report as category wsdcg with temp_current and humidity_value.

Tuya also publishes a general temperature and humidity sensor solution. That page describes the Tuya platform category, not this exact SENCKIT retail listing.

Other devices that expose the same data points may work, but they have not been verified against this project yet. Tuya Cloud setup, API authorization, endpoint behavior, and service availability can also change independently of this repository.

Hourly CSV reports are the only built-in reporting workflow. Arbitrary queries, charts, and an MCP server are not implemented yet. The built-in scheduler currently supports macOS only.

Development

Use synthetic fixtures only. Never add real credentials, device IDs, identity keys, household labels, telemetry, archives, or exports.

python3 -m venv .venv
.venv/bin/python -m pip install -e '.[dev]'
.venv/bin/python -m pytest -v
.venv/bin/ruff check .
.venv/bin/python -m build

See CONTRIBUTING.md for the safety requirements and development workflow.

Maintenance and contributions

This project will be actively maintained. Contributors are welcome to add more device integrations, reporting workflows, scheduling platforms, and other improvements.

See the Tuya Cloud setup guide, security policy, contribution guide, release guide, and MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tuya_telemetry_archive-0.1.0.tar.gz (63.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tuya_telemetry_archive-0.1.0-py3-none-any.whl (46.2 kB view details)

Uploaded Python 3

File details

Details for the file tuya_telemetry_archive-0.1.0.tar.gz.

File metadata

  • Download URL: tuya_telemetry_archive-0.1.0.tar.gz
  • Upload date:
  • Size: 63.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for tuya_telemetry_archive-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b3918b237521764c1065e9ad2bf446318dca823ba462d7eb4ee0ecf73838397c
MD5 d85ed352b7bce5ad8d2166f66957df14
BLAKE2b-256 56d85157485f9a20d2e1fdd73a7cab1b0eea9d01edadbcddb482654f04a2906e

See more details on using hashes here.

Provenance

The following attestation bundles were made for tuya_telemetry_archive-0.1.0.tar.gz:

Publisher: publish-to-pypi.yml on ankushagrawal94/tuya-telemetry-archive

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tuya_telemetry_archive-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tuya_telemetry_archive-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7a878d14281a83e230b7b31c7f4a0e8e3a8eee3fb50b69b9ce0aa224cf6108a0
MD5 58c954a937aa31ec3caafa959f8b1c66
BLAKE2b-256 c05b80d15befbd03e6d1fd832322b8c163c35742dc650c69058e1621b213ce98

See more details on using hashes here.

Provenance

The following attestation bundles were made for tuya_telemetry_archive-0.1.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on ankushagrawal94/tuya-telemetry-archive

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page