alextud / ha-switchbot-curtain Goto Github PK
View Code? Open in Web Editor NEWControls switchbot curtain using Home Assistant
License: MIT License
Controls switchbot curtain using Home Assistant
License: MIT License
Hello there,
Unfortunately the integration is somehow broken after March 7 2021 - that's the last commit where the curtain's are working (at least for me, running on an NUC, but I've seen plenty of complaints where the integration went offline, bluetooth went offline, etc). I Don't know what changed there and then (I suspect it has something to do with the bluetooth stack.
I just updated the firmware on my switchbot curtains (foolishly), and now the current_position and battery attributes are incorrect. They appear to be swapped.
Last update drops the following error (though the curtain opens and closes):
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 316, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 524, in async_device_update
raise exc
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/switchbot-curtain/cover.py", line 164, in update
self._device.update()
File "/usr/local/lib/python3.8/site-packages/switchbot/init.py", line 189, in update
devices = bluepy.btle.Scanner().scan(scan_timeout)
File "/usr/local/lib/python3.8/site-packages/bluepy/btle.py", line 854, in scan
self.stop()
File "/usr/local/lib/python3.8/site-packages/bluepy/btle.py", line 803, in stop
self._mgmtCmd(self._cmd()+"end")
File "/usr/local/lib/python3.8/site-packages/bluepy/btle.py", line 312, in _mgmtCmd
raise BTLEManagementError("Failed to execute management command '%s'" % (cmd), rsp)
bluepy.btle.BTLEManagementError: Failed to execute management command 'scanend' (code: 11, error: Rejected)
Seeing these issues recently in the logs and it seems like the status cannot be captured; Google Assistant also mentions it cannot communicate although the curtain does work
2021-06-28 22:17:33 ERROR (MainThread) [homeassistant.helpers.entity] Update for cover.curtain fails
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 350, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 558, in async_device_update
raise exc
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/switchbot-curtain/cover.py", line 164, in update
self._device.update()
File "/usr/local/lib/python3.8/site-packages/switchbot/__init__.py", line 189, in update
devices = bluepy.btle.Scanner().scan(scan_timeout)
File "/usr/local/lib/python3.8/site-packages/bluepy/btle.py", line 852, in scan
self.start(passive=passive)
File "/usr/local/lib/python3.8/site-packages/bluepy/btle.py", line 790, in start
self._mgmtCmd("le on")
File "/usr/local/lib/python3.8/site-packages/bluepy/btle.py", line 309, in _mgmtCmd
rsp = self._waitResp('mgmt')
File "/usr/local/lib/python3.8/site-packages/bluepy/btle.py", line 366, in _waitResp
raise BTLEManagementError("Management not available (permissions problem?)", resp)
bluepy.btle.BTLEManagementError: Management not available (permissions problem?)
I’ve noticed the official API has been updated with docs that explain how to gather more curtain state info (https://github.com/OpenWonderLabs/SwitchBotAPI#responses-1), like the state of the curtains. Is that a possibility for this BL component? It currently doesn’t change the state when you or the official app change the curtains.
Home assistant has started putting
No 'version' key in the manifest file for custom integration 'switchbot-curtain'. This will not be allowed in a future version of Home Assistant. Please report this to the maintainer of 'switchbot-curtain'
In the log file. At some point it looks like it's going to stop working!
I updated the switchbot library with curtain support here:
Danielhiversen/pySwitchbot#13
After that is released, you could use the SwitchbotCurtain
directly, without needing all the extra commands and keys in this file.
The cover fails to add to HA due to line 110. I changed locally to below to get it working
return True ##self.current_cover_position <= 0
Hey there, thanks for making this integration!
I've got it working with my blinds showing up in home assistant, and controllable from the dashboard.
However, trying to get them working in a scene, I've found it very finnicky.
They don't show up as a device (not sure if that right there is the issue?) but I can add them as an entity.
I can set the blind positions through the entity listing, but when I trigger the scene, the blinds only actually move maybe 1/10 times.
No idea what could be causing this - anything you'd recommend trying?
Just got 4 switchbot curtains and a hub mini. How do I add this properly? The MAC-addresses of the curtains themselves are BLE (Bluetooth) devices and my HA-setup doesn't have BLE. The hub however has a WiFi MAC-address.
How to properly set this up? The documentation is very very sparse and unclear about this.
Hello, @alextud,
I would like to get permission to use your code in part or whole to update the official HA switchbot integration. I do not want to upset anyone or not credit the people that worked on this.
Thanks,
Jeremy
Hi this is working great so thank you. It would be really usefully to be able to see the battery % in Home Assistant of Switchbot curtains. Is there any way to add this?
I have both manually added the repository and also downloaded using Hacs. The folder switchbot-curtain is now under the custom-components folder.
However, when adding the curtain entry to the configuration.yaml, it is not recognised:
cover:
Value is not accepted. Valid values: "mqtt".yaml-schema: http://schemas.home-assistant.io/configuration(1)
I have restarted Home Assistant so its should have been applied correctly. Certainly looks ok in Hacs
Not sure what I need to do to get this recognised.
Sorry that the code is not formatted correctly above, including the hyphen changing to a bullet point, but the Insert Code option did not appear to format anything so had to stick with unformatted. The format in my yaml is correct, it is just the platform it does not recognise.
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/switchbot-curtain/cover.py", line 41, in setup_platform
add_entities([SwitchBotCurtain(mac_addr, name, password)])
File "/config/custom_components/switchbot-curtain/cover.py", line 56, in init
self._device = switchbot.SwitchbotCurtain(mac=mac, password=password)
AttributeError: module 'switchbot' has no attribute 'SwitchbotCurtain'
config:
cover:
installed the integration via hacs
Any idea what would cause this? Am I missing some dependency?
2021-05-24 21:16:45 ERROR (MainThread) [homeassistant.helpers.entity] Update for cover.switchbot_
curtain fails
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 278, in async_update_ha_sta
te
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 474, in async_device_update
raise exc
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/switchbot-curtain/cover.py", line 164, in update
self._device.update()
File "/usr/local/lib/python3.8/site-packages/switchbot/__init__.py", line 189, in update
devices = bluepy.btle.Scanner().scan(scan_timeout)
File "/usr/local/lib/python3.8/site-packages/bluepy/btle.py", line 852, in scan
self.start(passive=passive)
File "/usr/local/lib/python3.8/site-packages/bluepy/btle.py", line 790, in start
self._mgmtCmd("le on")
File "/usr/local/lib/python3.8/site-packages/bluepy/btle.py", line 312, in _mgmtCmd
raise BTLEManagementError("Failed to execute management command '%s'" % (cmd), rsp)
bluepy.btle.BTLEManagementError: Failed to execute management command 'le on' (code: 17, error: Invalid Index)
Since Home Assistant SwitchBot default implementation in 2021.11 now has PySwitchbot updted to version 0.12, the curtain implementation cannot live side by side, and official SwitchBot implementation doesn't work.
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 446, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 641, in async_device_update
raise exc
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/switchbot-curtain/cover.py", line 164, in update
self._device.update()
File "/usr/local/lib/python3.9/site-packages/switchbot/init.py", line 189, in update
File "/usr/local/lib/python3.9/site-packages/bluepy/btle.py", line 853, in scan
self.process(timeout)
File "/usr/local/lib/python3.9/site-packages/bluepy/btle.py", line 840, in process
isNewData = dev._update(resp)
File "/usr/local/lib/python3.9/site-packages/bluepy/btle.py", line 696, in _update
raise BTLEInternalError("Address type changed during scan, for address %s" % self.addr)
bluepy.btle.BTLEInternalError: Address type changed during scan, for address xx:xx:xx:xx:xx:xx
I downloaded the files and copied them to the config directory but when i try and restart the server i get the error 'Integration 'switchbot-curtain' not found'
can anyone help please?
this is the ha log
Logger: homeassistant.components.websocket_api.http.connection
Source: components/hassio/init.py:562
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 19:24:18 (1 occurrences)
Last logged: 19:24:18
[139692267184864] The system cannot restart because the configuration is not valid: Platform error cover.switchbot-curtain - Integration 'switchbot-curtain' not found.
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 185, in handle_call_service
await hass.services.async_call(
File "/usr/src/homeassistant/homeassistant/core.py", line 1492, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1527, in _execute_service
await handler.job.target(service_call)
File "/usr/src/homeassistant/homeassistant/components/hassio/init.py", line 562, in async_handle_core_service
raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: The system cannot restart because the configuration is not valid: Platform error cover.switchbot-curtain - Integration 'switchbot-curtain' not found.
Since the last update in HACS to 896be86, the control works fine from Home Assistant directly, but not longer from HomeKit. The state is always reported as closed, and when tapping it to open, the loading circle appears and nothing happens.
When reverting back to f31b687, everything works fine again.
Used your code to get Switchbot Curtain working with HA. No problems, thank you 👍 . My question is how do I add a second, separate switchbot curtain controlling a different curtain. I've tried a few things, but my configuration.yaml keeps failing. Any suggestions much appreciated
Hi. Another happy new user here. Thank you for your work to create support for this neat hardware solution in HA. I have run into one minor issue, though...
The integration has started reporting the bot's battery level to be 221% (having previously indicated the same value as the mobile app). The android app shows battery level to be 93%, so I think the hardware is reporting correctly and this seems more likely a software issue. Not a big deal, but will prevent my plan to integrate notifications to warn of low battery.
Hello,
I'm a happy user of this integration. It works just fine right after HA has been started but when the system has been up for a while (I really can’t tell when that starts to happen), the integration fails to trigger my switchbots.
Scenario:
And of course, as soon as restart the integration, it works again.
I'm just wondering if this is something which only happens on an intel NUC and the way it handles bluetooth. I would appreciate it if you could help me troubleshoot my system.
I'm using the Bluetooth tracking integration to track family members presence. Not sure if this could be problematic.
thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.