Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switchbot new Integration Aborted Unexpected error message when trying to set it up #57250

Closed
andremain opened this issue Oct 7, 2021 · 25 comments · Fixed by #57367
Closed

Comments

@andremain
Copy link

The problem

I have tried a lot of things but nothing worked and the logs don't get me anywhere.. Here they are:

Unexpected exception
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/switchbot/config_flow.py", line 96, in async_step_user
self._discovered_devices = await self._get_switchbots()
File "/usr/src/homeassistant/homeassistant/components/switchbot/config_flow.py", line 62, in _get_switchbots
_btle_adv_data = await self.hass.async_add_executor_job(_btle_connect)
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/switchbot/config_flow.py", line 36, in _btle_connect
switchbot_devices = GetSwitchbotDevices().discover()
File "/usr/local/lib/python3.9/site-packages/switchbot/init.py", line 138, in discover
_model = binascii.unhexlify(value[4:6]).decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 0: unexpected end of data

Please help

What is version of Home Assistant Core has the issue?

core-2021.10.0

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Switchbot

Link to integration documentation on our website

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

@chreestopher
Copy link

I’m getting the same.

some additional details:

I already was using SwitchBot via manual yaml config without issues prior to this upgrade.

I have tried upgrading with the SwitchBot entities already defined in configuration.yaml and I have tried removing the SwitchBot entries from config and then upgrading.

in both scenarios the new SwitchBot ui element shows up under integrations with the same error reported in this issue for both of my SwitchBot devices.

I’m using two SwitchBot button pressers, if the device type matters. Both devices are using SwitchBot 4.9 firmware.

@andremain
Copy link
Author

I already was using SwitchBot via manual yaml config without issues prior to this upgrade.

I have tried upgrading with the SwitchBot entities already defined in configuration.yaml and I have tried removing the SwitchBot entries from config and then upgrading.

Same goes for me. Now i get the error no matter what .

@chreestopher
Copy link

Out of curiosity, if you don’t mind sharing, are you also using the button pressers or are you having issues with a different SwitchBot device type?

@andremain
Copy link
Author

Out of curiosity, if you don’t mind sharing, are you also using the button pressers or are you having issues with a different SwitchBot device type?

Nope just button pressers. I haven't found a way to add my humidifier yet. Lets hope someone will answer for our issue..

@rktr2009
Copy link

rktr2009 commented Oct 7, 2021

Same for me with a unexpected exception error.
This is for the two switchbot button pressers I have.
[Edit] I forgot that I had a switchbot meter (to detect temperature and humidity) as well.
Removed the configs in configuration.yaml and the log for me with the UI was:

Unexpected exception
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/switchbot/config_flow.py", line 96, in async_step_user
self._discovered_devices = await self._get_switchbots()
File "/usr/src/homeassistant/homeassistant/components/switchbot/config_flow.py", line 62, in _get_switchbots
_btle_adv_data = await self.hass.async_add_executor_job(_btle_connect)
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/switchbot/config_flow.py", line 36, in _btle_connect
switchbot_devices = GetSwitchbotDevices().discover()
File "/usr/local/lib/python3.9/site-packages/switchbot/init.py", line 156, in discover
] = _process_wosensorth(value[4:])
File "/usr/local/lib/python3.9/site-packages/switchbot/init.py", line 86, in _process_wosensorth
_wosensorth_data["temp"]["c"] = _temp_c
KeyError: 'temp'

@andremain
Copy link
Author

@RenierM26 any chance you could help us out?

@bbostock
Copy link

bbostock commented Oct 7, 2021

I am also getting an error following this upgrade:
I have tried with and without pre-configured switches. Should it work in either case?

021-10-07 15:46:07 ERROR (MainThread) [homeassistant.components.switchbot.coordinator] Unexpected error fetching switchbot data: 'temp'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 187, in _async_refresh
self.data = await self._async_update_data()
File "/usr/src/homeassistant/homeassistant/components/switchbot/coordinator.py", line 54, in _async_update_data
switchbot_data = await self.hass.async_add_executor_job(self._update_data)
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/switchbot/coordinator.py", line 46, in _update_data
return self.switchbot_api.GetSwitchbotDevices().discover(
File "/usr/local/lib/python3.9/site-packages/switchbot/init.py", line 156, in discover
] = _process_wosensorth(value[4:])
File "/usr/local/lib/python3.9/site-packages/switchbot/init.py", line 86, in _process_wosensorth
_wosensorth_data["temp"]["c"] = _temp_c
KeyError: 'temp'

@ideris01
Copy link

ideris01 commented Oct 8, 2021

switchbot broke for me as well; first with a permission denied error which I tracked down to needing to setcap… but then I got this:

hass[45721]:   File “/opt/homeassistant/lib64/python3.9/site-packages/homeassistant/components/switchbot/coordinator.py”, line 46, in _update_data

