Switchbot Curtain

Hi, I installed this commit and a single curtain works fine, open close and stop. But I have a double curtain that opens to the middle (two switchbot curtain bots linked together) opening and closing works fine, but stopping only stops the left curtain. Is there anything to do about this? Also the position is off. Anyone else that has this problem? Any help is appreciated

Sorry, I only use it for opening and closing (never used the stop or positioning) so Iā€™m afraid I canā€™t help you.

This is awesome! Thanks for pointing out RenierM26ā€™s fork.

After removing alextudā€™s repo from HACS, I added this one instead. I added my curtain through the integrations GUI, no editing yaml files. It appears to have scanned for Switch-bot MACs and let me pick the MAC I wanted to add (it only showed one MAC). It also creates all of the entities, so I added battery and light levels in my device card.

I guess I can create an automation to open/close the curtain based on its light level (currently Iā€™m using the ā€œsunā€ device to open at sunrise). I donā€™t know the range of light levels. Currently Iā€™m seeing ā€œ1 Levelā€ up to ā€œ3 Levelā€.

Hello, for two SwitchBot Curtains (and I guess, as many as you have), just add them this way in configuration.yaml:

cover:
  - platform: switchbot-curtain
    mac: XX:XX:XX:XX:XX:XX
  - platform: switchbot-curtain
    mac: YY:YY:YY:YY:YY:YY

So I have ha-switchbot-curtain and the official ā€˜Switchbotā€™ Integration running side by side. All you have to do is update the custom componentā€™s manifest.json to ā€˜0.11.0ā€™ for PySwitchbot.

So after I updated the manifest and restarted, for some reason my cover entity was greyed out at first. Somehow the slider was working, and I tested it ā€“ my curtains closed and the entity arrows went from grey to white.

How do you update the custom component manifest on home assistant OS?

I am getting the following error from home asssistant:

Logger: switchbot
Source: /usr/local/lib/python3.9/site-packages/switchbot/__init__.py:286
First occurred: 23:00:00 (1 occurrences)
Last logged: 23:00:00

