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.

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.5

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.5
File Size Uploaded
pyelectra-1.2.5.tar.gz 13.0 kB Details

Built distribution (wheel)

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

Total release size: 25.2 kB

Release files / pyelectra-1.2.5.tar.gz

Download URL pyelectra-1.2.5.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b1bb8069aea7fad0b1c99137332fe60d4238e8005fb8c1d82d144e57963a6579
BLAKE2b-256 checksum
How to use checksums
4871bce3bc5f769213ce8eb5db8797c9be81bc78956e68564c31b475c817c07e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

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

Download URL pyelectra-1.2.5-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
821d31b14ac3082536e740400c6f989e18c5f2e999ddf16b4cadb48e76810330
BLAKE2b-256 checksum
How to use checksums
a077434876a44b36dc2cedb293cadf91d59bfb6f9c685f2ebde0ff9194309851
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

1.2.6

2 release files

This release

1.2.5 This release

2 release files

1.2.4

1 release file

1.2.3

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.2.0

2 release files

1.1.0

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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