Skip to main content

Python client for Netatmo API with truetemperature control - set room temperatures programmatically

Project description

py-netatmo-truetemp

CI Python 3.13+ License: MIT codecov Code style: ruff Type checked: mypy Security: bandit

A Python client for the Netatmo API with truetemperature control - set room temperatures programmatically via the undocumented API endpoint.

⚠️ Disclaimer

Unofficial Project: This is an independent, community-developed library and is not affiliated with, endorsed by, or supported by Netatmo or Legrand.

Why This Exists: The official Netatmo OAuth API does not currently support programmatic temperature adjustments via the truetemperature endpoint. This library fills that gap using reverse-engineered API endpoints.

Archival Policy: This repository will be archived or removed if:

  • Netatmo officially adds temperature control support to their OAuth API
  • Netatmo requests takedown of this project

Use at Your Own Risk: This library relies on undocumented endpoints that may change without notice. Functionality could break if Netatmo modifies their internal API.

Features

  • TrueTemperature API: Set room temperatures via Netatmo's undocumented endpoint
  • Room Management: List and lookup rooms by name (case-insensitive) or ID
  • Smart Updates: Skips API call if temperature already at target (0.1°C tolerance)
  • Automatic Authentication: Cookie-based session management with secure storage (0o600)
  • Auto-Retry: Automatically recovers from authentication failures and API errors
  • Type-Safe: Full type hints with TypedDict definitions for API responses (Python 3.13+)
  • Thread-Safe: Safe to use in multi-threaded applications
  • Simple API: Easy-to-use facade with sensible defaults
  • Extensible: Modular components for advanced customization
  • Production-Ready: Comprehensive error handling and logging

Installation

From Source

# Clone the repository
git clone https://github.com/P4uLT/py-netatmo-truetemp.git
cd py-netatmo-truetemp

# Create virtual environment and install
uv venv
uv sync

As a Dependency

# Install from GitHub (until PyPI release)
uv add "py-netatmo-truetemp @ git+https://github.com/P4uLT/py-netatmo-truetemp.git"

Environment Variables

Set these required environment variables:

export NETATMO_USERNAME="your_username"
export NETATMO_PASSWORD="your_password"

Optional:

export NETATMO_HOME_ID="your_home_id"  # Auto-detected if not set

Quick Start

import os
from py_netatmo_truetemp import NetatmoAPI

# Initialize the API (uses cookie-based authentication)
api = NetatmoAPI(
    username=os.environ['NETATMO_USERNAME'],
    password=os.environ['NETATMO_PASSWORD']
)

# Get homes data
homes = api.homesdata()

# Get home status
status = api.homestatus(home_id="your-home-id")

# List rooms with thermostats
rooms = api.list_thermostat_rooms()
# Returns: [{'id': '1234567890', 'name': 'Living Room'}, ...]

# Set room temperature (smart update with 0.1°C tolerance)
api.set_truetemperature(
    room_id="1234567890",
    corrected_temperature=20.5
)

Common Use Cases

Set Temperature by Room Name

from py_netatmo_truetemp import NetatmoAPI
import os

api = NetatmoAPI(
    username=os.environ['NETATMO_USERNAME'],
    password=os.environ['NETATMO_PASSWORD']
)

# Get all rooms
rooms = api.list_thermostat_rooms()
living_room = next(r for r in rooms if r['name'].lower() == 'living room')

# Set temperature
api.set_truetemperature(
    room_id=living_room['id'],
    corrected_temperature=20.5
)

Monitor All Room Temperatures

status = api.homestatus()
for room in status['body']['home']['rooms']:
    temp = room.get('therm_measured_temperature')
    if temp:
        print(f"Room {room['id']}: {temp}°C")

Custom Cookie Location

api = NetatmoAPI(
    username=os.environ['NETATMO_USERNAME'],
    password=os.environ['NETATMO_PASSWORD'],
    cookies_file="/secure/path/cookies.json"
)

How It Works

The library provides a simple NetatmoAPI facade that handles all the complexity:

  • Automatic Authentication: Cookie-based session management with secure storage (0o600 permissions)
  • Smart API Calls: Auto-retry on authentication failures, skips redundant temperature updates
  • Type-Safe Responses: Fully typed API responses for better IDE support and error prevention
  • Thread-Safe Operations: Safe to use in multi-threaded applications with session locking

For advanced usage, you can access individual components directly (see Advanced Usage below).

For complete architectural details and SOLID design principles, see CLAUDE.md.

Advanced Usage

For advanced use cases, you can use individual components:

