Skip to main content

sony-tv-rs232

Async Python library to control Sony Bravia TVs over RS232 serial, built on serialkit (the serial-toolkit distribution on PyPI) and serialx.

Installation

pip install sony-tv-rs232

# To talk to a TV over an ESPHome serial proxy:
pip install 'sony-tv-rs232[esphome]'

Requires Python 3.14+.

Quick start

import asyncio
from sony_tv_rs232 import SonyTV, InputSource


async def main():
    tv = SonyTV("/dev/ttyUSB0")
    await tv.connect()

    await tv.enable_standby_listening()  # so power_on works from standby
    await tv.power_on()
    await tv.set_volume(20)
    await tv.select_input_source(InputSource.HDMI1)

    await tv.disconnect()


asyncio.run(main())

CLI

python -m sony_tv_rs232 /dev/ttyUSB0                 # query + print status
python -m sony_tv_rs232 socket://192.168.1.29:5000   # raw TCP bridge
python -m sony_tv_rs232 'esphome://192.168.1.29/?port_name=TTL'
python -m sony_tv_rs232 /dev/ttyUSB0 --power on
python -m sony_tv_rs232 /dev/ttyUSB0 --input HDMI1
python -m sony_tv_rs232 /dev/ttyUSB0 --diagnose      # raw wiring diagnosis

Protocol notes

Sony's consumer RS-232C protocol is effectively set-only: the TV acknowledges every Set command but most models ignore query packets, and the answer frame carries no echo of which command it answers. The library:

  • updates state optimistically when a Set is acknowledged, and from query replies on the Pro Bravia displays that answer them. A relative volume step clears state.volume, since its ack does not say where the volume landed;
  • runs every command as an exclusive exchange, because answers are unaddressed — holding the wire for one send-and-read round, anchored on arrival order, is what keeps a dropped or garbled answer from being read as the next command's;
  • paces commands ≥ 500 ms apart, as the Sony spec requires;
  • resends the first command after an idle gap once: a TV that has slept loses the leading bytes of the frame that wakes it and answers PARSE_ERROR, so that reply is treated as "send it again". When the wake is silent instead, a query (never a set) that goes unanswered after the TV has been quiet for a few seconds is resent once as well;
  • reconnects automatically when the serial link drops.

All of that machinery lives in serialkit; this library is the Sony command surface plus a checksum-discriminated answer framer.

Connection handling

from sony_tv_rs232 import CommandTimeoutError, ConnectionLostError, SonyCommandError

try:
    await tv.set_volume(50)
except SonyCommandError as err:  # TV returned a non-zero answer code
    ...
except CommandTimeoutError:  # no answer in time (common on set-only TVs)
    ...
except ConnectionLostError:  # serial link dropped
    ...

Subscribe to state changes; callbacks receive a TVState snapshot, or None when the connection is lost:

unsub = tv.subscribe(lambda state: print("state:", state))

Serial connection

Sony Bravia sets use 9600 baud, 8N1. The library accepts any serialx-compatible URL (/dev/ttyUSB0, socket://host:port, esphome://host/?port_name=TTL).

Development

uv run --python 3.14 pytest
uv run --python 3.14 --with mypy mypy --strict src/
uvx ruff check && uvx ruff format --check

The RS-232C protocol reference is in docs/.

License

MIT

Metadata

Release files for sony-tv-rs232 0.3.4

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

Source distribution (sdist)

Source distribution for sony-tv-rs232 0.3.4
File Size Uploaded Provenance Actions
sony_tv_rs232-0.3.4.tar.gz 18.5 kB With provenance Details for sony_tv_rs232-0.3.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sony-tv-rs232 0.3.4
File Interpreter ABI Platform Actions
sony_tv_rs232-0.3.4-py3-none-any.whl Python 3 none any Details for sony_tv_rs232-0.3.4-py3-none-any.whl

Total release size: 40.6 kB

Release files / sony_tv_rs232-0.3.4.tar.gz

Download URL sony_tv_rs232-0.3.4.tar.gz
Size 18.5 kB
Tags Source
SHA-256 checksum
How to use checksums
cc6ff3d39ccfa76ebb0f428b93a1ed2ce0be9e5f10155be6520ffff1093360dc
BLAKE2b-256 checksum
How to use checksums
d21de595c28b91f9d7bc3f36b77b985a1a07c12546f3c711535826224453c8cc
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 7, 2026.

Transparency log

Release files / sony_tv_rs232-0.3.4-py3-none-any.whl

Download URL sony_tv_rs232-0.3.4-py3-none-any.whl
Size 22.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
371c64001a693528d4ac37242d39e5fd5d294769c095427cb63397fdba790c93
BLAKE2b-256 checksum
How to use checksums
aaf8f13c99ced68465359f8ce9777c02134e067be4322cd5e46d71148bdea834
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 7, 2026.

Transparency log

Security for sony-tv-rs232 0.3.4

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 sony_tv_rs232-0.3.4.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 7, 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