https://github.com/lawtancool/pycontrol4
Python 3 asyncio package for interacting with Control4 systems
https://github.com/lawtancool/pycontrol4
control4 home-assistant
Last synced: 4 months ago
JSON representation
Python 3 asyncio package for interacting with Control4 systems
- Host: GitHub
- URL: https://github.com/lawtancool/pycontrol4
- Owner: lawtancool
- License: apache-2.0
- Created: 2020-06-09T03:10:03.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-09-01T21:44:11.000Z (almost 2 years ago)
- Last Synced: 2025-05-23T15:33:32.796Z (about 1 year ago)
- Topics: control4, home-assistant
- Language: Python
- Homepage: https://lawtancool.github.io/pyControl4/
- Size: 245 KB
- Stars: 40
- Watchers: 6
- Forks: 17
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pyControl4
[](https://badge.fury.io/py/pyControl4)[](https://pepy.tech/project/pycontrol4)
[](https://github.com/lawtancool/pyControl4/actions?query=workflow%3ACI)[](https://github.com/lawtancool/pyControl4/actions?query=workflow%3Apdoc)[](https://github.com/lawtancool/pyControl4/actions?query=workflow%3A%22PyPI+Release%22)
An asynchronous library to interact with Control4 systems through their built-in REST API. This is known to work on controllers with OS 2.10.1.544795-res and OS 3.0+.
Auto-generated function documentation can be found at
For those who are looking for a pre-built solution for controlling their devices, this library is implemented in the [official Home Assistant Control4 integration](https://www.home-assistant.io/integrations/control4/).
## Usage example
```python
from pyControl4.account import C4Account
from pyControl4.director import C4Director
from pyControl4.light import C4Light
import asyncio
username = ""
password = ""
ip = "192.168.1.25"
"""Authenticate with Control4 account"""
account = C4Account(username, password)
asyncio.run(account.get_account_bearer_token())
"""Get and print controller name"""
account_controllers = asyncio.run(account.get_account_controllers())
print(account_controllers["controllerCommonName"])
"""Get bearer token to communicate with controller locally"""
director_bearer_token = asyncio.run(
account.get_director_bearer_token(account_controllers["controllerCommonName"])
)["token"]
"""Create new C4Director instance"""
director = C4Director(ip, director_bearer_token)
"""Print all devices on the controller"""
print(asyncio.run(director.get_all_item_info()))
"""Create new C4Light instance"""
light = C4Light(director, 253)
"""Ramp light level to 10% over 10000ms"""
asyncio.run(light.ramp_to_level(10, 10000))
"""Print state of light"""
print(asyncio.run(light.get_state()))
```
## Contributing
Pull requests are welcome! Please lint your Python code with `flake8` and format it with [Black](https://pypi.org/project/black/).
## Disclaimer
This library is not affiliated with or endorsed by Control4.