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. python-temescal has been archived, read-only, since 2023, so this project takes over its maintenance. Beyond the rewrite, it aims at handling each model as it really behaves: what it reports, what it ignores, and when it leaves the network. It is used by the LG Soundbars integration of Home Assistant.
The messages it sends and the way it reads the answers are those of python-temescal, which has been used with many LG models through that integration, so models that worked with it should keep working.
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 (on Linux, see Power loss detection); - 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.
Contents
- Usage
- Reconnection
- Power loss detection
- Power state
- Debugging
- Tests
- Tested devices
- Contributing
- Future work
- Credits
- License
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 or does not acknowledge them, 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.
A device can also disconnect on its own; the device pages list the cases observed on each model.
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.
Commands wait for the device to acknowledge them at the TCP level before
returning, which takes a few milliseconds on a local network. A command sent to
a device that just lost power therefore raises TemescalConnectionError once
the connection is closed, instead of returning as if it had been delivered.
This relies on Linux socket options. Each option is only set when Python
exposes it on the running system, and TCP_USER_TIMEOUT only exists on Linux.
Where an option is missing, the default of the operating system applies, which
is often two hours of silence before the first keepalive probe. Apart from the
check of silent devices that are on, the client sends no
application-level heartbeat, so a device that loses power while the connection
is idle can then go unnoticed for that long. Home Assistant OS and other Linux
hosts are not affected.
Power state
power_on is the last power state the device reported (b_powerstatus), or
None while it is unknown. reports_power tells whether the device reports it
at all: None until the first answer to SPK_LIST_VIEW_INFO, then False if
that answer had no b_powerstatus, and True as soon as one is seen. Devices
that never report it, like the SP8YA, also ignore set_power() (see
Devices without power control), so an
application can hide its power control when reports_power is False.
Silent devices
Some devices stop sending updates without closing the connection, while still
acknowledging at the TCP level, which keepalive cannot notice. When a device
that reported being on has sent nothing for idle_timeout seconds (30 by
default), the client asks it for SPK_LIST_VIEW_INFO. If no answer arrives,
the connection is closed and opened again, which requests the whole state.
Devices in standby and devices that do not report their power state are never
asked, so this does not apply to the SP8YA. The LG S95Q was reported to behave
this way (see its device page).
Asking a device in standby for its state is safe on the models tested so far: neither the SP8YA nor the S95Q wakes up, which the guided report checks. The client therefore asks for the whole state on every connection, including while the device is in standby.
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, twice
TEMESCAL_PORT overrides the default port 9741.
Tested devices
| Model | Firmware (main / micom / Chromecast) | Notes |
|---|---|---|
| LG SP8YA | 2407090 / 2207202 / 1.56.310669 | device page |
| LG S95Q (S95QR) | 2603241 / 2501151 / 1.56.310669 | device page |
Models that worked with python-temescal are expected to work too; this table
only lists the ones tested with aiotemescal itself. The versions are those
reported in UPDATE_VIEW_INFO. Each device page gathers what was learned on
that model: how it identifies itself, when it disconnects by itself, and what
it supports, such as power control.
Contributing
The protocol works the same across models, but the details differ: some report
their power state and others do not, some report their unique identifier
(s_uuid) in MAC_INFO_DEV, others only in PRODUCT_INFO (the S90QY,
according to home-assistant/core#77856)
or not at all (the SP8YA), some offer inputs or sound modes that have no name
in this library yet, some need internet access to stay reachable. Handling
these differences faithfully is a goal of this project, and only one model
has been examined in detail so far. A report from your device is the most
useful contribution, even if everything works.
Report your device
With uv, from any machine on the same network as the device:
uvx aiotemescal report 192.168.1.15 # read-only
uvx aiotemescal report 192.168.1.15 --guided # asks you to put it in standby and on
uvx aiotemescal report 192.168.1.15 --guided --try-power # also tries the power commands
uvx aiotemescal report 192.168.1.15 --guided --name-modes # also asks the names of unknown sound modes
- Without options, the report only asks the device for its state: nothing is changed. It lists what the device reports, the inputs and sound modes it offers, and the messages it does not answer.
--guidedasks you to put the device in standby, then to turn it on, with its remote, its own button or the LG app (not every model has a power button in the app), then to put it in standby the way you usually do (TV off, for example). Steps can be skipped, for example without a remote at hand. For each power change, the report says whether the device sentb_powerstatusby itself, only reported it when asked, or not at all, which tells whether, and how, its power state can be followed. It also compares its full state on and in standby, records every message the device sends by itself, and asks whether asking for the state in standby woke it up.--try-poweralso sends the power commands, which turn the device off and on, and asks you whether they worked.--name-modesselects each sound mode that has no name in aiotemescal, asks you which name the soundbar or the LG app shows for it, then restores the current sound mode. It can be used with or without--guided.
--try-power and --name-modes are the only options that change the device.
Some behaviours only show up over time, or not every time: a device that stops sending updates while it is idle, or after being turned off by hand. The report runs for a few minutes on a single connection and cannot catch them. To look for them, watch the device with debug logs for a longer while, turning it on and off as you usually do, and paste the relevant part:
uvx aiotemescal 192.168.1.15 -v
The report is printed as Markdown, ready to paste (-o FILE writes it to a
file). IP addresses, MAC addresses, UUIDs and the names you gave the device are
replaced with <redacted>; --no-redact keeps them. Read it before posting.
Then open an issue with the report, and anything you noticed that the report cannot see: how the device is connected to the TV, whether it loses the connection by itself, what the LG app shows for an unknown sound mode.
Example, a read-only report of the tested SP8YA while in standby:
## aiotemescal device report
aiotemescal 0.4.0, Python 3.14.10, Linux x86_64
### Findings
- Model: SP8YA
- Firmware (main / micom / Chromecast): 2407090 / 2207202 / 1.56.310669
- Power state: not reported (no `b_powerstatus`), run with --guided to find out which fields change between on and standby
- Unique id: not reported (no `s_uuid`)
- Inputs offered: 0 (Wi-Fi), 1 (Bluetooth), 15 (Optical/HDMI ARC), 6 (HDMI), 19 (USB2)
- Sound modes offered: 19 (AI Sound Pro), 0 (Standard), 7 (Cinema), 20 (Clear Voice), 21 (Sports), 6 (Music), 22 (Game), 14 (Bass Blast), 5 (User), 15 (Dolby Atmos), 23 (unknown)
- Sound modes without a name in aiotemescal: 23
- Current input: 4 (Optical)
- No answer to: `MAC_INFO_DEV`
<details><summary>Full state</summary>
```text
# current
(shortened: one line per message, for all nine messages)
FUNC_VIEW_INFO: {"ai_func_list": [0, 1, 15, 6, 19], "b_connect": false, "i_curr_func": 4, "s_spk_bt_name": "<redacted>"}
PRODUCT_INFO: {"i_model_no": 0, "i_model_type": 0, "i_network_type": 1, "s_model_name": "SP8YA"}
```
</details>
Add a device page
To document a model, copy docs/devices/_template.md
to docs/devices/lg-<model>.md, fill it from the report and your observations,
and add a row to the table above. docs/devices/lg-sp8ya.md
is an example.
Test against your device
If you clone the repository, the live tests check the client against
a real device: make test-live is read-only, make test-actions changes
settings and restores them, and make test-power-cycle needs you to unplug the
device.
Future work
Devices without power control
set_power() does not come from python-temescal. It sends the b_powerkey key
proposed in a pull request to python-temescal
in 2022, which was never merged, and which the Home Assistant integration
copied in 2024 (home-assistant/core#127022).
It worked on the device of whoever added it, but no model was named, and it
does not work everywhere:
| Model | set_power() |
Power state | Source |
|---|---|---|---|
| SP8YA | ignored, on and off | never reported | device page |
| SK8 | does nothing | always shown as on, even after the remote | comment of 2024-12-26 |
| DSP11RA | turns it on, not off | always shown as on | comment of 2025-04-16 |
The client currently sends the command anyway, and an application cannot tell whether it did anything. This needs to be handled:
- tell whether a device supports power control, so that applications can hide
their power button.
reports_poweris a first step, since none of the models above reportsb_powerstatus, but the DSP11RA shows that support can also be partial; - where it is reliable, follow the power state from other fields, such as
b_connecton the SP8YA (only confirmed with the TV as the source so far).
Reports from other models (see Contributing) are needed to know which models are affected and which fields can be trusted.
Devices that go silent after a manual shutdown
On the S95Q, the connection sometimes stops delivering updates after the device is turned off by hand, while the socket still looks open, so the next power-on is never reported. The check of silent devices only covers devices that are on, so it misses this case. A possible fix is to ask the device for its state a few seconds after it reports turning off, and to reconnect if it does not answer, without reporting the device as unavailable when the reconnection succeeds right away.
Unknown inputs and sound modes
The input and sound mode tables come from python-temescal and stop at the
models it knew. The SP8YA
offers sound mode 23 and the S95Q
sound modes 23 to 26, which have no name yet; applications show them as
unknown. Their names have to be found and added to equalisers in
const.py, along with any index reported by other models. The report lists
these indices under "without a name in aiotemescal", and --name-modes asks
for their names.
Support for more models
The client treats every model the same way, as python-temescal did. Handling each model as it really behaves means:
- turning the reports people send (see Contributing) into test fixtures, by loading the state of a report into the fake soundbar of the tests, so that the behaviour of each model stays covered without the device;
- telling applications what a model supports, starting with power control (see above), instead of each application finding out by itself;
- completing the input and sound mode tables (see above).
Power loss detection outside Linux
The client should run on macOS and Windows, which is enough for development,
but it has only been tested on Linux. The keepalive options are only set when
Python exposes them under their Linux names, and commands do not wait for the
device to acknowledge them, so how quickly a power loss is noticed there is
unknown: it may take up to the two hours of the system default (see
Power loss detection). Making this match Linux would
mean setting the equivalents those systems have, such as TCP_KEEPALIVE on
macOS, and testing on them. Since Home Assistant runs on Linux, this is not a
priority.
Identity from mDNS
Some devices give no stable identifier over the protocol: the SP8YA never
reports s_uuid and does not answer MAC_INFO_DEV. They do advertise one over
mDNS, as LG_SMART_AUDIO-<uuid>._lg-smart-device._tcp.local. with the UUID and
the IPv4 address in the TXT record. A helper that reads the UUID and the
address from such an announcement would spare each application from parsing
it.
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.5.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aiotemescal-0.5.1.tar.gz | 55.9 kB | With provenance | Details for aiotemescal-0.5.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aiotemescal-0.5.1-py3-none-any.whl | Python 3 | none | any | Details for aiotemescal-0.5.1-py3-none-any.whl |
Total release size: 83.2 kB
Release files / aiotemescal-0.5.1.tar.gz
| Download URL | aiotemescal-0.5.1.tar.gz |
|---|---|
| Size | 55.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
59e72805a43c01d93507bf625e38142e0b9d610e0d477517f28c55384acf2066
|
|
BLAKE2b-256 checksum How to use checksums |
2a29e2871a53138c8d076f743485c659b7ae118965426f98e92326a26059d1b5
|
| 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 21, 2026.
Transparency logRelease files / aiotemescal-0.5.1-py3-none-any.whl
| Download URL | aiotemescal-0.5.1-py3-none-any.whl |
|---|---|
| Size | 27.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c201ed06efeadb9e7d0300ac43002ba9c977de99cb68dc7548510ab8355335d4
|
|
BLAKE2b-256 checksum How to use checksums |
4930b2193b6aa956acee3a88beae877702d496a3416e11880d9f5e74432455a1
|
| 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 21, 2026.
Transparency logSecurity for aiotemescal 0.5.1
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.
Attestation for aiotemescal-0.5.1.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 21, 2026.
Transparency logA 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.