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

It’s the new plug with 2 USB ports, model: ZNCZ03CM

When HA start it’s working great, shows all data, but after 5 minutes goes “Unavailable” until next HA restart, and same again work 5 minutes and “Unavailable”, in MiHome app it works all the time

13123123

configuration.yaml:

switch:
  - platform: xiaomi_miio
    host: 10.0.0.1
    token: abcabcabcabcabcabcabcabc
    model: chuangmi.plug.v3

also tried without “model” line, same result

any experience with this model?

I am seeing the same thing, everything good for 5 minutes then “unavailable”. I can see in the logs

Got exception while fetching the state: {'code': -30001, 'message': 'Resp invalid json.'} components/switch/xiaomi_miio.py (ERROR)

Restarting hass seems to restart the 5 good minutes followed by unavailabile.

Please enable the debug output of the component:

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

And provide the content of your home-assistant.log. If it’s a bug it will contain the cause.

@syssi Thanks for looking

Here is home-assistant.log:

https://gist.github.com/HatHost/1c50d4e73956236812ae376f74a08c3a#file-home-assistant-log

With logs I see even first 5 minutes it shows errors but still get correct values (800 is actually 8W but it is corerct) and can control it but after 5 minutes it makes another error without values and control

Here are the logs, it looks like the parameter ‘load_power’ is added each time a request is made rather than being in the param list once.

