Easy way to make your dumb devices smart!
here is a python lib for it: https://github.com/OpenWonderLabs/python-host/blob/master/switchbot.py
Waiting for this
Edit: no longer needed. Use the native component.
I made a custom component myself actually. It only takes one (1) switchbot for now. Going to try to extend. Here you go: https://github.com/isabellaalstrom/HomeAssistantConfiguration/blob/master/custom_components/switch/switchbot.py
First thanks to @teachingbirds. I had some trouble getting it to work in hass.io and I just want to add my take.
You need the switch-bot mac adress. I unfortunately had to:
- Clone hassio sd-card with disk utility
- Follow instructions on https://github.com/OpenWonderLabs/python-host
- Write down mac
- Restore hassio sd-card with etcher
Get teachingbirds component
- switchbot.py
- Place in: custom_components/switch/switchbot.py
configuration.yaml
switch:
- platform: switchbot
name: 'Switch-bot iMac'
mac: 'xx:xx:xx:xx:xx:xx'
Activate Bluetooth BCM43xx in add-on store.
When I tested it out it only worked about half the time, I got a lot of connection errors in my log. In switchbot_bluepy-py thereâs a line thats missing from from teachingbirds switchbot.py component. After hand.write thereâs p.disconnect(). Iâm no programmer but I suspect that itâs needed to not cause timeout issues. It worked for me.
Also Iâm using my switch-bot to turn on my computer so I had to change the âlight-switchâ to âpressâ. To do this you change the hand.write to 570100.
Then I control it with this script:
switchbot:
sequence:
- condition: state
entity_id: switch.imac_wol
state: 'off'
- service: switch.toggle
entity_id: switch.switchbot_imac
Awesome! I will update my component with the missing line. Happy that it works for you now though!
What a bunch of legends you people are for writing the code for this. I have ordered by switchbot and I will test this out and report back. Guessing that by using this I will not need to use a switchbot gateway device.
Exactly, no gateway needed! I have yet to fix that you can have more than one bot though, so much to do and so little time
Good news is I only own a single SwitchBot.
I have two, so I will be getting around to it sooner or later But for now the other oneâs waiting for something to use it withâŠ
Well my SwitchBot arrived today and must say that I am very impressed with the little switch. I think I will order some more so when you have time please update the app.
One great big thanks from me for creating this code, without people like you home assistant would be a cold lonely place.
I agree! It feels good to contribute in some small way. I could maybe take the time to try to update this weekend.
I would appreciate that tooâŠ
Platform not found: switch.switchbot in check config
in the root of my config folder (i.e. where configuration.yaml lives) I have added the following structure
/custom_components/switch/switchbot.py and copied GitHub to page to it
My configuration.yaml looks like this
switch:
- platform: switchbot
name: 'heater'
mac: 'F1:B1:B9:89:4D:B0'
Point to note home assistant made this folder
/custom_components/switch/pycache/switchbot.cpython-36.pyc
What could I be doing wrong?
do I need to edit the switchbot.py with my details or do I just copy as is the github page?
ââ" keyâs expected from user configuration"ââ
CONF_NAME = ânameâ
CONF_MAC = âmacâ
Anyone? Got any bright ideas on why I get.
Platform not found: switch.switchbot in check config
Got this in my home assist logs, see the bit about
ModuleNotFoundError: No module named bluepy
I believe it has something to do with my docker build and bluepy, I will try rebuilding on a raspberry pi and testing.
2018-04-16 10:17:25 ERROR (MainThread) [homeassistant.loader] Error loading custom_components.switch.switchbot. Make sure all dependencies are installed
Traceback (most recent call last):
File "/usr/src/app/homeassistant/loader.py", line 142, in get_component
module = importlib.import_module(path)
File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/config/custom_components/switch/switchbot.py", line 22, in <module>
from bluepy.btle import Peripheral
ModuleNotFoundError: No module named 'bluepy'
2018-04-16 10:17:25 ERROR (MainThread) [homeassistant.loader] Unable to find component switch.switchbot
2018-04-16 10:20:42 ERROR (SyncWorker_8) [homeassistant.loader] Error loading custom_components.switch.switchbot. Make sure all dependencies are installed
Traceback (most recent call last):
File "/usr/src/app/homeassistant/loader.py", line 142, in get_component
module = importlib.import_module(path)
File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/config/custom_components/switch/switchbot.py", line 22, in <module>
from bluepy.btle import Peripheral
ModuleNotFoundError: No module named bluepy
2018-04-16 10:20:42 ERROR (SyncWorker_8) [homeassistant.loader] Unable to find component switch.switchbot
for what it is worth, I had to run this from SSH
pip install bluepy
To confirm I now have this fully working, thanks everyone.
Hoping you can help me through a hassio installation.
Here is what Iâve done:
-obtained the MAC address from the switchbot app
-copied it into configuration.yaml
- platform: switchbot
name: âSwitch-bot Coffeeâ
mac: âFE:FC:60:31:D0:6Câ
-copied switchbot.py file into /custom_components/switch/switchboy.py
Only notice i get is:
Setup failed for switchbot: Component not found.
1:24 PM setup.py (ERROR)
Unable to find component switchbot
1:24 PM loader.py (ERROR)
Any ideas on what step I missed?
Have you installed Bluetooth BCM43xx in the add-on store? I donât think bluetooth was activated on my pi until I did that.
Yeah, it is activated. I should have said that.