Xiaomi Chuangmi Wifi Plug v3 goes "Unavailable" after 5 minutes

Hi, syssi
this is what I have in the configuration file:
switch:

  • platform: xiaomi_miio
    devices:
    name: pump
    host: 192.168.1.XX
    token: 1d62493b6a14fac6cf8ddec0ae4006XX
    model: chuangmi.plug.m1

for some reason on the log it says it is trying to connect to this device under old IP adderess (that I corrected in config)

Log Details (ERROR)
Wed Feb 27 2019 15:32:11
Got exception while fetching the state: Unable to discover the device 192.168.1.73

Did you restart HA in the meantime?

I am having this problem with a m1 aswell.

It works, sometimes for a couple of hours, but eventually goes offline.

I even deleted it from the Mi Home app, wondering if there was some kind of login conflict. The mi home app still sees the device when it goes offline in HA.

Restarting the plug fixes the problem, for a while. Should i try to update its firmware? I think its running a pretty old version.

Hey @syssi
Hoping you might also be able to help me too.
Here is an excerpt from my logs, hopefully with everything needed. It just repeats on and on for my v3 ‘enhanced plugs’

Running 0.97.1 but it’s been like this since I installed them a couple of months back

Any help would be greatly appreciated thank you

Linton

Config:

  - platform: xiaomi_miio
    name: Gateway Power
    host: 192.168.1.xx
    token: redacted 
    model: chuangmi.plug.v3
2019-08-12 23:49:53 ERROR (MainThread) [custom_components.smartir.media_player] The device JSON file is invalid
2019-08-12 23:50:00 DEBUG (SyncWorker_8) [miio.protocol] Unable to decrypt, returning raw bytes: b''
2019-08-12 23:50:00 DEBUG (SyncWorker_8) [miio.device] Got a response: Container: 
    data = Container: 
        data = b'' (total 0)
        value = b'' (total 0)
        offset1 = 32
        offset2 = 32
        length = 0
    header = Container: 
        data = b'!1\x00 \x00\x00\x00\x00\x07$H\xa7\x00\x00\nd' (total 16)
        value = Container: 
            length = 32
            unknown = 0
            device_id = b'\x07$H\xa7' (total 4)
            ts = 1970-01-01 00:44:20
        offset1 = 0
        offset2 = 16
        length = 16
    checksum = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' (total 16)
2019-08-12 23:50:00 DEBUG (SyncWorker_13) [miio.protocol] Unable to decrypt, returning raw bytes: b''
2019-08-12 23:50:00 DEBUG (SyncWorker_8) [miio.device] Discovered 072448a7 with ts: 1970-01-01 00:44:20, token: b'00000000000000000000000000000000'
2019-08-12 23:50:00 DEBUG (SyncWorker_13) [miio.device] Got a response: Container: 
    data = Container: 
        data = b'' (total 0)
        value = b'' (total 0)
        offset1 = 32
        offset2 = 32
        length = 0
    header = Container: 
        data = b'!1\x00 \x00\x00\x00\x00\x07$H\xa7\x00\x00\nd' (total 16)
        value = Container: 
            length = 32
            unknown = 0
            device_id = b'\x07$H\xa7' (total 4)
            ts = 1970-01-01 00:44:20
        offset1 = 0
        offset2 = 16
        length = 16
    checksum = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' (total 16)
2019-08-12 23:50:00 DEBUG (SyncWorker_13) [miio.device] Discovered 072448a7 with ts: 1970-01-01 00:44:20, token: b'00000000000000000000000000000000'
2019-08-12 23:50:00 DEBUG (SyncWorker_8) [miio.device] 192.168.1.5:54321 >>: {'id': 1, 'method': 'get_prop', 'params': ['on', 'usb_on', 'temperature', 'wifi_led']}
2019-08-12 23:50:00 DEBUG (SyncWorker_13) [miio.device] 192.168.1.5:54321 >>: {'id': 2, 'method': 'get_prop', 'params': ['on', 'usb_on', 'temperature', 'wifi_led']}
2019-08-12 23:50:01 DEBUG (SyncWorker_13) [miio.device] 192.168.1.5:54321 (ts: 1970-01-01 00:44:20, id: 2) << {'id': 2, 'error': {'code': -30001, 'message': 'Resp invalid json.'}}
2019-08-12 23:50:01 DEBUG (SyncWorker_13) [miio.device] Retrying to send failed command, retries left: 3
2019-08-12 23:50:01 DEBUG (SyncWorker_13) [miio.device] 192.168.1.5:54321 >>: {'id': 3, 'method': 'get_prop', 'params': ['on', 'usb_on', 'temperature', 'wifi_led']}
2019-08-12 23:50:01 DEBUG (SyncWorker_8) [miio.device] 192.168.1.5:54321 (ts: 1970-01-01 00:44:20, id: 1) << {'result': [True, True, 38, 'on'], 'id': 1}
2019-08-12 23:50:01 DEBUG (SyncWorker_8) [miio.device] 192.168.1.5:54321 >>: {'id': 2, 'method': 'get_power', 'params': []}
2019-08-12 23:50:06 DEBUG (SyncWorker_13) [miio.device] Retrying with incremented id, retries left: 2