Error talking to Switchbot
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/switchbot/__init__.py", line 283, in _sendcommand
    self._connect()
  File "/usr/local/lib/python3.9/site-packages/switchbot/__init__.py", line 232, in _connect
    self._device = bluepy.btle.Peripheral(
  File "/usr/local/lib/python3.9/site-packages/bluepy/btle.py", line 391, in __init__
    self._connect(deviceAddr, addrType, iface)
  File "/usr/local/lib/python3.9/site-packages/bluepy/btle.py", line 439, in _connect
    raise BTLEDisconnectError("Failed to connect to peripheral %s, addr type: %s" % (addr, addrType), rsp)
bluepy.btle.BTLEDisconnectError: Failed to connect to peripheral e9:24:69:9c:e9:6e, addr type: random

How can i fix this?

1 Like

Hello, anybody running Home Assistant Supervised on Debian 11? Iā€™ve had the HACS integration running for months and all of the sudden it has stopped working for some reason. I see items populating the front-end, and they even react to my interactions as if everything was working, but it isnā€™t. I realise there is an official Switchbot integration in HA these days. Could somebody advice on what to do? is there a migration path from the HACS component to the official integration? what are we better off with?

Also, if you would suggest I stich with the HACS component, could somebody provide guidance on troubleshooting my scenario? I really donā€™t know how to enable logging at bluetooth level, to see if my NUC is actually triggering actions.

thanks!

Thanks for pointing this out! Iā€™ve swapped this out for the original one. But for some reason Iā€™m not able to add it using the UI? It doesnā€™t show up. Iā€™m assuming when adding it using the YAML the sensors wonā€™t be added. Do you have any idea what is going wrong here?

I am using the intergration from here and it works great. Only thing Iā€™m noticing is that when I open or close, I get the following error.

Logger: homeassistant.core
Source: components/switchbot/cover.py:110
First occurred: 1:25:34 PM (2 occurrences)
Last logged: 1:25:49 PM

Error executing service: <ServiceCall cover.close_cover (c:01810166c08e3ca8788e8bc0433939eb): entity_id=['cover.middleleft']>
Error executing service: <ServiceCall cover.close_cover (c:01810166d7680c46028830f251c372d8): entity_id=['cover.middleleft']>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1645, in catch_exceptions
    await coro_or_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1664, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 677, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 964, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 714, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/switchbot/cover.py", line 110, in async_close_cover
    await self.hass.async_add_executor_job(self._device.close)
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.9/site-packages/switchbot/__init__.py", line 648, in close
    result = self._sendcommand(CLOSE_KEY, self._retry_count)
  File "/usr/local/lib/python3.9/site-packages/switchbot/__init__.py", line 418, in _sendcommand
    notify_msg = self._readkey()
  File "/usr/local/lib/python3.9/site-packages/switchbot/__init__.py", line 386, in _readkey
    read_result: bytes = char.read()
  File "/usr/local/lib/python3.9/site-packages/bluepy/btle.py", line 197, in read
    return self.peripheral.readCharacteristic(self.valHandle)
  File "/usr/local/lib/python3.9/site-packages/bluepy/btle.py", line 530, in readCharacteristic
    resp = self._getResp('rd')
  File "/usr/local/lib/python3.9/site-packages/bluepy/btle.py", line 407, in _getResp
    resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
  File "/usr/local/lib/python3.9/site-packages/bluepy/btle.py", line 368, in _waitResp
    raise BTLEGattError("Bluetooth command failed", resp)
bluepy.btle.BTLEGattError: Bluetooth command failed (code: 2, error: Attribute can't be read)

It still opens or closes, Iā€™m using switch bot curtain 2.0

I realize I was not actually using the HACS installation, but instead the HA switchbot integration. Is there any reason not to use the HA integration? Anything this integration does better?

Yes, it does not need HACS in the first place which is the biggest advantage.

Good deal. I have removed the HACS integration, and it works, except for the bluetooth error that keeps popping up

There looks to be an open issue for it though, so fingers crossed it getā€™s fixed soon

I have my switchbot curtains connected to my switchbot hub. I followed the integration instructions and both curtain bots are integrated. However, when I want to open or close the curtains, I get the same error:

Bluetooth command failed (code: 2, error: Attribute canā€™t be read)

Is there another way, or do we depend on the abroadst fix in github as mentioned above ?

Kr,

Bart

I dont even use the hub. Intersting, I just assumed it was a bluetooth issue with my NUC, or just bluetooth in general. Is the hub bluetooth?

Yes, the CurtainBots speak Bluetooth only.
I donā€™t use the hub but a nearby ESP32 acting as a Bluetooth/WiFi MQTT bridge with the code from @devWaves, thereā€™s nothing better than that for the curtain bots / switch bots!
See this thread

the hub is indeed bluetooth, connected over WLAN to homeassistant

Hmm,
I saw the issue looked to be resolved for some people, but for me I now cannot control my curtains at all.

I removed the device thinking I would readd it, and get this error

Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/switchbot/config_flow.py", line 89, in async_step_user
    self._discovered_devices = await self._get_switchbots()
  File "/usr/src/homeassistant/homeassistant/components/switchbot/config_flow.py", line 55, in _get_switchbots
    _btle_adv_data = await _btle_connect()
  File "/usr/src/homeassistant/homeassistant/components/switchbot/config_flow.py", line 34, in _btle_connect
    switchbot_devices = await GetSwitchbotDevices().discover()
  File "/usr/local/lib/python3.10/site-packages/switchbot/__init__.py", line 162, in discover
    await devices.start()
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/scanner.py", line 88, in start
    self._bus = await MessageBus(bus_type=BusType.SYSTEM).connect()
  File "/usr/local/lib/python3.10/site-packages/dbus_next/aio/message_bus.py", line 122, in __init__
    super().__init__(bus_address, bus_type, ProxyObject)
  File "/usr/local/lib/python3.10/site-packages/dbus_next/message_bus.py", line 85, in __init__
    self._setup_socket()
  File "/usr/local/lib/python3.10/site-packages/dbus_next/message_bus.py", line 575, in _setup_socket
    raise err
  File "/usr/local/lib/python3.10/site-packages/dbus_next/message_bus.py", line 548, in _setup_socket
    self._sock.connect(filename)
FileNotFoundError: [Errno 2] No such file or directory

Found the solution here

I had to make changes to my docker to give it permissions to dbus so bluetooth could work with bleak.

What exactly did you do. It worked just fine but after upgrading to 2022.7.3 (from 2022.6.7) it stopped. I already put:

cap_add net admin to the docker config. I donā€™t know how to add dbus permissions to the docker.

volumes:
  - /var/run/dbus:/var/run/dbus

I have added this, but donā€™t know if this is what you mean.