This is a fork from [jonghwanhyeon/python-switchbot](https://github.com/jonghwanhyeon/python-switchbot), which seemed
abandoned at the time of the form. The fork was necessary since the package import name conflicts with https://github.com/sblibs/pySwitchbot,
used by home assistant. I will merge any pull requests, but I am not planning on actively developing it.
# python-switchbot
A Python library to control SwitchBot devices connected to SwitchBot Hub.
## Requirements
- Python 3.7+
- [A SwitchBot Token](https://github.com/OpenWonderLabs/SwitchBotAPI#getting-started)
## Installation
```python
pip install python-switchbot-v2
```
## Usage
### Devices
```python
from python_switchbot_v2 import SwitchBot
# To get the token and secret, please refer to https://github.com/OpenWonderLabs/SwitchBotAPI#getting-started
your_switch_bot_token = '98a6732b2ac256d40ffab7db31a82f518969f4d1a64eadff581d45e902327b7c577aa6ead517bda589c19b4ca0b2599b'
your_switch_bot_secret = '222cdc22f049d111c5d0071c131b8b77'
switchbot = SwitchBot(token=your_switch_bot_token, secret=your_switch_bot_secret)
# To list all devices
devices = switchbot.devices()
for device in devices:
print(device)
# Bot(id=CD0A18B1C291)
# Lock(id=CD0A1221C291)
# HubMini(id=4CAF08629A21)
# Bot(id=5F0B798AEF91)
# If you already know a device id:
device = switchbot.device(id='5F0B798AEF91')
# Device(id=5F0B798AEF91)
# To query a status of a device
print(device.status())
# {'power': 'off'}
# To command actions,
device.command('turn_on')
device.command('turn_off')
device.command('press')
device.command('set_position', parameter='0,ff,80')
# For some device types like Bot:
bot = devices[0]
bot.turn('on')
bot.turn('off')
bot.toggle()
bot.press()
# For some device types like Lock:
lock = devices[1]
lock.lock()
lock.unlock()
lock.toggle()
```
### Remotes
```python
# To list all infra red remotes
remotes = switchbot.remotes()
for remote in remotes:
print(remote)
# If you already know a remote id:
remote = switchbot.remote(id='')
# Supported devices such as fans, air purifiers:
remote.turn('on')
remote.turn('off')
# To send supported commands,
remote.command('swing')
remote.command('low_speed')
# To send custom commands,
remote.command('MyCustomCommand', customize=True)
```
### Scenes
```python
# To list all infra red remotes
scenes = switchbot.scenes()
for scene in scenes:
print(scene)
# If you already know a remote id:
scene = switchbot.scene(id='')
# To execute scene
scene.execute()
```
Raw data
{
"_id": null,
"home_page": "https://github.com/areazus/python-switchbot-v2",
"name": "python-switchbot-v2",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "python-switchbot-v2",
"author": "Ahmed Reaz",
"author_email": "dev@areaz.us",
"download_url": "https://files.pythonhosted.org/packages/c5/72/a19fbf2f0edc5ed66899ce4c3fe25d82d4864079a619c0d309c98bea30ee/python_switchbot_v2-2.3.1.tar.gz",
"platform": null,
"description": "This is a fork from [jonghwanhyeon/python-switchbot](https://github.com/jonghwanhyeon/python-switchbot), which seemed\nabandoned at the time of the form. The fork was necessary since the package import name conflicts with https://github.com/sblibs/pySwitchbot,\nused by home assistant. I will merge any pull requests, but I am not planning on actively developing it.\n\n# python-switchbot\nA Python library to control SwitchBot devices connected to SwitchBot Hub.\n\n## Requirements\n- Python 3.7+\n- [A SwitchBot Token](https://github.com/OpenWonderLabs/SwitchBotAPI#getting-started)\n\n## Installation\n```python\npip install python-switchbot-v2\n```\n\n## Usage\n\n\n### Devices\n\n```python\nfrom python_switchbot_v2 import SwitchBot\n\n# To get the token and secret, please refer to https://github.com/OpenWonderLabs/SwitchBotAPI#getting-started\nyour_switch_bot_token = '98a6732b2ac256d40ffab7db31a82f518969f4d1a64eadff581d45e902327b7c577aa6ead517bda589c19b4ca0b2599b'\nyour_switch_bot_secret = '222cdc22f049d111c5d0071c131b8b77'\nswitchbot = SwitchBot(token=your_switch_bot_token, secret=your_switch_bot_secret)\n# To list all devices\ndevices = switchbot.devices()\nfor device in devices:\n print(device)\n# Bot(id=CD0A18B1C291)\n# Lock(id=CD0A1221C291)\n# HubMini(id=4CAF08629A21)\n# Bot(id=5F0B798AEF91)\n\n# If you already know a device id:\ndevice = switchbot.device(id='5F0B798AEF91')\n# Device(id=5F0B798AEF91)\n\n# To query a status of a device\nprint(device.status())\n# {'power': 'off'}\n\n# To command actions,\ndevice.command('turn_on')\ndevice.command('turn_off')\ndevice.command('press')\ndevice.command('set_position', parameter='0,ff,80')\n\n# For some device types like Bot:\nbot = devices[0]\nbot.turn('on')\nbot.turn('off')\nbot.toggle()\nbot.press()\n\n# For some device types like Lock:\nlock = devices[1]\nlock.lock()\nlock.unlock()\nlock.toggle()\n```\n\n### Remotes\n```python\n# To list all infra red remotes\nremotes = switchbot.remotes()\nfor remote in remotes:\n print(remote)\n\n# If you already know a remote id:\nremote = switchbot.remote(id='')\n\n# Supported devices such as fans, air purifiers:\nremote.turn('on')\nremote.turn('off')\n\n# To send supported commands,\nremote.command('swing')\nremote.command('low_speed')\n\n# To send custom commands,\nremote.command('MyCustomCommand', customize=True)\n```\n\n### Scenes\n```python\n# To list all infra red remotes\nscenes = switchbot.scenes()\nfor scene in scenes:\n print(scene)\n\n# If you already know a remote id:\nscene = switchbot.scene(id='')\n\n# To execute scene\nscene.execute()\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python library to control SwitchBot devices connected to SwitchBot Hub.",
"version": "2.3.1",
"project_urls": {
"Homepage": "https://github.com/areazus/python-switchbot-v2"
},
"split_keywords": [
"python-switchbot-v2"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c572a19fbf2f0edc5ed66899ce4c3fe25d82d4864079a619c0d309c98bea30ee",
"md5": "216c592ff15194a053a4240bef346bed",
"sha256": "a16635e7f23bc9d54773ac40af0804b628fa1044250ba4cfc7b94fa145b7fb94"
},
"downloads": -1,
"filename": "python_switchbot_v2-2.3.1.tar.gz",
"has_sig": false,
"md5_digest": "216c592ff15194a053a4240bef346bed",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 5871,
"upload_time": "2024-11-26T15:37:14",
"upload_time_iso_8601": "2024-11-26T15:37:14.067753Z",
"url": "https://files.pythonhosted.org/packages/c5/72/a19fbf2f0edc5ed66899ce4c3fe25d82d4864079a619c0d309c98bea30ee/python_switchbot_v2-2.3.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-26 15:37:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "areazus",
"github_project": "python-switchbot-v2",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "python-switchbot-v2"
}