Skip to main content

pyElectra

PyPI PyPI - Downloads Python

Python library to control Electra Smart air conditioners.

It is the client library behind the electrasmart Home Assistant integration.

Install

pip install pyElectra

Requires Python 3.11 or newer.

Usage

import asyncio

import aiohttp

from electrasmart.api import ElectraAPI, ElectraApiError
from electrasmart.api.utils import generate_imei
from electrasmart.device.const import OperationMode


async def main() -> None:
    session = aiohttp.ClientSession(
        connector=aiohttp.TCPConnector(ssl=False),
        timeout=aiohttp.ClientTimeout(total=10),
    )

    # 1. Register your phone number. The IMEI identifies this "device" to
    #    Electra, so generate it once and store it.
    api = ElectraAPI(session)
    imei = generate_imei()
    await api.generate_new_token(phone_number="0521234567", imei=imei)

    # 2. Confirm the OTP that was sent by SMS.
    resp = await api.validate_one_time_password(
        otp="123456", imei=imei, phone_number="0521234567"
    )
    token = resp["data"]["token"]

    # 3. Connect with the token and enumerate devices. The token is long-lived,
    #    so steps 1-2 only need to happen once.
    api = ElectraAPI(session, imei=imei, token=token)
    await api.fetch_devices()

    for ac in api.devices:
        print(ac.name, ac.get_temperature(), ac.get_sensor_temperature())

        ac.turn_on()
        ac.set_mode(OperationMode.MODE_COOL)
        ac.set_temperature(22)
        ac.set_fan_speed(OperationMode.FAN_SPEED_HIGH)
        await api.set_state(ac)  # push the new state to the A/C


asyncio.run(main())

Network failures and API-level errors raise ElectraApiError. An account the vendor has locked out raises ElectraIntruderLockoutError, a subclass of it, which nothing but signing in again will clear.

Changelog

See CHANGELOG.md. Notable in 1.2.5:

  • The KeyError: 'deviceToken' setup crash on device records that omit that field.
  • Current temperature reported as the raw ×256 left-shifted telemetry value (5,632 °C instead of 22 °C).

Development

pip install -e . pytest ruff mypy

pytest                       # tests
ruff format --check .        # formatting
ruff check .                 # lint
mypy --config-file mypy.ini src/electrasmart

CI runs lint, type checks and the test suite on Python 3.11, 3.12 and 3.13.

License

Apache-2.0

Metadata

Release files for pyElectra 1.2.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyElectra 1.2.12
File Size Uploaded Provenance Actions
pyelectra-1.2.12.tar.gz 27.2 kB With provenance Details for pyelectra-1.2.12.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyElectra 1.2.12
File Interpreter ABI Platform Actions
pyelectra-1.2.12-py3-none-any.whl Python 3 none any Details for pyelectra-1.2.12-py3-none-any.whl

Total release size: 45.3 kB

Release files / pyelectra-1.2.12.tar.gz

Download URL pyelectra-1.2.12.tar.gz
Size 27.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f9f3e1ea5a85094af7b4f8a83b7740febbe3e8a308c5617c31b2f982daa40c6d
BLAKE2b-256 checksum
How to use checksums
76b381390b6ee4c0384b31a3b8b33bf591e3dec76d80fe204ed8b251465a7fde
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / pyelectra-1.2.12-py3-none-any.whl

Download URL pyelectra-1.2.12-py3-none-any.whl
Size 18.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
630cb19a034af6318a850d7dac477d00cad4d7dc0d1e9652b4fe08097e34e4b7
BLAKE2b-256 checksum
How to use checksums
2328195aaab4ce2abbf9579f3b575244f26e6520a60c4a9400c798c338e4efd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Security for pyElectra 1.2.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pyelectra-1.2.12.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.2.12 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page