The successful calls are:
2018-05-28 17:11:40 DEBUG (SyncWorker_12) [miio.device] 192.168.0.180:54321 >>: {'id': 1, 'method': 'get_prop', 'params': ['on', 'usb_on', 'temperature', 'wifi_led', 'load_power']} 2018-05-28 17:11:40 DEBUG (SyncWorker_1) [miio.protocol] Unable to decrypt, returning raw bytes: b'' 2018-05-28 17:11:40 DEBUG (SyncWorker_1) [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\x04A\xbc\xcc\x00\x01p\xb7' (total 16) value = Container: length = 32 unknown = 0 device_id = b'\x04A\xbc\xcc' (total 4) ts = 1970-01-02 02:13:11 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) 2018-05-28 17:11:40 DEBUG (SyncWorker_1) [miio.device] Discovered 0441bccc with ts: 1970-01-02 02:13:11, token: b'00000000000000000000000000000000' 2018-05-28 17:11:40 DEBUG (SyncWorker_1) [miio.device] 192.168.0.180:54321 >>: {'id': 2, 'method': 'get_prop', 'params': ['on', 'usb_on', 'temperature', 'wifi_led', 'load_power']} 2018-05-28 17:11:40 DEBUG (SyncWorker_12) [miio.device] 192.168.0.180:54321 (ts: 1970-01-02 02:13:11, id: 1) << {'result': [True, True, 42, 'on', None], 'id': 1} 2018-05-28 17:11:40 DEBUG (SyncWorker_12) [miio.device] 192.168.0.180:54321 >>: {'id': 2, 'method': 'get_power', 'params': []} 2018-05-28 17:11:40 DEBUG (SyncWorker_1) [miio.device] 192.168.0.180:54321 (ts: 1970-01-02 02:13:12, id: 2) << {'result': [True, True, 42, 'on', None], 'id': 2} 2018-05-28 17:11:40 DEBUG (SyncWorker_1) [miio.device] 192.168.0.180:54321 >>: {'id': 3, 'method': 'get_power', 'params': []} 2018-05-28 17:11:40 DEBUG (SyncWorker_1) [miio.device] 192.168.0.180:54321 (ts: 1970-01-02 02:13:12, id: 3) << {'result': [4900], 'id': 3} 2018-05-28 17:11:44 DEBUG (SyncWorker_7) [miio.device] Retrying with incremented id, retries left: 3 2018-05-28 17:11:44 DEBUG (SyncWorker_7) [miio.protocol] Unable to decrypt, returning raw bytes: b'' 2018-05-28 17:11:44 DEBUG (SyncWorker_7) [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\x04?\xf8X\x00\x01kG' (total 16) value = Container: length = 32 unknown = 0 device_id = b'\x04?\xf8X' (total 4) ts = 1970-01-02 01:49:59 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) 2018-05-28 17:11:44 DEBUG (SyncWorker_7) [miio.device] Discovered 043ff858 with ts: 1970-01-02 01:49:59, token: b'00000000000000000000000000000000' 2018-05-28 17:11:44 DEBUG (SyncWorker_7) [miio.device] 192.168.0.181:54321 >>: {'id': 104, 'method': 'get_power', 'params': []} 2018-05-28 17:11:44 DEBUG (SyncWorker_7) [miio.device] 192.168.0.181:54321 (ts: 1970-01-02 01:49:59, id: 104) << {'result': [600], 'id': 104} 2018-05-28 17:11:45 DEBUG (SyncWorker_12) [miio.device] Retrying with incremented id, retries left: 3 2018-05-28 17:11:45 DEBUG (SyncWorker_12) [miio.protocol] Unable to decrypt, returning raw bytes: b'' 2018-05-28 17:11:45 DEBUG (SyncWorker_12) [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\x04A\xbc\xcc\x00\x01p\xbd' (total 16) value = Container: length = 32 unknown = 0 device_id = b'\x04A\xbc\xcc' (total 4) ts = 1970-01-02 02:13:17 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) 2018-05-28 17:11:45 DEBUG (SyncWorker_12) [miio.device] Discovered 0441bccc with ts: 1970-01-02 02:13:17, token: b'00000000000000000000000000000000' 2018-05-28 17:11:45 DEBUG (SyncWorker_12) [miio.device] 192.168.0.180:54321 >>: {'id': 104, 'method': 'get_power', 'params': []} 2018-05-28 17:11:45 DEBUG (SyncWorker_12) [miio.device] 192.168.0.180:54321 (ts: 1970-01-02 02:13:17, id: 104) << {'result': [4900], 'id': 104} 2018-05-28 17:11:50 DEBUG (MainThread) [homeassistant.components.switch.xiaomi_miio] Got new state: <ChuangmiPlugStatus power=True, usb_power=True, temperature=42load_power=4900, wifi_led=True> 2018-05-28 17:11:50 DEBUG (MainThread) [homeassistant.components.switch.xiaomi_miio] Got new state: <ChuangmiPlugStatus power=True, usb_power=False, temperature=38load_power=600, wifi_led=True> 2018-05-28 17:11:50 DEBUG (MainThread) [homeassistant.components.switch.xiaomi_miio] Got new state: <ChuangmiPlugStatus power=True, usb_power=True, temperature=42load_power=4900, wifi_led=True>

and when it fails, the calls become:

2018-05-28 17:14:37 DEBUG (SyncWorker_7) [miio.device] 192.168.0.180:54321 >>: {'id': 421, 'method': 'get_prop', 'params': ['on', 'usb_on', 'temperature', 'wifi_led', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power']} 2018-05-28 17:14:37 DEBUG (SyncWorker_14) [miio.device] 192.168.0.181:54321 >>: {'id': 521, 'method': 'get_prop', 'params': ['on', 'usb_on', 'temperature', 'wifi_led', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power']} 2018-05-28 17:14:37 DEBUG (SyncWorker_13) [miio.device] 192.168.0.181:54321 >>: {'id': 522, 'method': 'get_prop', 'params': ['on', 'usb_on', 'temperature', 'wifi_led', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power']} 2018-05-28 17:14:37 DEBUG (SyncWorker_8) [miio.device] 192.168.0.180:54321 >>: {'id': 422, 'method': 'get_prop', 'params': ['on', 'usb_on', 'temperature', 'wifi_led', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power', 'load_power']} 2018-05-28 17:14:38 DEBUG (SyncWorker_8) [miio.device] 192.168.0.180:54321 (ts: 1970-01-02 02:16:09, id: 422) << {'id': 422, 'error': {'code': -30001, 'message': 'Resp invalid json.'}} 2018-05-28 17:14:38 DEBUG (SyncWorker_14) [miio.device] 192.168.0.181:54321 (ts: 1970-01-02 01:52:53, id: 521) << {'id': 521, 'error': {'code': -30001, 'message': 'Resp invalid json.'}} 2018-05-28 17:14:38 DEBUG (SyncWorker_13) [miio.device] 192.168.0.181:54321 (ts: 1970-01-02 01:52:53, id: 522) << {'id': 522, 'error': {'code': -30001, 'message': 'Resp invalid json.'}} 2018-05-28 17:14:38 DEBUG (SyncWorker_7) [miio.device] 192.168.0.180:54321 (ts: 1970-01-02 02:16:09, id: 421) << {'id': 421, 'error': {'code': -30001, 'message': 'Resp invalid json.'}} 2018-05-28 17:14:38 ERROR (MainThread) [homeassistant.components.switch.xiaomi_miio] Got exception while fetching the state: {'code': -30001, 'message': 'Resp invalid json.'} 2018-05-28 17:14:38 ERROR (MainThread) [homeassistant.components.switch.xiaomi_miio] Got exception while fetching the state: {'code': -30001, 'message': 'Resp invalid json.'} 2018-05-28 17:14:38 ERROR (MainThread) [homeassistant.components.switch.xiaomi_miio] Got exception while fetching the state: {'code': -30001, 'message': 'Resp invalid json.'} 2018-05-28 17:14:38 ERROR (MainThread) [homeassistant.components.switch.xiaomi_miio] Got exception while fetching the state: {'code': -30001, 'message': 'Resp invalid json.'} 2

Ups! This can be easily fixed. I will care about!

2 Likes

This fix should solve the issue: https://github.com/rytilahti/python-miio/pull/330/files

It will be part of python-miio 0.4.0.

2 Likes

Thanks @syssi its fixed, tested as custom component it is not disconnecting now

Thanks again, @syssi. I can confirm that after applying your fix it works, but some remarks about the component:

  • load_power attribute seems to return wrong values. If it measures watts, it should be divided by 100 I think. At first glance I thought it was milliamperes.
  • In addition the attribute is added to both “switches”, the main switch and the USB switch; but apparently both attributes are the same at the protocol level. I think it should be added just to the main switch.
  • Finally, if I specify the model at the switch configuration (chuangmi.plug.v3), the component is never initialized. If I don’t specify it, it is correctly discovered and works OK.
1 Like

Thanks for your feedback. I will care about the issues!

1 Like

Could you test this point one more time? Could you enable the debug log of the component and provide some details?

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

I addressed the above issues by

and

1 Like

These are some excerpts from my log. I’m sorry but I don’t know what to filter out, I have many Xiaomi devices…

2018-06-16 19:56:05 INFO (MainThread) [homeassistant.components.switch.xiaomi_miio] Initializing with host 192.168.1.76 (token 137b3…)
2018-06-16 19:56:05 DEBUG (Thread-5) [miio.protocol] Unable to decrypt, returning raw bytes: b’’
2018-06-16 19:56:05 DEBUG (Thread-5) [miio.device] Got a response: Container:
data = Container:
value = b’’ (total 0)
data = b’’ (total 0)
length = 0
offset2 = 32
offset1 = 32
header = Container:
value = Container:
length = 32
unknown = 0
device_id = b’\x04@\xed\xe3’ (total 4)
ts = 1970-01-02 02:33:13
data = b’!1\x00 \x00\x00\x00\x00\x04@\xed\xe3\x00\x01ui’ (total 16)
length = 16
offset2 = 16
offset1 = 0
checksum = b’\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00’ (total 16)
2018-06-16 19:56:05 DEBUG (Thread-5) [miio.device] Discovered 0440ede3 with ts: 1970-01-02 02:33:13, token: b’00000000000000000000000000000000’
2018-06-16 19:56:05 DEBUG (Thread-5) [miio.device] 192.168.1.76:54321 >>: {‘params’: [‘on’, ‘usb_on’, ‘temperature’, ‘wifi_led’], ‘method’: ‘get_prop’, ‘id’: 1}
2018-06-16 19:56:05 DEBUG (Thread-12) [miio.protocol] Unable to decrypt, returning raw bytes: b’’
2018-06-16 19:56:05 DEBUG (Thread-12) [miio.device] Got a response: Container:
data = Container:
value = b’’ (total 0)
data = b’’ (total 0)
length = 0
offset2 = 32
offset1 = 32
header = Container:
value = Container:
length = 32
unknown = 0
device_id = b’\x04@\xed\xe3’ (total 4)
ts = 1970-01-02 02:33:13
data = b’!1\x00 \x00\x00\x00\x00\x04@\xed\xe3\x00\x01ui’ (total 16)
length = 16
offset2 = 16
offset1 = 0
checksum = b’\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00’ (total 16)
2018-06-16 19:56:05 DEBUG (Thread-12) [miio.device] Discovered 0440ede3 with ts: 1970-01-02 02:33:13, token: b’00000000000000000000000000000000’
2018-06-16 19:56:05 DEBUG (Thread-12) [miio.device] 192.168.1.76:54321 >>: {‘params’: [‘on’, ‘usb_on’, ‘temperature’, ‘wifi_led’], ‘method’: ‘get_prop’, ‘id’: 2}
2018-06-16 19:56:05 DEBUG (Thread-12) [miio.device] 192.168.1.76:54321 (ts: 1970-01-02 02:33:13, id: 2) << {‘result’: [False, False, 40, ‘on’], ‘id’: 2}
2018-06-16 19:56:05 DEBUG (Thread-12) [miio.device] 192.168.1.76:54321 >>: {‘params’: , ‘method’: ‘get_power’, ‘id’: 3}
2018-06-16 19:56:05 DEBUG (Thread-5) [miio.device] 192.168.1.76:54321 (ts: 1970-01-02 02:33:13, id: 1) << {‘result’: [False, False, 40, ‘on’], ‘id’: 1}
2018-06-16 19:56:05 DEBUG (Thread-5) [miio.device] 192.168.1.76:54321 >>: {‘params’: , ‘method’: ‘get_power’, ‘id’: 2}
2018-06-16 19:56:06 DEBUG (Thread-12) [miio.device] 192.168.1.76:54321 (ts: 1970-01-02 02:33:13, id: 3) << {‘result’: [0], ‘id’: 3}
2018-06-16 19:56:06 DEBUG (MainThread) [homeassistant.components.switch.xiaomi_miio] Got new state: <ChuangmiPlugStatus power=False, usb_power=False, temperature=40load_power=0, wifi_led=True>
2018-06-16 19:56:06 INFO (MainThread) [homeassistant.components.switch.xiaomi_miio] Initializing with host 192.168.1.62 (token 74685…)
2018-06-16 19:56:06 DEBUG (MainThread) [miio.protocol] Unable to decrypt, returning raw bytes: b’’
2018-06-16 19:56:06 DEBUG (MainThread) [miio.device] Got a response: Container:
data = Container:
value = b’’ (total 0)
data = b’’ (total 0)
length = 0
offset2 = 32
offset1 = 32
header = Container:
value = Container:
length = 32
unknown = 0
device_id = b’\x02\xe7$V’ (total 4)
ts = 1970-01-02 05:31:55
data = b’!1\x00 \x00\x00\x00\x00\x02\xe7$V\x00\x01\x9fK’ (total 16)
length = 16
offset2 = 16
offset1 = 0
checksum = b’thPO\xc6~\x16\x15\xf9\xf9\xe7u\xdc\xc8\xbc\xbc’ (total 16)


2018-06-16 19:56:11 DEBUG (Thread-5) [miio.protocol] Unable to decrypt, returning raw bytes: b’’
2018-06-16 19:56:11 DEBUG (Thread-5) [miio.device] Got a response: Container:
data = Container:
value = b’’ (total 0)
data = b’’ (total 0)
length = 0
offset2 = 32
offset1 = 32
header = Container:
value = Container:
length = 32
unknown = 0
device_id = b’\x04@\xed\xe3’ (total 4)
ts = 1970-01-02 02:33:18
data = b’!1\x00 \x00\x00\x00\x00\x04@\xed\xe3\x00\x01un’ (total 16)
length = 16
offset2 = 16
offset1 = 0
checksum = b’\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00’ (total 16)
2018-06-16 19:56:11 DEBUG (Thread-5) [miio.device] Discovered 0440ede3 with ts: 1970-01-02 02:33:18, token: b’00000000000000000000000000000000’
2018-06-16 19:56:11 DEBUG (Thread-5) [miio.device] 192.168.1.76:54321 >>: {‘params’: , ‘method’: ‘get_power’, ‘id’: 104}
2018-06-16 19:56:11 DEBUG (Thread-5) [miio.device] 192.168.1.76:54321 (ts: 1970-01-02 02:33:18, id: 104) << {‘result’: [0], ‘id’: 104}
2018-06-16 19:56:11 DEBUG (MainThread) [homeassistant.components.switch.xiaomi_miio] Got new state: <ChuangmiPlugStatus power=False, usb_power=False, temperature=40load_power=0, wifi_led=True>
2018-06-16 19:56:11 DEBUG (Thread-16) [miio.device] Retrying with incremented id, retries left: 3
2018-06-16 19:56:11 DEBUG (Thread-16) [miio.protocol] Unable to decrypt, returning raw bytes: b’’
2018-06-16 19:56:11 DEBUG (Thread-16) [miio.device] Got a response: Container:
data = Container:
value = b’’ (total 0)
data = b’’ (total 0)
length = 0
offset2 = 32
offset1 = 32
header = Container:
value = Container:
length = 32
unknown = 0
device_id = b’\x02\xe7$V’ (total 4)
ts = 1970-01-02 05:32:00
data = b’!1\x00 \x00\x00\x00\x00\x02\xe7$V\x00\x01\x9fP’ (total 16)
length = 16
offset2 = 16
offset1 = 0
checksum = b’thPO\xc6~\x16\x15\xf9\xf9\xe7u\xdc\xc8\xbc\xbc’ (total 16)


2018-06-16 20:01:04 DEBUG (Thread-3) [miio.device] Discovered 0440ede3 with ts: 1970-01-02 02:38:11, token: b’00000000000000000000000000000000’
2018-06-16 20:01:04 DEBUG (Thread-3) [miio.device] 192.168.1.76:54321 >>: {‘params’: , ‘method’: ‘get_power’, ‘id’: 939}
2018-06-16 20:01:04 DEBUG (Thread-3) [miio.device] 192.168.1.76:54321 (ts: 1970-01-02 02:38:11, id: 939) << {‘result’: [0], ‘id’: 939}
2018-06-16 20:01:04 DEBUG (MainThread) [homeassistant.components.switch.xiaomi_miio] Got new state: <ChuangmiPlugStatus power=False, usb_power=False, temperature=40load_power=0, wifi_led=True>
2018-06-16 20:01:30 DEBUG (Thread-2) [miio.device] 192.168.1.76:54321 >>: {‘params’: [‘on’, ‘usb_on’, ‘temperature’, ‘wifi_led’], ‘method’: ‘get_prop’, ‘id’: 941}
2018-06-16 20:01:30 DEBUG (Thread-14) [miio.device] 192.168.1.76:54321 >>: {‘params’: [‘on’, ‘usb_on’, ‘temperature’, ‘wifi_led’], ‘method’: ‘get_prop’, ‘id’: 940}
2018-06-16 20:01:30 DEBUG (Thread-17) [miio.device] 192.168.1.63:54321 >>: {‘params’: [‘power’, ‘temperature’], ‘method’: ‘get_prop’, ‘id’: 112}
2018-06-16 20:01:30 DEBUG (Thread-20) [miio.device] 192.168.1.62:54321 >>: {‘params’: [‘power’, ‘temperature’, ‘current’, ‘mode’, ‘power_consume_rate’, ‘wifi_led’, ‘power_price’], ‘method’: ‘get_prop’, ‘id’: 112}
2018-06-16 20:01:30 DEBUG (Thread-16) [miio.device] 192.168.1.56:54321 >>: {‘params’: [‘power’, ‘temperature’], ‘method’: ‘get_prop’, ‘id’: 114}
2018-06-16 20:01:30 DEBUG (Thread-20) [miio.device] 192.168.1.62:54321 (ts: 1970-01-02 05:37:18, id: 112) << {‘result’: [‘off’, 38.3, 0.0, None, 0.0, ‘on’, 29], ‘id’: 112}
2018-06-16 20:01:30 DEBUG (MainThread) [homeassistant.components.switch.xiaomi_miio] Got new state:
2018-06-16 20:01:30 DEBUG (Thread-17) [miio.device] 192.168.1.63:54321 (ts: 1970-01-06 09:13:33, id: 112) << {‘result’: [‘off’, 43], ‘id’: 112}
2018-06-16 20:01:30 DEBUG (Thread-16) [miio.device] 192.168.1.56:54321 (ts: 1970-01-06 08:57:48, id: 114) << {‘result’: [‘off’, 44], ‘id’: 114}
2018-06-16 20:01:30 DEBUG (MainThread) [homeassistant.components.switch.xiaomi_miio] Got new state: <ChuangmiPlugStatus power=False, usb_power=None, temperature=43load_power=None, wifi_led=None>
2018-06-16 20:01:30 DEBUG (MainThread) [homeassistant.components.switch.xiaomi_miio] Got new state: <ChuangmiPlugStatus power=False, usb_power=None, temperature=44load_power=None, wifi_led=None>
2018-06-16 20:01:30 DEBUG (Thread-14) [miio.device] 192.168.1.76:54321 (ts: 1970-01-02 02:38:37, id: 940) << {‘result’: [False, False, 40, ‘on’], ‘id’: 940}
2018-06-16 20:01:30 DEBUG (Thread-2) [miio.device] 192.168.1.76:54321 (ts: 1970-01-02 02:38:37, id: 941) << {‘result’: [False, False, 40, ‘on’], ‘id’: 941}
2018-06-16 20:01:30 DEBUG (Thread-14) [miio.device] 192.168.1.76:54321 >>: {‘params’: , ‘method’: ‘get_power’, ‘id’: 941}
2018-06-16 20:01:30 DEBUG (Thread-2) [miio.device] 192.168.1.76:54321 >>: {‘params’: , ‘method’: ‘get_power’, ‘id’: 942}
2018-06-16 20:01:30 DEBUG (Thread-2) [miio.device] 192.168.1.76:54321 (ts: 1970-01-02 02:38:38, id: 942) << {‘result’: [0], ‘id’: 942}
2018-06-16 20:01:30 DEBUG (MainThread) [homeassistant.components.switch.xiaomi_miio] Got new state: <ChuangmiPlugStatus power=False, usb_power=False, temperature=40load_power=0, wifi_led=True>
2018-06-16 20:01:35 DEBUG (Thread-14) [miio.device] Retrying with incremented id, retries left: 3
2018-06-16 20:01:35 DEBUG (Thread-14) [miio.protocol] Unable to decrypt, returning raw bytes: b’’
2018-06-16 20:01:35 DEBUG (Thread-14) [miio.device] Got a response: Container:
data = Container:
value = b’’ (total 0)
data = b’’ (total 0)
length = 0
offset2 = 32
offset1 = 32
header = Container:
value = Container:
length = 32
unknown = 0
device_id = b’\x04@\xed\xe3’ (total 4)
ts = 1970-01-02 02:38:42
data = b’!1\x00 \x00\x00\x00\x00\x04@\xed\xe3\x00\x01v\xb2’ (total 16)
length = 16
offset2 = 16
offset1 = 0
checksum = b’\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00’ (total 16)
2018-06-16 20:01:35 DEBUG (Thread-14) [miio.device] Discovered 0440ede3 with ts: 1970-01-02 02:38:42, token: b’00000000000000000000000000000000’
2018-06-16 20:01:35 DEBUG (Thread-14) [miio.device] 192.168.1.76:54321 >>: {‘params’: , ‘method’: ‘get_power’, ‘id’: 1043}
2018-06-16 20:01:35 DEBUG (Thread-14) [miio.device] 192.168.1.76:54321 (ts: 1970-01-02 02:38:43, id: 1043) << {‘result’: [0], ‘id’: 1043}
2018-06-16 20:01:35 DEBUG (MainThread) [homeassistant.components.switch.xiaomi_miio] Got new state: <ChuangmiPlugStatus power=False, usb_power=False, temperature=40load_power=0, wifi_led=True>
2018-06-16 2

This is the switch configuration (it’s IP is 192.168.1.76):

  • platform: xiaomi_miio
    host: !secret ip_enchufe_3
    name: Cargador Isidoro
    token: 137b************************
    model: chuangmi.plug.v3

If I comment out the model attribute, it works fine.

Could you describe what’s not working? I cannot see a problem in your logs.

What does not work is that the device is not detected by HA.
It’s not in its group nor in the developer tools states. The template sensor I have defined to extract the load power does not work either, as the switch does not exist.

Reviewing my own logs, I can see that the method miIO.info is called on every xiaomiplug I have (and even on the IR emitter) except for the new v3 (when the model is specified in configuration).

This is the result of grep miIO\.info /var/log/hass.log when the model is specified:

2018-06-16 19:56:00 DEBUG (MainThread) [miio.device] 192.168.1.61:54321 >>: {‘params’: , ‘method’: ‘miIO.info’, ‘id’: 1}
2018-06-16 19:56:00 DEBUG (MainThread) [miio.device] 192.168.1.61:54321 >>: {‘params’: , ‘method’: ‘miIO.info’, ‘id’: 2}
2018-06-16 19:56:03 DEBUG (MainThread) [miio.device] 192.168.1.63:54321 >>: {‘params’: , ‘method’: ‘miIO.info’, ‘id’: 1}
2018-06-16 19:56:04 DEBUG (MainThread) [miio.device] 192.168.1.56:54321 >>: {‘params’: , ‘method’: ‘miIO.info’, ‘id’: 1}
2018-06-16 19:56:06 DEBUG (MainThread) [miio.device] 192.168.1.62:54321 >>: {‘params’: , ‘method’: ‘miIO.info’, ‘id’: 1}

This is the result of the same command when the model is specified:

2018-06-17 01:58:25 DEBUG (MainThread) [miio.device] 192.168.1.61:54321 >>: {‘id’: 1, ‘method’: ‘miIO.info’, ‘params’: }
2018-06-17 01:58:26 DEBUG (MainThread) [miio.device] 192.168.1.61:54321 >>: {‘id’: 2, ‘method’: ‘miIO.info’, ‘params’: }
2018-06-17 01:58:28 DEBUG (MainThread) [miio.device] 192.168.1.63:54321 >>: {‘id’: 1, ‘method’: ‘miIO.info’, ‘params’: }
2018-06-17 01:58:30 DEBUG (MainThread) [miio.device] 192.168.1.56:54321 >>: {‘id’: 1, ‘method’: ‘miIO.info’, ‘params’: }
2018-06-17 01:58:31 DEBUG (MainThread) [miio.device] 192.168.1.76:54321 >>: {‘id’: 1, ‘method’: ‘miIO.info’, ‘params’: }
2018-06-17 01:58:32 DEBUG (MainThread) [miio.device] 192.168.1.62:54321 >>: {‘id’: 1, ‘method’: ‘miIO.info’, ‘params’: }

The IP 192.168.1.76 is the v3 plug.

This is correct. If the model is provided at the configuration the device identification is avoided. Please check your entity list at the dev tools again. Does the device show up (with a different entity name!)?

1 Like

Yes, you’re right, I’m sorry.
It shows as two switches (main and USB), but with different names (suffix _2 added), I don’t know why.

This is intended. The configuration without “model” parameter has entity registry support (a unique id). If the model parameter is used we don’t know the MAC address and cannot provide a proper unique id to use for the entity registry.

1 Like

Reading this thread was really helpful. Thanks!

I have an issue that every now and then (i cannot track why and when), HASS changes the recognized switch name, exactly like @ec-blaster mentioned above (suffix “_#” added). this completely messes my automations as they call an entity which no longer exists. Any idea why it happens and how to fix it?

Hi, sorry, I have the same issue with the Xiaomi Plug Mini, however I’m quite new to the HA. Could you please explain in some steps how do I apply your fix? Thank you in advance!

1 Like

Could you post your configuration? Do you see any related errors in your home-assistant.log?