Core: Xiaomi Miio Vaccum still broken

Created on 11 Feb 2018  ·  70Comments  ·  Source: home-assistant/core

Make sure you are running the latest version of Home Assistant before reporting an issue.

You should only file an issue if you found a bug. Feature and enhancement requests should go in the Feature Requests section of our community forum:

Home Assistant release (hass --version):

0.63.0 from hass.io

Component/platform:

Xiaomi Miio Vaccum

Description of problem:

Error while setup

Expected:

Setup of Vaccum is working

Problem-relevant configuration.yaml entries and steps to reproduce:

vacuum:
- platform: xiaomi_miio
  name: !secret vaccum_name
  host: !secret vaccum_ip
  token: !secret vacuum

Traceback (if applicable):

system_log_event[L]: timestamp=1518346794.2290583, level=ERROR, message=Error while setting up platform xiaomi_miio, exception=Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 84, in async_setup
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/lib/python3.6/asyncio/coroutines.py", line 210, in coro
    res = func(*args, **kw)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/vacuum/xiaomi_miio.py", line 90, in async_setup_platform
    from miio import Vacuum
  File "/usr/lib/python3.6/site-packages/miio/__init__.py", line 2, in <module>
    from miio.protocol import Message, Utils
  File "/usr/lib/python3.6/site-packages/miio/protocol.py", line 179, in <module>
    Const(0x2131, Int16ub),
  File "/usr/lib/python3.6/site-packages/construct/core.py", line 1894, in __init__
    super(Const, self).__init__(subcon)
  File "/usr/lib/python3.6/site-packages/construct/core.py", line 291, in __init__
    raise TypeError("subcon should be a Construct field")
TypeError: subcon should be a Construct field
, source=components/vacuum/xiaomi_miio.py>

Most helpful comment

@tringler Plese remove this folder /etc/homeassistant/deps/lib/python3.5/site-packages/miio and its content.

All 70 comments

Same for me with the pi3 docker image.

Works for me again as Docker image with v0.63 on my Synology NAS

@thorsten Which exact image are you using?

This one: https://hub.docker.com/r/homeassistant/home-assistant/ (I think it's the official one?)

It looks like the required dependencies aren't fulfilled at the docker container. The version of the construct package is too old.

With HA 0.63 we are using python-miio 0.3.5 which enforces construct >= 2.9.23. It looks like construct 2.8.22 is still used. I don't know why.