hass[45721]:     return self.switchbot_api.GetSwitchbotDevices().discover(

hass[45721]:   File “/opt/homeassistant/lib64/python3.9/site-packages/switchbot/__init__.py”, line 138, in discover

hass[45721]:     _model = binascii.unhexlify(value[4:6]).decode()

hass[45721]: UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xc8 in position 0: unexpected end of data

I just have the “switchbot bot”s and they’re password protected (both MAC and password defined in config file)

@probot-home-assistant
Copy link

Hey there @Danielhiversen, @RenierM26, mind taking a look at this issue as it has been labeled with an integration (switchbot) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)


switchbot documentation
switchbot source
(message by IssueLinks)

@ioannispelelis
Copy link

Same issue while trying to integrate switchbot.
FYI i had never tried switchbot integration in the past (via the yaml nor via the integration menu)

@vwt12eh8
Copy link

vwt12eh8 commented Oct 8, 2021

It seems that an error occurs when a password is set.
After deleting all the passwords in the surrounding area, we were able to work together.

However, using it without a password is a risk.

@bbostock
Copy link

bbostock commented Oct 8, 2021

I'm afraid I really don't understand what you mean. A password is set where? And what is "the surrounding area".

@andremain
Copy link
Author

I'm afraid I really don't understand what you mean. A password is set where? And what is "the surrounding area".

I believe he means the Switchbot app, inside the bot settings. You need to have physical access to the device though.

@bbostock
Copy link

bbostock commented Oct 8, 2021

Thanks, but definitely no passwords used in my switchbot setup for any devices.

@rktr2009
Copy link

rktr2009 commented Oct 8, 2021

So I have 2 switchbot pressers, and I tried to add the switchbot integration many times and finally got 2 of those added.
Most of the time I was getting "unexpected error".
Sometimes I get "no unconfigured devices found", which is obviously not, since I don't have both pressers added.

But even with the configured presser, it will switch on, but the status will turn to "off" immediately, so there is a consistency mismatch on the status.
I am finding the integration is unstable, where I see, "Retrying setup: 'temp'" many times and "Retrying setup: Device disconnected" a lot.

By the way, I have no password set on the device.

@joe-sydney
Copy link

Same here, switchbot broke for me when upgrading to 2021.10. First I got the Permission error which needed the setcap, and now the "can't decode byte" error, both described earlier.

It had been working for a very long time previously (with passwords).

@smbm
Copy link

smbm commented Oct 8, 2021

Also broken here, has been working for months configured via yaml with password. Now getting the "can't decode byte" error. Have tried commenting the yaml and using the integration directly, adding and removing the integration, I always end up with the same error no matter what I do.

@avbfr
Copy link

avbfr commented Oct 9, 2021

+1
Same issue here.

@RenierM26
Copy link
Contributor

Hi All,

I found the issue and have opened a pull request on the switchbot api github repository.

Basically there are two issues:

  1. If you have a Switchbot Meter then a key error occurs.
  2. If a password is set, the binary value used for the model number starts with a "1" instead of a "0". This results in a different hex value, which then results in a decode error.

Thank you for the feedback and stack traces.

@RenierM26
Copy link
Contributor

So I have 2 switchbot pressers, and I tried to add the switchbot integration many times and finally got 2 of those added. Most of the time I was getting "unexpected error". Sometimes I get "no unconfigured devices found", which is obviously not, since I don't have both pressers added.

But even with the configured presser, it will switch on, but the status will turn to "off" immediately, so there is a consistency mismatch on the status. I am finding the integration is unstable, where I see, "Retrying setup: 'temp'" many times and "Retrying setup: Device disconnected" a lot.

By the way, I have no password set on the device.

This is most likely caused by low signal strength. You could try bringing the SB device closer to your hassio server for setup.

@RenierM26
Copy link
Contributor

Once the device is added, you can play around with the entry options to increase the scan interval and retry timeouts. These options will help with devices with weak signal.

@joe-sydney
Copy link

Hi All,

I found the issue and have opened a pull request on the switchbot api github repository.

Basically there are two issues:

  1. If you have a Switchbot Meter then a key error occurs.
  2. If a password is set, the binary value used for the model number starts with a "1" instead of a "0". This results in a different hex value, which then results in a decode error.

Thank you for the feedback and stack traces.

Hi @RenierM26, Could you please share the link to the repository so I can find the PR?

@RenierM26 RenierM26 mentioned this issue Oct 9, 2021
22 tasks
@RenierM26
Copy link
Contributor

RenierM26 commented Oct 9, 2021

Hi All,

The dependency (api) changes have been merged and I have opened a hass pull request to bump the dependency.

Kudos to Danielhiversen for the help with this issue!

#57367

@joe-sydney
Copy link

OK, thanks. Will wait for it to make its way into a HA release.

@rktr2009
Copy link

rktr2009 commented Oct 9, 2021

Once the device is added, you can play around with the entry options to increase the scan interval and retry timeouts. These options will help with devices with weak signal.

Thanks for your suggestion. However, for the switchbot integration before 2021.10, I had zero issue and no signs for weak signal. Haven't changed the switchbot location at all after I installed 2021.10. I will try for the updated one mentioned above after it is released.
For now I went back to 2021.09, and it is all working good.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.