Async Samsung 2024+ TV control via the HTTPS JSON-RPC interface
Project description
py-samsungtv
py-samsungtv is an async Python library that talks to Samsung TVs over HTTPS JSON-RPC.
Why
Samsung, in their infinite wisdom, disabled ports 8001 and 8002. This breaks the existing Home Assistant integration/libraries for all 2024+ models. They still expose their JSON-RPC over port 1516/1515, but it is undocumented.
I got frustrated enough to do a clean-room implemenation of it here.
Installation
# pypi
pip install py-samsungtv
# local dev
just install
The package depends on aiohttp for HTTP/1.1 TLS transport. TLS verification is disabled by default because Samsung panels present self-signed certificates; set verify_ssl=True when the certificate chain is trusted on your host.
Usage
Check tests for example usage.
Every helper method corresponds to the JSON-RPC methods in the protocol notes (e.g. get_tv_states, direct_channel_control, volume_up_down, remote_key_control, sound_mode_control, etc). Each coroutine returns the parsed result body or raises a SamsungTVError subclass on transport/protocol failures. Custom RPCs can be issued with SamsungTVClient.send_request().
The optional on_update callback is invoked sequentially after every response. It receives the RPC method name and the parsed payload, making it easy to wire into Home Assistant's entity update routines.
Development
- Install and run
pre-commit(pip install pre-commit && pre-commit install) to ensuremypyandpytestpass locally before committing. - All code is typed and passes
mypyusing the configuration inpyproject.toml. - Run the test suite with
pytest. Unit tests use fully mocked transports. - Integration tests require a real TV: set
SAMSUNG_TV_HOST(plus optionalSAMSUNG_TV_PORTand/orSAMSUNG_TV_TOKEN) and runpytest -m integration. If no token is supplied the first run will prompt for authorization and cache the returned token under.pytest_cache/samsung_tv_tokenfor later runs. - A
Justfileis included for convenience:just install,just install-tests,just test,just mypy, etc. - All command inputs are exposed as enums in
samsungtv.enums(also re-exported at the package root) so you can rely on autocomplete/validation for things likeInputSource,PictureMode,SoundMode, andRemoteKey. - Convenience helpers such as
set_picture_mode,set_sound_mode,select_speaker,select_input_source,set_volume,mute()/unmute(), andart_mode_on()/art_mode_off()call the corresponding*_controlRPCs for you.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_samsungtv-1.0.0.tar.gz.
File metadata
- Download URL: py_samsungtv-1.0.0.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d6c24bbc80733beb38dcc4098ab6acd696c5ade1225db0cb14b9526a596405f
|
|
| MD5 |
36fb408c43c3d35c162c02088f82e36a
|
|
| BLAKE2b-256 |
48b540e9477151240da611ee9028404958432f44754f9bb7ec9ca90bd92b02d7
|
Provenance
The following attestation bundles were made for py_samsungtv-1.0.0.tar.gz:
Publisher:
publish.yaml on iloveicedgreentea/py-samsungtv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_samsungtv-1.0.0.tar.gz -
Subject digest:
8d6c24bbc80733beb38dcc4098ab6acd696c5ade1225db0cb14b9526a596405f - Sigstore transparency entry: 702155641
- Sigstore integration time:
-
Permalink:
iloveicedgreentea/py-samsungtv@e4545b23d0de154f47e2f84f49c447d067bfb3d1 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/iloveicedgreentea
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@e4545b23d0de154f47e2f84f49c447d067bfb3d1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file py_samsungtv-1.0.0-py3-none-any.whl.
File metadata
- Download URL: py_samsungtv-1.0.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b9e354f901f83e384120ddcbf92c816277dc0257c90d72bd3d43dd72c4c3038
|
|
| MD5 |
d1b90f424c381bdc78458fac462c2862
|
|
| BLAKE2b-256 |
207f168773a54a2e5e5d17c324fdd0785284b41eb7e71cce80226e95fa755293
|
Provenance
The following attestation bundles were made for py_samsungtv-1.0.0-py3-none-any.whl:
Publisher:
publish.yaml on iloveicedgreentea/py-samsungtv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_samsungtv-1.0.0-py3-none-any.whl -
Subject digest:
1b9e354f901f83e384120ddcbf92c816277dc0257c90d72bd3d43dd72c4c3038 - Sigstore transparency entry: 702155642
- Sigstore integration time:
-
Permalink:
iloveicedgreentea/py-samsungtv@e4545b23d0de154f47e2f84f49c447d067bfb3d1 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/iloveicedgreentea
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@e4545b23d0de154f47e2f84f49c447d067bfb3d1 -
Trigger Event:
push
-
Statement type: