Skip to main content

aiotemescal

Asyncio client for LG soundbars and Wi-Fi speakers, speaking the "temescal" protocol used by the LG Wi-Fi Speaker app (TCP port 9741).

It is a rewrite of python-temescal, which was not designed for devices that are only intermittently present on the network, for example a soundbar powered through a smart plug. It is used by the LG Soundbars integration of Home Assistant.

Features:

  • the connection is kept open in the background and re-established with an exponential backoff;
  • a power cut is noticed within seconds through tuned TCP keepalive and TCP_USER_TIMEOUT, without any application traffic;
  • the backoff can be skipped when you know the device is back, and the address can be changed without restarting the client;
  • after each connection, the whole state is requested and delivered to subscribers before the connection is reported, so a device that comes back is never shown with the state it had before;
  • connection state changes are reported to subscribers;
  • requests can be awaited for their answer.

Usage

import asyncio
from aiotemescal import TemescalClient


async def main() -> None:
    client = TemescalClient("192.168.1.15")
    client.subscribe(print)
    client.subscribe_connection(lambda up: print("connected" if up else "gone"))
    await client.start()
    ...
    await client.stop()


asyncio.run(main())

One-shot use, for example to identify a device:

async with TemescalClient("192.168.1.15") as client:
    info = await client.request("SPK_LIST_VIEW_INFO")
    print(info["data"]["s_user_name"])

request() and send() raise TemescalConnectionError when the device is not connected, and request() raises TemescalTimeoutError when no answer arrives.

Every message received from the device is delivered to the subscribe() callbacks, including answers to requests and unsolicited status updates.

Reconnection

While the device is unreachable, the client retries with a backoff that grows from 1 to 5 s. If you learn by other means that the device is back, call reconnect_now() to retry right away; it does nothing while connected. set_host() changes the address of the device and retries right away.

Power loss detection

A device that loses power stops acknowledging TCP packets. The client configures the socket so that the kernel closes such a connection after about 7 s when idle (keepalive probes after 5 s of silence, every second, two missed), or 3 s after a command that is not acknowledged. These options exist on Linux; on other systems the defaults of the OS apply and detection can take much longer.

Debugging

python -m aiotemescal 192.168.1.15 -v

prints every message and connection change; use it while cutting power to the device to see how quickly the loss and the return are detected.

Tests

make test                                          # unit tests, against a fake soundbar
make test-live TEMESCAL_HOST=192.168.1.127         # read-only tests against a real device
make test-actions TEMESCAL_HOST=192.168.1.127      # changes and restores settings, input and power
make test-power-cycle TEMESCAL_HOST=192.168.1.127  # asks you to unplug and replug it

TEMESCAL_PORT overrides the default port 9741.

Tested devices

Model Firmware (main / micom / Chromecast)
LG SP8YA 2407090 / 2207202 / 1.56.310669

The versions are those reported in UPDATE_VIEW_INFO.

Credits

The heavy lifting was done by Matthew Garrett, who wrote python-temescal and made the protocol usable from Python. The encryption key and IV, the message names and the equaliser and function tables of this library all come from that work, along with the additions of its contributors Berni Moses, teldri and tomasrollo. aiotemescal only adds an asyncio client around them.

License

Apache 2.0. Derived from python-temescal, Copyright 2018 Google LLC, also licensed under Apache 2.0. The files taken from it say so in their header.

Metadata

Release files for aiotemescal 0.3.0

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

Source distribution (sdist)

Source distribution for aiotemescal 0.3.0
File Size Uploaded Provenance Actions
aiotemescal-0.3.0.tar.gz 35.5 kB With provenance Details for aiotemescal-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 50.8 kB

Release files / aiotemescal-0.3.0.tar.gz

Download URL aiotemescal-0.3.0.tar.gz
Size 35.5 kB
Tags Source
SHA-256 checksum
How to use checksums
da79c95536d676336c4a5a45b8953fe6baf06a884ebeb79bc3fa8afc4d2fc7d4
BLAKE2b-256 checksum
How to use checksums
9014777cea40ad13dca075e66920c1b405d85bf5ab90d4bd9ee175f98bfe90be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 2, 2026.

Transparency log

Release files / aiotemescal-0.3.0-py3-none-any.whl

Download URL aiotemescal-0.3.0-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3039f8371a8eef810652b8f4747abf4d9648f9e205d1f3c18aab0f89870363d5
BLAKE2b-256 checksum
How to use checksums
89e5169b1e298757c7de3d7ea3db024d54b8eae1a8ad4f5ef2931043f6331a2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 2, 2026.

Transparency log

Security for aiotemescal 0.3.0

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 aiotemescal-0.3.0.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 Nov 2, 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.

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