roku-smarthome
Control Roku Smart Home plugs and bulbs from Python. Read status, switch power, set brightness and color temperature, from a command line or as a library you drop into your own project.
Roku publishes no API for its Smart Home line, and the only integrations are Alexa and Google Assistant. This package talks to the same backend that Roku's own web app at my.roku.com/smarthome uses, with your own account session. No reverse-engineered mobile app login, no email verification codes, no soldering. Log in once and it stays logged in.
Not affiliated with or endorsed by Roku.
Developed and tested against the Roku Indoor Smart Plug SE (PS1000X) and the Roku Smart Bulb (BS1000X). Cameras show up in the device list with online state; video is out of scope.
What it can do
- List every device on your Roku Smart Home account with its state: power, online, brightness, color temperature
- Turn plugs and bulbs on and off
- Set bulb brightness (0 to 100) and white color temperature (2700K to 6500K on the tested bulb; values outside 1800K to 6500K are rejected)
- Set RGB color on color bulbs (confirmed working by a user with a color bulb, see #1)
- Send any other command a device advertises, via a generic escape hatch
- Keep itself logged in: Roku renews the session on every request and this client saves the renewed cookie, so the login never expires as long as you use it at least once a year
Install
pip install roku-smarthome
Or clone this repo and pip install . to build the exact package that's published to PyPI.
Requirements
- Python 3.10+
requestsandwebsockets(installed automatically by pip)
Setup
1. Copy your session cookie (once)
- Sign in at https://my.roku.com/smarthome in a desktop browser.
- Open DevTools (F12) and go to the Network tab. Type
leavesin the filter box and reload the page. - Click the
leavesrequest. In Headers, scroll down to Request Headers and copy the entire value of theCookieheader. (Right-click the request > Copy > "Copy as cURL" also works; the value is on the-H 'Cookie: ...'line.)
2. Save it
roku-smarthome login
Paste the cookie value when prompted (a whole "Copy as cURL" command or a Cookie: prefix is fine too). What you paste isn't shown on screen. Avoid passing the cookie as an argument instead, since it would end up in your shell history. It's verified against your account before it's saved, so a bad paste keeps your previous login, and it's saved to a per-user file (%USERPROFILE%\.config\roku-smarthome\cookies.json on Windows, ~/.config/roku-smarthome/cookies.json on macOS/Linux). Set ROKU_SMARTHOME_COOKIES or pass --cookies PATH to use a different location.
Keep that file private. It is a working login to your Roku account. Don't share it, and don't paste the cookie into chat windows or bug reports. It's stored outside the project folder, so it can't be committed by accident.
3. Run
roku-smarthome status
Command line
roku-smarthome status # list devices and state
roku-smarthome on "Living room lamp"
roku-smarthome off "Living room lamp"
roku-smarthome toggle "Living room lamp"
roku-smarthome brightness "Bedroom bulb" 40 # 0-100
roku-smarthome temp "Bedroom bulb" 3000 # Kelvin, 1800-6500
roku-smarthome rgb "Color bulb" 255 80 0 # color bulbs only
roku-smarthome rgb "Color bulb" "#ff5000" # same, as a hex color
roku-smarthome json # raw device list, for piping elsewhere
roku-smarthome watch # print changes live, from anywhere (Ctrl-C to stop)
roku-smarthome --cookies PATH status # use a different cookie file
Device names are matched case-insensitively against the names in the Roku Smart Home app, and you can shorten them to any part that only one device has: roku-smarthome on porch works for "Porch Camera". If a short name matches several devices, the error lists them.
Exit codes, for scripts and cron jobs: 0 OK, 1 error (unknown device, bad value, unsupported command), 2 bad arguments, 3 session expired (run login again), 4 Roku unreachable (retry later), 5 Roku received the command but reported that it failed, 130 interrupted with Ctrl-C.
In Python, rk.find("porch") does the same forgiving lookup; rk.get(name) still requires the exact name, and refuses to guess if two devices share it (use rk.get(id, by_id=True) then).
Use it as a library
from roku_smarthome import RokuSmartHome
rk = RokuSmartHome() # uses the default cookie file
for d in rk.devices():
print(d.name, d.type, d.power, d.online, d.brightness, d.color_temp)
lamp = rk.get("Living room lamp")
lamp.turn_on()
lamp.turn_off()
lamp.toggle()
print(lamp.is_on)
bulb = rk.get("Bedroom bulb")
bulb.set_brightness(40)
bulb.set_color_temp(3000)
bulb.set_color_rgb(255, 80, 0) # color bulbs only
bulb.refresh() # re-fetch state from Roku
print(bulb.brightness, bulb.color_temp)
# anything else the device advertises in supportedCommands
bulb.send("color", {"colorType": "temperature", "temperature": 4000})
Device attributes: id, name, type (plug, light, camera), model, local_ip, power ("on"/"off"), online, brightness, color_temp, color_type, color_rgb, supported_commands, and raw (the untouched JSON).
Sending many commands quickly
The client keeps one connection to Roku open and reuses it, so commands sent in a row (a brightness slider, a scene that changes several bulbs) go out almost instantly instead of each opening a new connection. If the connection has dropped, the next command reconnects and resends automatically. The connection closes by itself after 60 seconds without a command (idle_timeout).
Close it when you're done, or use a with block. It is also closed automatically when your script exits.
with RokuSmartHome() as rk:
bulb = rk.get("Bedroom bulb")
for level in range(0, 101, 10):
bulb.set_brightness(level)
Pass persistent=False to go back to one connection per command (the behavior before 0.3.0).
Live updates
Roku pushes a message whenever a device changes, whether from your code, the Roku app, a voice assistant or the device's own button. Register a callback to hear about it, instead of polling:
rk = RokuSmartHome()
def changed(device):
print(device.name, device.power, device.brightness)
stop = rk.on_change(changed) # keeps the connection open and listens
...
stop() # or rk.close()
device is a full Device with the new state. Callbacks run one at a time on their own thread, so they can send commands. If the connection drops, it reconnects automatically (waiting 1 s, then 2, 4... up to 60 s between tries) and reports any changes it missed. While it's retrying, rk.live_error says why, for example SessionExpired if the login needs renewing; it's None while connected. From the command line, roku-smarthome watch prints the same updates, and exits with code 3 if the login expires.
Exceptions: SessionExpired (saved cookie no longer works; run login again), RokuUnavailable (Roku's API unreachable or erroring, or no reply to a command; retry later), CommandFailed (Roku received the command and reported an error, e.g. failed to execute command), DeviceNotFound, and UnsupportedCommand (raised instead of sending a command the device doesn't list).
Each command waits for Roku's reply (usually 0.1 to 2 seconds) so failures are reported. Pass confirm=False to RokuSmartHome(), or to a single send(), to skip that, for example for a brightness slider.
Keeping it logged in
Every request to Roku's API comes back with a re-issued session cookie carrying a fresh 365-day expiry. This client saves that cookie back into its file whenever it fetches the device list (status, devices(), get(), find(), and every CLI command). In practice: if anything uses this library at least once a year, the login is permanent. A daily cron entry like
0 9 * * * /path/to/venv/bin/roku-smarthome status > /dev/null
is enough on a machine that would otherwise sit idle.
Roku's sign-in page emails a verification code on every new login, which is why this package deliberately does not try to automate the email/password flow. Copying the cookie once is simpler and more reliable.
How it works
GET https://my.roku.com/smarthome/api/v1/leavesreturns every device ("leaf") with its current state.- Commands go over a websocket at
wss://aspen-sockets.aspen.msc.roku.com/v1/socketas{"id": ..., "type": "send_command", "payload": {"leafId": ..., "leafType": "device", "command": {"command": ..., "parameters": {...}}}}. - Known commands:
power {"power": "on"|"off"},brightness {"level": 0-100},color {"colorType": "temperature", "temperature": K},color {"colorType": "rgb", "rgb": [r, g, b]}. - Authentication is the
ks.sessioncookie from the browser, sent on both the REST call and the websocket handshake.
The Roku Smart Home line is Wyze hardware sold under the Roku brand, but the devices are registered to Roku's cloud, not Wyze's, so Wyze libraries can't log in to them. The earlier community effort (a 2022 fork of wyzeapy that reproduced the Roku mobile app's AWS Cognito login) stopped working when Roku removed that endpoint.
Notes and limitations
- Cloud only. The plugs have a local API on port 88 but it's encrypted with a key that only the Roku/Wyze login flow hands out. Local control would mean flashing ESPHome or Tasmota onto the ESP32 inside, which requires opening the device.
- Unofficial. Roku could change or remove these endpoints at any time. If
statusstarts failing with something other thanSESSION EXPIRED, that's probably what happened; please open an issue with the error (and the cookie value removed). - Cameras are listed with name and online state only. Streams, events and settings are visible in the API but not implemented here.
- RGB color was implemented from Roku's web app without a color bulb to test on, and has since been confirmed working by a user (#1). The parameter shape is
{"colorType": "rgb", "rgb": [r, g, b]}, each 0 to 255. - A command Roku confirms has been accepted by Roku's cloud; the device itself acts a moment later. Call
refresh()if you need to see the new state. toggle()flips based on the state theDeviceobject last saw. If something else may have changed the device, callrefresh()first.- The shared connection and live updates are tested on a real plug (PS1000X), including changes made through Google Assistant. Bulbs haven't been tested with them yet. If commands start failing after a period of inactivity, try
persistent=Falseand please open an issue.
Project layout
src/roku_smarthome/
__init__.py package entry, exports RokuSmartHome, Device and the exceptions
client.py the library: cookie handling, device list, commands
cli.py the command line
pyproject.toml packaging / build config
tests/ test suite (pip install . pytest; python -m pytest)
ROADMAP.md planned improvements
CHANGELOG.md what changed in each release
LICENSE MIT
Clone and pip install . to build exactly what's published to PyPI.
A note on how this was built
This started as "can I read my smart plug from Python," went through a dead 2022 library, a Windows DNS bug, and a login endpoint Roku had deleted, before landing on the web app's own API. Watching the network traffic on my.roku.com/smarthome showed that the device list included plugs and bulbs even though the page only displays cameras; from there the websocket command format came out of the web app's JavaScript, was confirmed on real hardware, and testing showed that Roku renews the session cookie on every request, which is what makes this usable long-term without any login automation.
I used AI assistance throughout: for digging through the minified web app, for the client and CLI code, and for this README. The testing on real devices, the decisions about what to build and what to leave out, and the packaging are mine.
Acknowledgements
Thanks to the people in the Home Assistant community thread who mapped the original Wyze/Roku relationship and the 2022 mobile-app login, and to wyze-sdk and wyzeapy for showing what the underlying hardware speaks.
Metadata
Release files for roku-smarthome 0.3.2
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 |
|---|---|---|---|---|
| roku_smarthome-0.3.2.tar.gz | 52.6 kB | With provenance | Details for roku_smarthome-0.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| roku_smarthome-0.3.2-py3-none-any.whl | Python 3 | none | any | Details for roku_smarthome-0.3.2-py3-none-any.whl |
Total release size: 79.2 kB
Release files / roku_smarthome-0.3.2.tar.gz
| Download URL | roku_smarthome-0.3.2.tar.gz |
|---|---|
| Size | 52.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d2aa75e3d0c7d8520aab2bf84df7ec22d5f0c1cbc058c150ae3009bea154d0c1
|
|
BLAKE2b-256 checksum How to use checksums |
9c8313d5e5725845de283b673a961d81d161b407d26402177408fc08ab914410
|
| 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 15, 2026.
Transparency logRelease files / roku_smarthome-0.3.2-py3-none-any.whl
| Download URL | roku_smarthome-0.3.2-py3-none-any.whl |
|---|---|
| Size | 26.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6dc85e700ac7016316fb3d9fc7736922a8e5ab5894c7163850367d8953701dc0
|
|
BLAKE2b-256 checksum How to use checksums |
682423599f0b413ceea403cf756e0e88b9b4d249692e651899d81dd97dbc5648
|
| 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 15, 2026.
Transparency logSecurity for roku-smarthome 0.3.2
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 roku_smarthome-0.3.2.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 15, 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.