I just installed home assistant from scratch (https://home-assistant.io/docs/installation/virtualenv/). The xiaomi_miio component works out of the box. It looks like certain docker images are affected.

Same issue here, started out on hass.io v0.62.1 and upgraded to v0.63 and still have this error.

@syssi is there any way to manually upgrade the construct in the docker? Sorry I'm not very familiar with how docker works.

I get another error using that component, not sure if its the same root cause:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity_platform.py", line 197, in _async_add_entity
    yield from entity.async_device_update(warning=False)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/helpers/entity.py", line 324, in async_device_update
    yield from self.hass.async_add_job(self.update)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/vacuum/xiaomi_miio.py", line 368, in update
    state = self._vacuum.status()
  File "/etc/homeassistant/deps/lib/python3.5/site-packages/miio/vacuum.py", line 108, in status
    return VacuumStatus(self.send("get_status")[0])
  File "/etc/homeassistant/deps/lib/python3.5/site-packages/miio/device.py", line 216, in send
    m = Message.build(msg, ctx)
TypeError: build() takes 2 positional arguments but 3 were given

@tringler It's the same root cause. python-miio wasn't updated. :-(

@syssi But I ran sudo pip3 install https://github.com/rytilahti/python-miio and getting the same issue

@tringler Did you switch to your virtualenv beforehand? This verison of pytion-miio must be updated:

/etc/homeassistant/deps/lib/python3.5/site-packages/miio/device.py

It doesn't work if you install python-miio a second time to another location. This command

$ cat /etc/homeassistant/deps/lib/python3.5/site-packages/miio/version.py

must return "0.3.5".

Please checkout this issue #12305, too. It's a duplicate of another xiaomi device using the same library.

@syssi I'm not using a venv at all

@tringler Plese remove this folder /etc/homeassistant/deps/lib/python3.5/site-packages/miio and its content.

Same issue here, started out on 0.62.1 and upgraded to v0.63 and still have this issue

@zamzas at #12305 was able to resolve the issue by removing the contents of /config/deps.

Hi, that folder is already empty.
Should have said that before, sorry.

@TheCrey please describe your setup (docker/hassio/virtualenv, error log incl. paths, install pythion-miio and construct verisons). How much "miio" folders can be found on your system ("find / -name miio") and how much "construct" folders? ("find / -name construct")

Hi,

i am using hassio, so the image on a normal pi3

Supervisor:

Version | 0.88
-- | --
Beta channel | false
Latest available version

Host OS
Hostname hassio
Type resinos
OS GNU/Linux
Host Control version 1.1
Latest available version 1.1

How much "miio" folders can be found on your system ("find / -name miio") and how much "construct" folders? ("find / -name construct")

I am not quite sure how you want me to get this information, so ssh'd into the pi3 and run those commands, booth did not come up with an answer (or any error message)
(sorry that I do no know what to do here)
`
➜ ~ find / -name miio

➜ ~ find / -name construct

➜ ~
`

The Error log is the following:
2018-02-11 17:24:54 ERROR (MainThread) [homeassistant.components.vacuum] Error while setting up platform xiaomi_miio Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 84, in async_setup SLOW_SETUP_MAX_WAIT, loop=hass.loop) File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for return fut.result() File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result raise self._exception File "/usr/lib/python3.6/asyncio/tasks.py", line 180, in _step result = coro.send(None) File "/usr/lib/python3.6/asyncio/coroutines.py", line 210, in coro res = func(*args, **kw) File "/usr/lib/python3.6/site-packages/homeassistant/components/vacuum/xiaomi_miio.py", line 90, in async_setup_platform from miio import Vacuum File "/usr/lib/python3.6/site-packages/miio/__init__.py", line 2, in <module> from miio.protocol import Message, Utils File "/usr/lib/python3.6/site-packages/miio/protocol.py", line 179, in <module> Const(0x2131, Int16ub), File "/usr/lib/python3.6/site-packages/construct/core.py", line 1894, in __init__ super(Const, self).__init__(subcon) File "/usr/lib/python3.6/site-packages/construct/core.py", line 291, in __init__ raise TypeError("subcon should be a Construct field") TypeError: subcon should be a Construct field

I'm having same problem and setup as @TheCrey

Same issue here on hassio 0.63.0.
Not sure how do upgrade/delete those python files as described above on hassio as even through ssh, we don't seem to have access to them (might be missing something though)

@TheCrey SSH into your Raspberry Pi. What's the output of "docker ps" on hassio? Open an interactive shell on your home-assistant container (docker exec -it home-assistant /bin/bash) and try to execute the commands again:

$ docker exec -it home-assistant /bin/bash
$ cat /usr/local/lib/python3.6/site-packages/miio/version.py
# flake8: noqa
__version__ = "0.3.5"
$ cat /usr/local/lib/python3.6/site-packages/construct/version.py
version = (2,9,28)
version_string = "2.9.28"
release_date = "2018.02.08
$
# Check the number of construct installs:
$ find / -name construct
/usr/local/lib/python3.6/site-packages/construct
$
# Check the number of python-miio installs:
$ find / -name miio
/usr/local/lib/python3.6/site-packages/miio 

Hi,

I just ssh into the pi, and all I get is the following:

➜ ~ docker ps
zsh: command not found: docker
➜ ~ docker exec -it home-assistant /bin/bash
zsh: command not found: docker

I am not able to really ssh in the pi, as this is the hassio, where I have to install the ssh add-on to be able to ssh, maybe this is the issue ?
Is there an other way to ssh into the pi ?

Okay... I will try to understand hassio first. :-( :-(

All cool take your time ! If you need anything (and In case I am able to) let me know 👍

Deleting the deps has also for me solved the issue

@TheCrey , @syssi
Looks like that might be how to properly ssh into the hassio container
https://home-assistant.io/developers/hassio/debugging/

@TheCrey Please use this how to: https://home-assistant.io/developers/hassio/debugging/#ssh-access-to-the-host

Will do, but I do not thing it will happen soon today, maybe later :) As this will take a little time

Got the same setup and issue and happy to give stuff a try. Altough as above, I can't seem to run any command when ssh'd in hassio

@gcorgnet Oh... the wording was bad. Please check out and follow this paragraph:

https://home-assistant.io/developers/hassio/debugging/#ssh-access-to-the-host

The document is not about the "SSH add-on". SSH to your raspberry pi later on. Now you will have access to the command line tool called "docker".

For any reason it does not work for me, I am getting the error

[email protected]: Permission denied (publickey).

Maybe someone else can do this and I will wait in the corner und see whats happens.....

@TheCrey you first need to create the SSH keys and put it inside the SD card as it says here https://home-assistant.io/developers/hassio/debugging/#ssh-access-to-the-host

hassio, updated to 0.63 couple of minutes ago - still no vacuum visible :(

log:

_2018-02-11 23:48:41 ERROR (MainThread) [homeassistant.components.vacuum] Error while setting up platform xiaomi_miio
Traceback (most recent call last):_

  • File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 84, in async_setup SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  • File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for return fut.result()
  • File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result raise self._exception
  • File "/usr/lib/python3.6/asyncio/tasks.py", line 180, in _step result = coro.send(None)
  • File "/usr/lib/python3.6/asyncio/coroutines.py", line 210, in coro res = func(args, *kw)
  • File "/usr/lib/python3.6/site-packages/homeassistant/components/vacuum/xiaomi_miio.py", line 90, in async_setup_platform from miio import Vacuum
  • File "/usr/lib/python3.6/site-packages/miio/__init__.py", line 2, in from miio.protocol import Message, Utils
  • File "/usr/lib/python3.6/site-packages/miio/protocol.py", line 179, in Const(0x2131, Int16ub),
  • File "/usr/lib/python3.6/site-packages/construct/core.py", line 1894, in __init__ super(Const, self).__init__(subcon)
  • File "/usr/lib/python3.6/site-packages/construct/core.py", line 291, in __init__ raise TypeError("subcon should be a Construct field")

_TypeError: subcon should be a Construct field_

Would doing a fresh install of hass.io 0.63 fix the issue? or would it still install the old version of the xiaomi mio script?

Still the same problem on fresh xiaomi MiRemote

I have same error with 0.63 as well :(

Do I need to put the SD card in my computer? I can't see how to get the rsa key into the right place. If I put the sd-card in my computer I can't even access anything correctly - it does not end well. I can SSH of Winscp into the pi and it uses my certificate but that doesn't give me access to the docker container.

my /config/deps/ is empty

yeah I put the sd card in my pc and it's not even seeing it

to those on hassio... please try this method... I believe hassio's construct version is outdated
https://github.com/home-assistant/home-assistant/issues/12028

I tried to summarize the issue here: https://github.com/home-assistant/hassio/issues/356

I found the root cause. It's another component (homeassistant.components.sensor.eddystone_temperature) which depends on beacontools which is pinned to construct==2.8.10.

nice... so what can be done for hassio without manually updating construct everytime pi reboots?

I'm trying to convince the author of beacontools to support recent versions of construct for removing the version constraint. As far as the constraint is removed the library won't be downgraded anymore and the hassio issue will disappear. Nevertheless this will need some time. I will think about an alternative hotfix for example a compatibility layer in python-miio which supports multiple versions of construct.

I upgraded HASSIO to 0.63 but it do not works and do not recognize Philips LED Ceiling Lamp

  - platform: xiaomi_miio
    name: Xiaomi Philips LED Ceiling
    host: 192.168.1.34
    token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I receive a lot of errors:

2018-02-12` 19:19:10 ERROR (MainThread) [homeassistant.components.light] Error while setting up platform xiaomi_miio
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 84, in async_setup
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/lib/python3.6/asyncio/coroutines.py", line 210, in coro
    res = func(*args, **kw)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/light/xiaomi_miio.py", line 65, in async_setup_platform
    from miio import Device, DeviceException
  File "/usr/lib/python3.6/site-packages/miio/__init__.py", line 2, in <module>
    from miio.protocol import Message, Utils
  File "/usr/lib/python3.6/site-packages/miio/protocol.py", line 179, in <module>
    Const(0x2131, Int16ub),
  File "/usr/lib/python3.6/site-packages/construct/core.py", line 1894, in __init__
    super(Const, self).__init__(subcon)
  File "/usr/lib/python3.6/site-packages/construct/core.py", line 291, in __init__
    raise TypeError("subcon should be a Construct field")
TypeError: subcon should be a Construct field

None of the Miio devices are being discovered in my HA even with 0.63.2.
Wasn't this supposed to be fixed with updated beacontools?
Do we still have to downgrade to 0.61.1?

having same issue here, I get the Vacuum cleaner displayed on HA but it's "unavailable" so I can't control it

0.63.2 doesn't contain all needed fixes. The dev branch of HA works fine.

@syssi so we need wait to 0.64?

@htcheroportugal What kind of setup do you use (hassio)?

@syssi Yeah I'm on hassio as well...

i'm on the 0.64dev, python-miio from git and construct 2.9.30 and it still does not work

You've a vacuum right? Could you try to change this line of the miio/device.py:

self._device_id = m.header.value.device_id

to

self._device_id = binascii.hexlify(m.header.value.device_id)

https://github.com/rytilahti/python-miio/blob/master/miio/device.py#L245

no I have air purifier 2, where's the file located? i'm using hassbian

This is strange. My air purifier works just fine. Please provide the content of following files:

/srv/homeassistant/lib/python3.4/site-packages/miio/version.py
/srv/homeassistant//lib/python3.4/site-packages/construct/version.py

And the output of your homeassistant.log with debugging enabled:

logger:
  default: warn
  logs:
    miio: debug
    homeassistant.components.fan.xiaomi_miio: debug
2018-02-16 21:39:28 ERROR (Thread-9) [miio.device] Unable to discover a device at address 192.168.31.183
2018-02-16 21:39:28 ERROR (MainThread) [homeassistant.components.fan.xiaomi_miio] Got exception while fetching the state: Unable to discover the device 192.168.31.183
2018-02-16 21:39:59 WARNING (Thread-21) [miio.device] error while reading discover results: _decode() takes 3 positional arguments but 4 were given
2018-02-16 21:39:59 ERROR (Thread-21) [miio.device] Unable to discover a device at address 192.168.31.183
2018-02-16 21:39:59 ERROR (MainThread) [homeassistant.components.fan.xiaomi_miio] Got exception while fetching the state: Unable to discover the device 192.168.31.183
2018-02-16 21:40:30 WARNING (Thread-17) [miio.device] error while reading discover results: _decode() takes 3 positional arguments but 4 were given
2018-02-16 21:40:30 ERROR (Thread-17) [miio.device] Unable to discover a device at address 192.168.31.183
2018-02-16 21:40:30 ERROR (MainThread) [homeassistant.components.fan.xiaomi_miio] Got exception while fetching the state: Unable to discover the device 192.168.31.183
2018-02-16 21:41:01 WARNING (Thread-5) [miio.device] error while reading discover results: _decode() takes 3 positional arguments but 4 were given
2018-02-16 21:41:01 ERROR (Thread-5) [miio.device] Unable to discover a device at address 192.168.31.183
2018-02-16 21:41:01 ERROR (MainThread) [homeassistant.components.fan.xiaomi_miio] Got exception while fetching the state: Unable to discover the device 192.168.31.183

python3.5

pi@hassbian:/srv/homeassistant/lib $ cat /srv/homeassistant/lib/python3.5/site-packages/miio/version.py
__version__ = "0.3.6"

pi@hassbian:/srv/homeassistant/lib $ cat /srv/homeassistant//lib/python3.5/site-packages/construct/version.py
version = (2,9,30)
version_string = "2.9.30"
release_date = "2018.02.13"

also, I don't know if it's connected but my Xiaomi Bedside Lamp stopped working after trying all these upgrades

@yemu The error message is part of another python-miio & construct constellation. Could you check for other installs on your hassbian by

find / -name miio
find / -name construct

yeah,

i messed it completely and now I have it installed three times :)

/home/pi/.local/lib/python3.5/site-packages/miio
/srv/homeassistant/lib/python3.5/site-packages/miio
/usr/local/lib/python3.5/dist-packages/miio

/home/pi/.local/lib/python3.5/site-packages/construct
/srv/homeassistant/lib/python3.5/site-packages/construct
/usr/local/lib/python3.5/dist-packages/construct

could you please tell me which one should I leave, and how to delete not needed ones?

Please login as user "pi":

# removes packages from /home/pi
pip3 uninstall miio
pip3 uninstall construct

# removes packages from  /usr/local
sudo pip3 uninstall miio
sudo pip3 uninstall construct

Ok. Thanks. And how can I downgrade to working version?

Huh? After the uninstall of the wrong versions HA 0.64dev should work. Please reboot HA.

now after deleting the other versions I only have one in /srv/ but it's 0.63.2,
so, how can I upgrade to 0.64dev or downgrade to lower working version?

Stop your homeassistant instance and upgrade:

su - homeassistant
source /srv/homeassistant/bin/activate
pip3 install https://github.com/home-assistant/home-assistant/archive/dev.zip -U

Start homeassistant again. It will fetch python-miio 0.3.6 and construct 2.9.30. The miio components should work now.

thanks! it works!

Maybe not the best place to report this, since I don't know if it's connected issue but...
I'm on 0.64 now and Yeelight Celing lamps still report as "Unknown miio device found", all three of them.

Yeelight Celing lamps still report as "Unknown miio device found", all three of them

All mine working fine and never had issues with lights (I'm on 0.63.3 - 0.64 not available yet)

They work fine if I configure them manually, but discovery throws that error (and adds the entity as unknown), about every 30 mins or so, for all 3 that I have, so it's a bit annoying when you look the log.

This is the full error:

Unknown miio device found: ServiceInfo(type='_miio._udp.local.', name='yeelink-light-ceiling1_mibt77535239._miio._udp.local.', address=b'\xc0\xa8\x01#', port=54321, weight=0, priority=0, server='yeelink-light-ceiling1_mibt77535239.local.', properties={b'epoch': b'1', b'mac': b'7811dca8d7be'})
Was this page helpful?
0 / 5 - 0 ratings