syssi / xiaomi_airpurifier

Xiaomi Mi Air Purifier and Xiaomi Mi Air Humidifier integration for Home Assistant
Apache License 2.0
445 stars 109 forks source link

Unable to discover the device #22

Closed Andunes closed 3 years ago

Andunes commented 6 years ago

A couple of versions back my Air Purifier 2 stopped appearing in HASS and I just got these errors:

2018-03-06 18:14:06 ERROR (Thread-12) [miio.device] Unable to discover a device at address 10.0.2.26
2018-03-06 18:14:06 ERROR (MainThread) [homeassistant.components.fan.xiaomi_miio] Got exception while fetching the state: Unable to discover the device 10.0.2.26

I've done a factory reset of the purifier and retrieved the token more then once from my iPhone so it should be correct. I've also got a Mi Vacuum and it works without problems.

Right now I'm on version 0.65.5 and this is my configuration.yaml:

logger:
  default: warn
  logs:
    miio: debug
    homeassistant.components.fan.xiaomi_miio: debug

fan:
  - platform: xiaomi_miio
    name: Mi Purifier
    host: 10.0.2.26
    token: *token*

This is the log when starting HASS with debug enabled (and disabling the vacuum):

2018-03-29 01:05:47 INFO (MainThread) [homeassistant.components.fan.xiaomi_miio] Initializing with host 10.0.2.26 (token c53b5...)
2018-03-29 01:05:52 ERROR (Thread-10) [miio.device] Unable to discover a device at address 10.0.2.26
2018-03-29 01:05:52 ERROR (MainThread) [homeassistant.components.fan.xiaomi_miio] Got exception while fetching the state: Unable to discover the device 10.0.2.26

I've tried looking around but can't seem to figure out what it's not working.

syssi commented 6 years ago

Your token is incorrect. Please try to extract the token again.

Andunes commented 6 years ago

Thanks for the response.

I've tried extracting the token again today from a new iOS backup and I get the same token as before.

I've also tried running "mirobo discover" but it returns errors when the purifier is connected:

(homeassistant) homeassistant@hassbian:/home/pi $ mirobo discover
INFO:miio.discovery:Discovering devices with mDNS, press any key to quit...
INFO:miio.discovery:Found a supported 'Vacuum' at 10.0.2.25 - token: ffffffffffffffffffffffffffffffff
WARNING:miio.discovery:Found unsupported device isa-camera-df3_miio59542966._miio._udp.local. at 10.0.2.35, please report to developers
Exception in thread zeroconf-ServiceBrowser__miio._udp.local.:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/srv/homeassistant/lib/python3.5/site-packages/zeroconf.py", line 1360, in run
    handler(self.zc)
  File "/srv/homeassistant/lib/python3.5/site-packages/zeroconf.py", line 1308, in <lambda>
    state_change=state_change,
  File "/srv/homeassistant/lib/python3.5/site-packages/zeroconf.py", line 1223, in fire
    h(**kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/zeroconf.py", line 1281, in on_change
    listener.add_service(*args)
  File "/srv/homeassistant/lib/python3.5/site-packages/miio/discovery.py", line 112, in add_service
    addr = str(ipaddress.ip_address(info.address))

Anything else I could try? I don't have access to an Android device but I could run an emulator.

syssi commented 6 years ago

Are you able to ping the device? Which version / product do you own in detail?

Andunes commented 6 years ago

Yes, I'm able to ping the device. It's a zhimi.airpurifier.m2, running software version 1.2.9_61.

syssi commented 6 years ago

Are you aware of every miio device has an individual token? You are not allowed to use the vacuum token for your air purifier f.e. Could you provide the output of:

mirobo --token <vacuum-token> --ip 10.0.2.25 -d info
mirobo --token <purifier-token> --ip 10.0.2.26 -d info

I just want to make sure python-miio is working properly in general.

Andunes commented 6 years ago

Yes, I’m aware of the individual tokens.

Output of mirobo --token 48476b... --ip 10.0.2.25 -d info:

INFO:miio.vacuum_cli:Debug mode active
DEBUG:miio.vacuum_cli:Read stored sequence ids: {'seq': 3, 'manual_seq': 0}
DEBUG:miio.vacuum_cli:Connecting to 10.0.2.25 with token 48476b624c326775624932476f5a5244
DEBUG:miio.protocol:Unable to decrypt, returning raw bytes: b''
DEBUG:miio.device:Got a response: Container: 
    data = Container: 
        length = 0
        offset2 = 32
        data = b'' (total 0)
        offset1 = 32
        value = b'' (total 0)
    header = Container: 
        length = 16
        offset2 = 16
        data = b'!1\x00 \x00\x00\x00\x00\x04\xea+\x8f[\x12\x85\x0b' (total 16)
        offset1 = 0
        value = Container: 
            length = 32
            unknown = 0
            device_id = b'\x04\xea+\x8f' (total 4)
            ts = 2018-06-02 11:52:43
    checksum = b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' (total 16)
DEBUG:miio.device:Discovered 04ea2b8f with ts: 2018-06-02 11:52:43, token: b'ffffffffffffffffffffffffffffffff'
DEBUG:miio.device:10.0.2.25:54321 >>: {'method': 'miIO.info', 'params': [], 'id': 4}
DEBUG:miio.device:10.0.2.25:54321 (ts: 2018-06-02 11:52:43, id: 4) << {'result': {'fw_ver': '3.3.9_003194', 'life': 146299, 'ap': {'rssi': -66, 'ssid': 'Carlssons City', 'bssid': 'F0:9F:C2:3D:04:B7'}, 'hw_ver': 'Linux', 'mac': '78:11:DC:E6:F6:4A', 'model': 'rockrobo.vacuum.v1', 'netif': {'gw': '10.0.2.1', 'mask': '255.255.255.0', 'localIp': '10.0.2.25'}, 'token': '48476b624c326775624932476f5a5244'}, 'id': 4, 'partner_id': '', 'code': 0, 'message': 'ok'}
rockrobo.vacuum.v1 v3.3.9_003194 (78:11:DC:E6:F6:4A) @ 10.0.2.25 - token: 48476b624c326775624932476f5a5244
DEBUG:miio.vacuum_cli:Full response: {'ap': {'bssid': 'F0:9F:C2:3D:04:B7', 'rssi': -66, 'ssid': 'Carlssons City'},
 'fw_ver': '3.3.9_003194',
 'hw_ver': 'Linux',
 'life': 146299,
 'mac': '78:11:DC:E6:F6:4A',
 'model': 'rockrobo.vacuum.v1',
 'netif': {'gw': '10.0.2.1', 'localIp': '10.0.2.25', 'mask': '255.255.255.0'},
 'token': '48476b624c326775624932476f5a5244'}
DEBUG:miio.vacuum_cli:Writing {'seq': 4, 'manual_seq': 0} to /home/homeassistant/.cache/python-miio/python-mirobo.seq

Output of mirobo --token c53b5c... --ip 10.0.2.26 -d info:

INFO:miio.vacuum_cli:Debug mode active
DEBUG:miio.vacuum_cli:Read stored sequence ids: {'seq': 4, 'manual_seq': 0}
DEBUG:miio.vacuum_cli:Connecting to 10.0.2.26 with token c53b5cbf79a0e3a3601c664dd1d8bb9a
ERROR:miio.device:Unable to discover a device at address 10.0.2.26
DEBUG:miio.click_common:Exception: Unable to discover the device 10.0.2.26
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/miio/click_common.py", line 47, in __call__
    return self.main(*args, **kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/srv/homeassistant/lib/python3.5/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/srv/homeassistant/lib/python3.5/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/srv/homeassistant/lib/python3.5/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args[1:], **kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/miio/vacuum_cli.py", line 384, in info
    res = vac.info()
  File "/srv/homeassistant/lib/python3.5/site-packages/miio/device.py", line 305, in info
    return DeviceInfo(self.send("miIO.info", []))
  File "/srv/homeassistant/lib/python3.5/site-packages/miio/device.py", line 225, in send
    self.do_discover()
  File "/srv/homeassistant/lib/python3.5/site-packages/miio/device.py", line 163, in do_discover
    raise DeviceException("Unable to discover the device %s" % self.ip)
miio.device.DeviceException: Unable to discover the device 10.0.2.26
Error: Unable to discover the device 10.0.2.26

I can still ping the purifier, and it works with the app:

PING 10.0.2.26 (10.0.2.26) 56(84) bytes of data.
64 bytes from 10.0.2.26: icmp_seq=1 ttl=254 time=3.43 ms
64 bytes from 10.0.2.26: icmp_seq=2 ttl=254 time=7.16 ms
64 bytes from 10.0.2.26: icmp_seq=3 ttl=254 time=4.11 ms
64 bytes from 10.0.2.26: icmp_seq=4 ttl=254 time=3.26 ms

c6031c06-b1da-452c-aefe-8669ec34699d

syssi commented 6 years ago

I'm clueless. I would factory reset the device as next step.

Andunes commented 6 years ago

So I just factory reset the device (and updated it to 1.2.9_64), extracted a new token, and got the exact same errors...

I might try to setup miio on somthing else and see if the problem is with the RPi.

domibarton commented 5 years ago

I've the same issue over here, even after factory reset and new tokens. Any updates on this?
The RoboRock works without any problems, it's just the Humidifiers which won't work (v1 and ca1).

kronna commented 5 years ago

I am also unable to get a token out of my Air Purifier 2S running version 1.4.3_21104 firmware.

I try with miio:

 INFO  Discovering devices. Press Ctrl+C to stop.

Device ID: 81008550
Model info: Unknown
Address: 192.168.0.184
Token: ???
Support: Unknown

I try adb, su and use this command:

echo "select name,localIP,token from devicerecord;" | sqlite3 /data/data/com.xiaomi.smarthome/databases/miio2.db

I get only:

Mi Air Purifier 2S|192.168.0.184|

no token :cry: :cry: :cry:

UPDATE:

Tried also mirobo no luck:


INFO:miio.discovery:Discovering devices with mDNS, press any key to quit...
INFO:miio.discovery:Found a supported 'AirPurifier' at 192.168.0.184 - token: 00000000000000000000000000000000
syssi commented 5 years ago

Please downgrade your MiHome app: https://python-miio.readthedocs.io/en/latest/discovery.html#tokens-from-mi-home-logs

kronna commented 5 years ago

Thanks installing mihome 5.4.49 and re-adding the device worked!

syssi commented 5 years ago

@Andunes Could you try to update your unifi ap firmware? cp. https://github.com/home-assistant/home-assistant/issues/20452#issuecomment-469010542

monotonus commented 5 years ago

Is there a solution meanwhile? I've also got these error messages and my graph is looking like this:

grafik

Therefore I have to make a workaround for my automations because the states are interrupted all the time and a simple state trigger "on for 15 minutes" will not work anymore. And maybe because of that my CPU usage also is higher than usual.

I'm running 0.96.4 right now.

PS: the mirobo command is not available on my Pi.

monotonus commented 5 years ago

Update: I had the suspicion that it could be a wifi problem and moved the purifier closer to my accesspoint. This worked. But after moving back to the old position it's also working again. So it seems it was enough to remove the current from the device in my case.