from py_netatmo_truetemp import (
    CookieStore,
    AuthenticationManager,
    NetatmoApiClient,
    HomeService,
    ThermostatService
)

# Create custom cookie store
cookie_store = CookieStore("/custom/path/cookies.json")

# Inject custom session
import requests
session = requests.Session()
# Configure session as needed...

# Use components directly
auth_manager = AuthenticationManager(
    username="...",
    password="...",
    cookie_store=cookie_store,
    session=session
)

Security

  • Credentials should be provided via environment variables
  • Session cookies are cached with secure permissions (0o600)
  • All API communications use HTTPS
  • No unsafe pickle serialization

Project Structure

This project uses a library + examples structure:

src/py_netatmo_truetemp/     # Core library (installable package)
   ├── __init__.py            # Package exports
   ├── netatmo_api.py         # Main facade
   ├── cookie_store.py        # Cookie persistence
   ├── auth_manager.py        # Authentication (thread-safe)
   ├── api_client.py          # HTTP client (auto-retry)
   ├── home_service.py        # Home operations
   ├── thermostat_service.py  # Thermostat operations
   ├── types.py               # TypedDict definitions
   ├── validators.py          # Input validation
   ├── exceptions.py          # Custom exceptions
   ├── constants.py           # API endpoints
   └── logger.py              # Logging utilities

examples/                     # Example applications (independent)
   ├── cli.py                 # CLI entry point
   ├── helpers.py             # Helper functions (API init, error handling)
   ├── display.py             # Display formatting (Rich library)
   ├── pyproject.toml         # Examples dependencies (Typer, Rich)
   ├── .venv/                 # Isolated virtual environment
   └── README.md              # CLI setup and usage

Development

Library Development

# Syntax check library modules
python -m py_compile src/py_netatmo_truetemp/*.py

Testing with Examples

The examples/ folder contains independent applications for testing library changes. See examples/README.md for setup and usage instructions.

Release Automation

This project uses semantic-release for fully automated releases. All versioning, changelog generation, and publishing happens automatically in CI when you push to the main branch.

Quick workflow:

# 1. Make changes with conventional commits
git commit -m "feat: add new feature"
git commit -m "fix: resolve bug"

# 2. Push to main - automatic release happens
git push origin main

# GitHub Actions automatically:
# - Analyzes conventional commits
# - Determines version bump (major/minor/patch)
# - Updates version in pyproject.toml and __init__.py
# - Generates and updates CHANGELOG.md
# - Creates git tag with verified signature
# - Creates GitHub Release
# - Publishes to PyPI

All commits must follow Conventional Commits format:

  • feat: - New features (minor version bump: 0.1.0 → 0.2.0)
  • fix: - Bug fixes (patch version bump: 0.1.0 → 0.1.1)
  • feat!: or BREAKING CHANGE: - Breaking changes (major version bump: 0.1.0 → 1.0.0)

Pre-commit hooks enforce commit message validation. For complete release workflow documentation, see RELEASE_WORKFLOW_GUIDE.md.

Documentation

Contributing

Contributions are welcome! Please read our Contributing Guide for details on:

  • Code of conduct
  • Development setup
  • Running tests
  • Code style guidelines
  • Conventional commit message format (required)
  • Submitting pull requests

All commits must follow the Conventional Commits format. Pre-commit hooks will validate your commit messages automatically.

See also:

Support

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Uses modern Python 3.13+ features and comprehensive type hints
  • Built with clean architecture patterns for maintainability (see CLAUDE.md)
  • Inspired by the need for programmatic Netatmo thermostat control

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

py_netatmo_truetemp-0.1.0.tar.gz (104.6 kB view details)

Uploaded Source

Built Distribution

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

py_netatmo_truetemp-0.1.0-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for py_netatmo_truetemp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 270419e046cf0e275f488c6f332c4974716fce2a62b5cd04a8301fbcf4a2efde
MD5 a72df0be84f713758790fb3516d7dfa1
BLAKE2b-256 d17e48f4349a236c1983bd92cbb7b6fbae52e58b89239d0cbbcea407720e4fff

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on P4uLT/py-netatmo-truetemp

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

File details

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

File metadata

File hashes

Hashes for py_netatmo_truetemp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 08e8f11d067ee0176d3538f6adaaaeaed43ab4b9a5754bd168a69a65a11eb39c
MD5 d10bb39277c1f3577728b3657b4bfd93
BLAKE2b-256 efc6ac4731872025da6f7950cd1f798c5e671d7ea3b4a8046f61c8eb14d339e8

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on P4uLT/py-netatmo-truetemp

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