Name | pyswitchbee JSON |
Version |
1.8.0
JSON |
| download |
home_page | |
Summary | SwitchBee Python Integration. |
upload_time | 2023-05-07 10:46:37 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.9 |
license | |
keywords |
home
automation
switchbee
smart
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# pySwitchbee
A Python module library to control [SwitchBee](https://www.switchbee.com) smart home devices.
![PyPI](https://img.shields.io/pypi/v/pyswitchbee?label=pypi%20package)
![PyPI - Downloads](https://img.shields.io/pypi/dm/pyswitchbee)
![alt text](https://brands.home-assistant.io/switchbee/logo@2x.png)
## Example code usage:
```python
from asyncio import get_event_loop
from aiohttp import ClientSession, ClientTimeout, TCPConnector
from switchbee.api import CentralUnitAPI
from switchbee.device import ApiStateCommand, DeviceType
async def main():
session = ClientSession(
connector=TCPConnector(ssl=False),
timeout=ClientTimeout(total=3),
)
cu = CentralUnitAPI("192.168.50.2", "user", "pass", session)
await cu.connect()
print(f"Central Unit Name: {cu.name}")
print(f"Central Unit MAC: {cu.mac}")
print(f"Central Unit Version: {cu.version}")
devices = await cu.devices
for device in devices:
# set the dimmer lights to 50% brightness
if device.type == DeviceType.Dimmer:
print(
"Discovered Dimmer device called {device.name}"
" current brightness is {device.brigt}"
)
await cu.set_state(device.id, 50)
# set the shutters position to 30% opened
if device.type == DeviceType.Shutter:
print(
"Discovered Shutter device called {device.name}"
" current position is {device.position}"
)
await cu.set_state(device.id, 30)
# turn off switches
if device.type == DeviceType.Switch:
print(
"Discovered Switch device called {device.name}"
" current state is {device.state}"
)
await cu.set_state(device.id, ApiStateCommand.OFF)
# set timer switch on for 10 minutes
if device.type == DeviceType.TimedPower:
print(
"Discovered Timed Power device called {device.name}"
" current state is {device.state} with {device.minutes_left} "
"minutes left until shutdown"
)
await cu.set_state(device.id, 10)
session.close()
if __name__ == "__main__":
get_event_loop().run_until_complete(main())
exit()
```
## Using the CLI tool:
Alternatively, it is possible to control [SwitchBee](https://www.switchbee.com) devices using the cli tool `switchbee_cli.py` as following:
To list devices that currently on:
`python switchbee_cli.py -i 192.168.50.2 -u USERNAME -p PASSWORD get_states --only-on`
```
'_state': 'ON',
'hardware': <HardwareType.Switch: 'DIMMABLE_SWITCH'>,
'id': 311,
'name': 'Ceiling',
'type': <DeviceType.Switch: 'SWITCH'>,
'zone': 'Outdoo Storage'}
{ '_state': 'ON',
'hardware': <HardwareType.Switch: 'DIMMABLE_SWITCH'>,
'id': 142,
'name': 'Spotlights',
'type': <DeviceType.Switch: 'SWITCH'>,
'zone': 'Porch'}
```
To set shutter with device id 392 position 50%:
`python switchbee_cli.py -i 192.168.50.2 -u USERNAME -p PASSWORD set_state --device-id 392 --state 50`
To turn on Power Timed Switch with device id 450 for 30 minutes:
`python switchbee_cli.py -i 192.168.50.2 -u USERNAME -p PASSWORD set_state --device-id 450 --state 30`
To turn off light with device id 122:
`python switchbee_cli.py -i 192.168.50.2 -u USERNAME -p PASSWORD set_state --device-id 122 --state OFF`
Raw data
{
"_id": null,
"home_page": "",
"name": "pyswitchbee",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "",
"keywords": "home,automation,switchbee,smart",
"author": "",
"author_email": "Jafar Atili <at.jafar@outlook.com>",
"download_url": "https://files.pythonhosted.org/packages/ba/6e/ef09694f0f25f056e143fcab77681cb9b61f7f74a98dea4a0f6743202a91/pyswitchbee-1.8.0.tar.gz",
"platform": null,
"description": "# pySwitchbee\n\nA Python module library to control [SwitchBee](https://www.switchbee.com) smart home devices.\n\n![PyPI](https://img.shields.io/pypi/v/pyswitchbee?label=pypi%20package)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/pyswitchbee)\n\n![alt text](https://brands.home-assistant.io/switchbee/logo@2x.png)\n\n\n\n## Example code usage:\n\n```python\nfrom asyncio import get_event_loop\n\nfrom aiohttp import ClientSession, ClientTimeout, TCPConnector\n\nfrom switchbee.api import CentralUnitAPI\nfrom switchbee.device import ApiStateCommand, DeviceType\n\n\nasync def main():\n session = ClientSession(\n connector=TCPConnector(ssl=False),\n timeout=ClientTimeout(total=3),\n )\n\n cu = CentralUnitAPI(\"192.168.50.2\", \"user\", \"pass\", session)\n await cu.connect()\n\n print(f\"Central Unit Name: {cu.name}\")\n print(f\"Central Unit MAC: {cu.mac}\")\n print(f\"Central Unit Version: {cu.version}\")\n\n devices = await cu.devices\n\n for device in devices:\n # set the dimmer lights to 50% brightness\n if device.type == DeviceType.Dimmer:\n print(\n \"Discovered Dimmer device called {device.name}\"\n \" current brightness is {device.brigt}\"\n )\n await cu.set_state(device.id, 50)\n\n # set the shutters position to 30% opened\n if device.type == DeviceType.Shutter:\n print(\n \"Discovered Shutter device called {device.name}\"\n \" current position is {device.position}\"\n )\n await cu.set_state(device.id, 30)\n\n # turn off switches\n if device.type == DeviceType.Switch:\n print(\n \"Discovered Switch device called {device.name}\"\n \" current state is {device.state}\"\n )\n await cu.set_state(device.id, ApiStateCommand.OFF)\n\n # set timer switch on for 10 minutes\n if device.type == DeviceType.TimedPower:\n print(\n \"Discovered Timed Power device called {device.name}\"\n \" current state is {device.state} with {device.minutes_left} \"\n \"minutes left until shutdown\"\n )\n await cu.set_state(device.id, 10)\n\n session.close()\n\n\nif __name__ == \"__main__\":\n\n get_event_loop().run_until_complete(main())\n exit()\n```\n\n## Using the CLI tool:\n\nAlternatively, it is possible to control [SwitchBee](https://www.switchbee.com) devices using the cli tool `switchbee_cli.py` as following:\n\nTo list devices that currently on:\n\n`python switchbee_cli.py -i 192.168.50.2 -u USERNAME -p PASSWORD get_states --only-on`\n\n```\n '_state': 'ON',\n 'hardware': <HardwareType.Switch: 'DIMMABLE_SWITCH'>,\n 'id': 311,\n 'name': 'Ceiling',\n 'type': <DeviceType.Switch: 'SWITCH'>,\n 'zone': 'Outdoo Storage'}\n\n{ '_state': 'ON',\n 'hardware': <HardwareType.Switch: 'DIMMABLE_SWITCH'>,\n 'id': 142,\n 'name': 'Spotlights',\n 'type': <DeviceType.Switch: 'SWITCH'>,\n 'zone': 'Porch'}\n```\n\nTo set shutter with device id 392 position 50%:\n\n`python switchbee_cli.py -i 192.168.50.2 -u USERNAME -p PASSWORD set_state --device-id 392 --state 50`\n\n\nTo turn on Power Timed Switch with device id 450 for 30 minutes:\n\n`python switchbee_cli.py -i 192.168.50.2 -u USERNAME -p PASSWORD set_state --device-id 450 --state 30`\n\n\nTo turn off light with device id 122:\n\n`python switchbee_cli.py -i 192.168.50.2 -u USERNAME -p PASSWORD set_state --device-id 122 --state OFF`\n",
"bugtrack_url": null,
"license": "",
"summary": "SwitchBee Python Integration.",
"version": "1.8.0",
"project_urls": {
"homepage": "https://pypi.org/project/pyswitchbee/",
"repository": "https://github.com/jafar-atili/pySwitchbee/"
},
"split_keywords": [
"home",
"automation",
"switchbee",
"smart"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d1622eb26a5f5bf8cf9225e021de4983a2f2ad31853935655b2cc887d99b1c7b",
"md5": "e4b3ed92d846d306cef2070077b412e9",
"sha256": "a309089201b2954f6266f8c743f2e6f6f27a7b5c6904cc5e01d2fe2a3b5a2fa5"
},
"downloads": -1,
"filename": "pyswitchbee-1.8.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e4b3ed92d846d306cef2070077b412e9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 19570,
"upload_time": "2023-05-07T10:46:34",
"upload_time_iso_8601": "2023-05-07T10:46:34.899324Z",
"url": "https://files.pythonhosted.org/packages/d1/62/2eb26a5f5bf8cf9225e021de4983a2f2ad31853935655b2cc887d99b1c7b/pyswitchbee-1.8.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ba6eef09694f0f25f056e143fcab77681cb9b61f7f74a98dea4a0f6743202a91",
"md5": "75b3d10dc1e2933a7ea72ddb50b88d42",
"sha256": "5bf0b169daa0a714ee8e8f2210ea98f3d522f551bb1dd9a8bd2f7a0d1abdb826"
},
"downloads": -1,
"filename": "pyswitchbee-1.8.0.tar.gz",
"has_sig": false,
"md5_digest": "75b3d10dc1e2933a7ea72ddb50b88d42",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 16805,
"upload_time": "2023-05-07T10:46:37",
"upload_time_iso_8601": "2023-05-07T10:46:37.268293Z",
"url": "https://files.pythonhosted.org/packages/ba/6e/ef09694f0f25f056e143fcab77681cb9b61f7f74a98dea4a0f6743202a91/pyswitchbee-1.8.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-07 10:46:37",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jafar-atili",
"github_project": "pySwitchbee",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pyswitchbee"
}