Hey @g0g0, how did you run this a custom component?

Cheers

@LintHart Let’s try to fix this issue. Can you provide some additional logs? Could you additional provide a screenshot of the switch card? Flips the device between available and unavailable every 5 minutes or is you device unavailable and unusable forever?

Hey @syssi thanks for getting back to me :slight_smile: what kind of additional logs would be helpful apart from the above? My problem it that the switches just constantly become unavailable. They’re not switches I regularly touch so I’m unsure if they’re really not working, I’m just really trying hard to get a stable system at the moment and this is just filling my logs with unfortunate messages.

I’ve recently removed 2/3 plugs to chill things out a bit as I wasn’t using them but for the one that is still active, I’m using a Lovelace entity lock so one one accidentally flick it off.

Lol, and just now, again. So yeah it looks like it definitely cracks it

If you click on the entity (if it’s available). Could you provide a screenshot of the availability chart? More logs: Your previous posted log doesn’t show any malfunction. The periodic (re-)discovery is fine, the hexdump is a bit verbose (but normal, too). The “invalid json exception” is recovered properly by a retry.

I’ll have another poke around the logs. Maybe realistically I just need to remove error logging for these devices if it’s normal enough behaviour. In this screenshot it’s fine for a while and then just in the last couple of hours it goes nuts between available/unavailable every few mins

Could you try to move the lamp (just for testing) next to your accesspoint?

I have a Chuangmi Plug v3, and it has been having similar problem, the Plug would randomly get registered fine in HA one time and gone the next time.

After checking in the Mi Home app, I found that it is getting a different IP address from what I assigned in the Static DHCP at my router. At first I thought there is a rogue DHCP server I forgot to turn off somewhere in my network, so I checked and turns out there is none.

So I checked my router’s dnsmasq log, I discovered that this troll of a plug actually requests DHCP address using two different mac addresses.

In my router, I assigned its mac address 40:31:3c:d6:61:cb to IP address 192.168.8.15
In the Mi Home app it is listed as IP 192.168.8.27

and here is the dnsmasq log

Sep 1 00:09:35 rtac68 daemon.info dnsmasq-dhcp[2121]: DHCPDISCOVER(br0) d6:6e:0e:d6:61:cb
Sep 1 00:09:35 rtac68 daemon.info dnsmasq-dhcp[2121]: DHCPOFFER(br0) 192.168.8.27 d6:6e:0e:d6:61:cb
Sep 1 00:09:36 rtac68 daemon.info dnsmasq-dhcp[2121]: DHCPREQUEST(br0) 192.168.8.27 d6:6e:0e:d6:61:cb
Sep 1 00:09:36 rtac68 daemon.info dnsmasq-dhcp[2121]: DHCPACK(br0) 192.168.8.27 d6:6e:0e:d6:61:cb chuangmi-plug-v3_miio119860300

It shows up as a ‘new’ mac address of d6:6e:0e:d6:61:cb
Checked the oui, that ‘d6:6e:0e’ does not belong to any company.

I restarted the plug, and then I rechecked the dnsmasq log again, it shows this

Sep 1 00:17:55 rtac68 daemon.info dnsmasq-dhcp[2121]: DHCPOFFER(br0) 192.168.8.215 40:31:3c:d6:61:cb
Sep 1 00:17:55 rtac68 daemon.info dnsmasq-dhcp[2121]: DHCPREQUEST(br0) 192.168.8.215 40:31:3c:d6:61:cb
Sep 1 00:17:55 rtac68 daemon.info dnsmasq-dhcp[2121]: DHCPACK(br0) 192.168.8.215 40:31:3c:d6:61:cb Xiaomi
Sep 1 00:17:55 rtac68 daemon.info dnsmasq-dhcp[2121]: DHCPDISCOVER(br0) d6:6e:0e:d6:61:cb
Sep 1 00:17:55 rtac68 daemon.info dnsmasq-dhcp[2121]: DHCPOFFER(br0) 192.168.8.27 d6:6e:0e:d6:61:cb
Sep 1 00:17:55 rtac68 daemon.info dnsmasq-dhcp[2121]: DHCPREQUEST(br0) 192.168.8.215 d6:6e:0e:d6:61:cb
Sep 1 00:17:55 rtac68 daemon.info dnsmasq-dhcp[2121]: DHCPNAK(br0) 192.168.8.215 d6:6e:0e:d6:61:cb address reserved

Hopefully this is relevant to this thread

hi, but may I ask how to do so, kinda new to HA

This definitely helped me!

Adding my old chuangmi.plug.m1 through Xiaomi (miio) integration from UI always finds it regularly but added device never shows up online for some reason, so I assumed it just adds some wrong device or something.
I toggled the advanced (add device manually), entered IP and token manually (got token using Xiaomi cloud tokens extractor) and we are back online baby!

As someone in some other thread said - I’m fairly sure I had it in the past and now it didn’t work, but apparently adding it manually fixes the issue.