{"id":13593261,"url":"https://github.com/OpenWonderLabs/python-host","last_synced_at":"2025-04-09T02:32:57.626Z","repository":{"id":17720591,"uuid":"82576652","full_name":"OpenWonderLabs/python-host","owner":"OpenWonderLabs","description":"The python code running on Raspberry Pi or other Linux based boards to control SwitchBot.","archived":false,"fork":false,"pushed_at":"2024-05-22T00:18:56.000Z","size":35,"stargazers_count":378,"open_issues_count":18,"forks_count":84,"subscribers_count":26,"default_branch":"master","last_synced_at":"2024-11-06T14:42:19.865Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OpenWonderLabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-20T16:07:04.000Z","updated_at":"2024-11-06T05:34:50.000Z","dependencies_parsed_at":"2024-11-06T14:38:15.722Z","dependency_job_id":null,"html_url":"https://github.com/OpenWonderLabs/python-host","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenWonderLabs%2Fpython-host","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenWonderLabs%2Fpython-host/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenWonderLabs%2Fpython-host/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenWonderLabs%2Fpython-host/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OpenWonderLabs","download_url":"https://codeload.github.com/OpenWonderLabs/python-host/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247965750,"owners_count":21025431,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T16:01:18.496Z","updated_at":"2025-04-09T02:32:52.617Z","avatar_url":"https://github.com/OpenWonderLabs.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# python-host\n\n# What is the SwitchBot opensource project?\n[SwitchBot](https://www.switch-bot.com) is a smart IoT robot to mechanically control all your switches and buttons. You can control the bot by your smartphone app ([iOS](https://itunes.apple.com/app/SwitchBot/id1087374760?mt=8) or  [Android](https://play.google.com/store/apps/details?id=com.theSwitchBot.SwitchBot), SwitchLink, or other platform based on our open APIs.\n\nThis project aims to provide a super light-weight solution to control your SwitchBot on [Raspberry Pi](https://www.raspberrypi.org)/[OpenWRT](https://openwrt.org/) or any other Linux based board.\n\nThe python-host distribution is supported and tested on Python 2.7.\n\n# How to Install?\n\n## On Raspberry Pi\nYou will need:\n  -  A Raspberry Pi 3 or A Raspberry Pi 2 plugged with a [Bluetooth dongle](https://www.amazon.com/Plugable-Bluetooth-Adapter-Raspberry-Compatible/dp/B009ZIILLI/ref=sr_1_3?s=electronics\u0026ie=UTF8\u0026qid=1487679848\u0026sr=1-3\u0026keywords=bluetooth+dongle).\n  -  A SwitchBot.\n  -  An SD Card with a fresh install of Raspbian (tested against the latest build [2017-01-11 Jessie with Pixel](https://www.raspberrypi.org/downloads/raspbian/)).\n\n## Installation\n  1. Boot your fresh Pi and open a command prompt.\n  2. Install the require library.\n```sh\nsudo apt-get update\nsudo apt-get install python-pexpect\nsudo apt-get install libusb-dev libdbus-1-dev libglib2.0-dev \nsudo apt-get install libudev-dev libical-dev libreadline-dev\nsudo pip install bluepy\n```\n  3. Clone this repo to the Pi.\n```sh\ngit clone https://github.com/OpenWonderLabs/python-host.git\ncd python-host\n```\n## Running\n\nYou can use in two ways:\n\n1. Scan and control by device name.\n\n```sh\nsudo python switchbot.py\n```\nFollow the instruction, input the device number for SwitchBot you want to control.\n\n2. Control SwitchBot by MAC address. (MAC address should be retrived in advanced)\n\n```sh\nsudo python switchbot.py [mac_addr action_cmd]\n```\n\naction_cmd :Press, Turn On, Turn Off.\n\n```\neg: sudo python switchbot.py  xx:xx:xx:xx:xx:xx Press\n```\n\n## Python 3 and new bluetooth stack support\n\nThe original `switchbot.py` script will work only on Python 2 and it relies on the old Bluez utils (like `hciconfig` and `hcitool`) that have been deprecated in the latest Bluez releases.\n\nIf you want to use the script on Python 3 or on a Linux distro that no longer ships Bluez with the old tools, use the switchbot_py3.py script instead.\n\nTo install the required dependencies on Debian 11 \"Bullseye\", Raspberry Pi OS or Ubuntu 21.10 or later:\n\n```sh\nsudo apt install python3-bluez\n```\n\nOn older versions of Ubuntu/Debian/Raspbian:\n\n```shell\nsudo apt-get install python3-pip\nsudo apt-get install libbluetooth-dev\npip3 install pybluez\nsudo apt-get install libboost-python-dev\nsudo apt-get install libboost-thread-dev\npip3 install gattlib\n```\n\nIf for some reason the gattlib installation fails:\n\n```sh\nsudo apt-get install pkg-config python3-dev\nsudo apt-get install libglib2.0-dev\n\npip3 download gattlib\ntar xvzf ./gattlib-0.20150805.tar.gz\ncd gattlib-0.20150805/\nsed -ie 's/boost_python-py34/boost_python-py36/' setup.py # \"py36\" might be \"py37\" (for example). Check \"python3 --version\"\npip3 install .\n```\n\nType `python3 switchbot_py3.py -h/--help` for usage tips.\n```\neg: sudo python3 switchbot_py3.py -d xx:xx:xx:xx:xx:xx -c close\n```\n\nEnjoy :)\n\n# References\n\n[SwitchBotAPI-BLE](https://github.com/OpenWonderLabs/SwitchBotAPI-BLE) \n\n- [Bot BLE open api](https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/bot.md)\n\n- [Meter BLE open api](https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/meter.md)\n\n- [Curtain BLE open api](https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/curtain.md)\n\n- [Contact Sensor BLE open api](https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/contactsensor.md)\n\n- [Motion Sensor BLE open api](https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/motionsensor.md)\n\n# Thanks to contributors\n[@BlackLight](https://github.com/BlackLight)\n\n[@rcmdnk](https://github.com/rcmdnk)\n\n[@tony-wallace](https://github.com/tony-wallace)\n\n\n# Community\n\n[SwitchBot (Official website)](https://www.switch-bot.com/)\n\n[Facebook @SwitchBotRobot](https://www.facebook.com/SwitchBotRobot/) \n\n[Twitter @SwitchBot](https://twitter.com/switchbot) \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOpenWonderLabs%2Fpython-host","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FOpenWonderLabs%2Fpython-host","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOpenWonderLabs%2Fpython-host/lists"}