Open miway80 opened 4 years ago
@miway80 did you already try to create a PR for the SwitchOneChannel?
Just open wireshark, select all interfaces and start a capture. Then type in the filter and apply the filter:
ip.src==192.168.1.IP or ip.dst==192.168.1.IP
with IP the ip-adress of the xiaomi gatewayNow you schould see UDP packets beeing captured when you sent stuff to the gateway and you schould also see responses from the gateway. Note that you need to communicate from the same device as wireshark is running and do not use VPN's while you are capturing.
Miio protecoll uses encryption with the token so you cant directly read the packets.
1. Stop the capture 2. click file--> Export packet dissections --> As json 3. save the file somewhere 4. install miIO Device Library using npm https://github.com/aholstenson/miio `npm install -g miio` 5. in command prompt type (using the path of the file of step 2 and the token of your gateway): `miio protocol json-dump path-to-json-file-of-step-2 --token TokenTokenToken` 6. this schould now show you the decrypted packets
I just did it and i got it, 192.168.31.224 = gateway ip I execute mi.py code when capture packages, also on / off some devices at some time
<- 192.168.31.224 data= N/A <- 192.168.31.224 data= {"result":{"life":64,"cfg_time":0,"token":"tokentoken","mac":"34:CE:00:88:C8:XX","fw_ver":"1.4.1_175","hw_ver":"MW300","model":"lumi.gateway.v3","mcu_fw_ver":"0220","wifi_fw_ver":"SD878x-14.76.36.p84-702.1.0-WM","ap":{"rssi":-39,"ssid":"miway","bssid":"50:64:2B:95:87:XX"},"netif":{"localIp":"192.168.31.224","mask":"255.255.255.0","gw":"192.168.31.1","gw_mac":"50:64:2B:95:88:XX"},"mmfree":162120,"ot":"ott","otu_stat":[0,0,0,0,0,268],"ott_stat":[2, 0, 273, 165]},"id":1} <- 192.168.31.224 data= N/A <- 192.168.31.224 data= N/A <- 192.168.31.224 data= N/A <- 192.168.31.224 data= {"result":{"life":25,"cfg_time":0,"token":"tokentoken","mac":"34:CE:00:88:C8:XX","fw_ver":"1.4.1_175","hw_ver":"MW300","model":"lumi.gateway.v3","mcu_fw_ver":"0220","wifi_fw_ver":"SD878x-14.76.36.p84-702.1.0-WM","ap":{"rssi":-41,"ssid":"miway","bssid":"50:64:2B:95:87:XX"},"netif":{"localIp":"192.168.31.224","mask":"255.255.255.0","gw":"192.168.31.1","gw_mac":"50:64:2B:95:88:XX"},"mmfree":160656,"otu_stat":[0,0,0,0,0,273],"ott_stat":[1, 0, 402, 581]},"id":1} <- 192.168.31.224 data= N/A <- 192.168.31.224 data= {"result":{"life":44,"cfg_time":0,"token":"tokentoken","mac":"34:CE:00:88:C8:XX","fw_ver":"1.4.1_175","hw_ver":"MW300","model":"lumi.gateway.v3","mcu_fw_ver":"0220","wifi_fw_ver":"SD878x-14.76.36.p84-702.1.0-WM","ap":{"rssi":-43,"ssid":"miway","bssid":"50:64:2B:95:87:XX"},"netif":{"localIp":"192.168.31.224","mask":"255.255.255.0","gw":"192.168.31.1","gw_mac":"50:64:2B:95:88:XX"},"mmfree":161496,"otu_stat":[0,0,0,0,0,5],"ott_stat":[2, 0, 274, 1082]},"id":1} <- 192.168.31.224 data= N/A <- 192.168.31.224 data= {"result":{"life":18,"cfg_time":0,"token":"tokentoken","mac":"34:CE:00:88:C8:XX","fw_ver":"1.4.1_175","hw_ver":"MW300","model":"lumi.gateway.v3","mcu_fw_ver":"0220","wifi_fw_ver":"SD878x-14.76.36.p84-702.1.0-WM","ap":{"rssi":-42,"ssid":"miway","bssid":"50:64:2B:95:87:XX"},"netif":{"localIp":"192.168.31.224","mask":"255.255.255.0","gw":"192.168.31.1","gw_mac":"50:64:2B:95:88:XX"},"mmfree":162464,"otu_stat":[0,0,0,0,0,5],"ott_stat":[0, 0, 0, 0]},"id":1} <- 192.168.31.224 data= N/A <- 192.168.31.224 data= N/A <- 192.168.31.224 data= N/A <- 192.168.31.224 data= {"result":{"life":26,"cfg_time":0,"token":"tokentoken","mac":"34:CE:00:88:C8:XX","fw_ver":"1.4.1_175","hw_ver":"MW300","model":"lumi.gateway.v3","mcu_fw_ver":"0220","wifi_fw_ver":"SD878x-14.76.36.p84-702.1.0-WM","ap":{"rssi":-42,"ssid":"miway","bssid":"50:64:2B:95:87:XX"},"netif":{"localIp":"192.168.31.224","mask":"255.255.255.0","gw":"192.168.31.1","gw_mac":"50:64:2B:95:88:XX"},"mmfree":158312,"ot":"ott","otu_stat":[0,0,0,0,0,404],"ott_stat":[1, 0, 10, 166]},"id":1} <- 192.168.31.224 data= N/A <- 192.168.31.224 data= {"result":{"life":27,"cfg_time":0,"token":"tokentoken","mac":"34:CE:00:88:C8:XX","fw_ver":"1.4.1_175","hw_ver":"MW300","model":"lumi.gateway.v3","mcu_fw_ver":"0220","wifi_fw_ver":"SD878x-14.76.36.p84-702.1.0-WM","ap":{"rssi":-41,"ssid":"miway","bssid":"50:64:2B:95:87:XX"},"netif":{"localIp":"192.168.31.224","mask":"255.255.255.0","gw":"192.168.31.1","gw_mac":"50:64:2B:95:88:XX"},"mmfree":158808,"ot":"ott","otu_stat":[0,0,0,0,0,405],"ott_stat":[1, 0, 2, 2914]},"id":1} <- 192.168.31.224 data= N/A <- 192.168.31.224 data= N/A <- 192.168.31.224 data= N/A <- 192.168.31.224 data= {"result":{"life":61,"cfg_time":0,"token":"tokentoken","mac":"34:CE:00:88:C8:XX","fw_ver":"1.4.1_175","hw_ver":"MW300","model":"lumi.gateway.v3","mcu_fw_ver":"0220","wifi_fw_ver":"SD878x-14.76.36.p84-702.1.0-WM","ap":{"rssi":-43,"ssid":"miway","bssid":"50:64:2B:95:87:XX"},"netif":{"localIp":"192.168.31.224","mask":"255.255.255.0","gw":"192.168.31.1","gw_mac":"50:64:2B:95:88:XX"},"mmfree":162144,"ot":"ott","otu_stat":[0,0,0,0,0,405],"ott_stat":[2, 0, 401, 193]},"id":1} <- 192.168.31.224 data= N/A <- 192.168.31.224 data= N/A <- 192.168.31.224 data= N/A <- 192.168.31.224 data= {"result":{"life":20,"cfg_time":0,"token":"tokentoken","mac":"34:CE:00:88:C8:XX","fw_ver":"1.4.1_175","hw_ver":"MW300","model":"lumi.gateway.v3","mcu_fw_ver":"0220","wifi_fw_ver":"SD878x-14.76.36.p84-702.1.0-WM","ap":{"rssi":-42,"ssid":"miway","bssid":"50:64:2B:95:87:XX"},"netif":{"localIp":"192.168.31.224","mask":"255.255.255.0","gw":"192.168.31.1","gw_mac":"50:64:2B:95:88:XX"},"mmfree":159888,"ot":"ott","otu_stat":[0,0,0,0,0,414],"ott_stat":[1, 0, 11, 165]},"id":1} <- 192.168.31.224 data= N/A <- 192.168.31.224 data= {"result":{"life":13,"cfg_time":0,"token":"tokentoken","mac":"34:CE:00:88:C8:XX","fw_ver":"1.4.1_175","hw_ver":"MW300","model":"lumi.gateway.v3","mcu_fw_ver":"0220","wifi_fw_ver":"SD878x-14.76.36.p84-702.1.0-WM","ap":{"rssi":-40,"ssid":"miway","bssid":"50:64:2B:95:87:XX"},"netif":{"localIp":"192.168.31.224","mask":"255.255.255.0","gw":"192.168.31.1","gw_mac":"50:64:2B:95:88:XX"},"mmfree":163032,"otu_stat":[0,0,0,0,0,103],"ott_stat":[0, 0, 0, 0]},"id":1} <- 192.168.31.224 data= N/A <- 192.168.31.224 data= {"result":{"life":18,"cfg_time":0,"token":"tokentoken","mac":"34:CE:00:88:C8:XX","fw_ver":"1.4.1_175","hw_ver":"MW300","model":"lumi.gateway.v3","mcu_fw_ver":"0220","wifi_fw_ver":"SD878x-14.76.36.p84-702.1.0-WM","ap":{"rssi":-38,"ssid":"miway","bssid":"50:64:2B:95:87:XX"},"netif":{"localIp":"192.168.31.224","mask":"255.255.255.0","gw":"192.168.31.1","gw_mac":"50:64:2B:95:88:XX"},"mmfree":162424,"otu_stat":[0,0,0,0,0,408],"ott_stat":[0, 0, 0, 0]},"id":1} <- 192.168.31.224 data= N/A <- 192.168.31.224 data= N/A <- 192.168.31.224 data= N/A
did you already try to create a PR for the SwitchOneChannel? yes, also i did it, i modified gateway.py
to start with a simple Pull Request:
go to the file you wish to edit, in this case: https://github.com/rytilahti/python-miio/blob/master/miio/gateway.py (make sure you are on the "master" brance wich is visible at the top left besides the file path)
Hit the pencile icon ("edit") on the top right of the file box
Make the changes that you want
type in a title and discribtion of the PR at the bottom
hit the green Propose changes button
A new fork will be created on your github acount and there schould apear a green button at the top to create a Pull Request to the original repositry (this reposity of rytilahti).
@miway80 alright I see the patch-1 in you github repository. However you did not make the actual pull request to the rytilahti repository. Anyway I already Included it in my latest PR. Just that you know for the next time: your PR schould show up under: https://github.com/rytilahti/python-miio/pulls if it is successful.
Nice so you are now able to capture packets from the gateway. You schould now try the discover_devices command again while capturing the packets. At least the command to discover schould then show up in wireshark, and then look if the gateway responds (in wireshark)
Also try to compare pakket captures of the gateway that is working and the one that does not work and try to spot diffrences
I also only see the responses of the gateway in your posted capture, why are the packets sent to the gateway not showing?
Did you set the filter correctly in wireshark:
ip.src==192.168.1.IP or ip.dst==192.168.1.IP
The "or" is part of the filter so enter the whole line with the IP filled in twice
@miway80 alright I see the patch-1 in you github repository. However you did not make the actual pull request to the rytilahti repository. Anyway I already Included it in my latest PR. Just that you know for the next time: your PR schould show up under: https://github.com/rytilahti/python-miio/pulls if it is successful.
ok, thanks.
I am checking captures, when i capture data in hub with many devices it block my wifi and can not use mihome app correctly .. other gateway is ok, it shows many info, for example 192.168.31.197 imy pc ip 192.168.31.240 ) gateway
192.168.31.197 data= {"id": 1, "method": "miIO.info", "params": []} <- 192.168.31.240 data= {"result":{"life":4429842,"cfg_time":0,"token":"tokentoken","mac":"78:11:DC:B2:XX:XX","fw_ver":"1.4.1_175","hw_ver":"MW300","model":"lumi.gateway.v3","mcu_fw_ver":"0220","wifi_fw_ver":"SD878x-14.76.36.p84-702.1.0-WM","ap":{"rssi":-48,"ssid":"miway","bssid":"50:64:2B:92:XX:XX"},"netif":{"localIp":"192.168.31.240","mask":"255.255.255.0","gw":"192.168.31.1","gw_mac":"50:64:2B:92:XX:XX"},"mmfree":168504,"ot":"otu","otu_stat":[266,225,81305,3097,72705,473],"ott_stat":[718, 27, 213, 335]},"id":1} -> 192.168.31.197 data= {"id": 2, "method": "get_device_prop", "params": ["lumi.0", "device_list"]} <- 192.168.31.240 data= {"result":["lumi.158d0001f3b1b1",1,1,0,10,"lumi.158d00015767a7",14,1,0,4,"lumi.158d00012e1f0c",9,1,21,1,"lumi.158d0001614697",9,1,21,1,"lumi.158d0001f47015",10,0,0,2,"lumi.158d000201407c",65,1,31,1],"id":2} -> 192.168.31.197 data= {"id": 3, "method": "get_battery", "params": ["lumi.158d0001f3b1b1"]} <- 192.168.31.240 data= {"result":[60],"id":3} -> 192.168.31.197 data= {"id": 4, "method": "get_battery", "params": ["lumi.158d00015767a7"]} <- 192.168.31.240 data= {"result":[60],"id":4} -> 192.168.31.197 data= {"id": 5, "method": "get_device_prop_exp", "params": [["lumi.158d00012e1f0c", "neutral_0"]]} <- 192.168.31.240 data= {"result":[["off"]],"id":5} -> 192.168.31.197 data= {"id": 6, "method": "get_battery", "params": ["lumi.158d00012e1f0c"]} <- 192.168.31.240 data= {"result":[60],"id":6} -> 192.168.31.197 data= {"id": 7, "method": "get_device_prop_exp", "params": [["lumi.158d0001614697", "neutral_0"]]} <- 192.168.31.240 data= {"result":[["off"]],"id":7} -> 192.168.31.197 data= {"id": 8, "method": "get_battery", "params": ["lumi.158d0001614697"]} <- 192.168.31.240 data= {"result":[60],"id":8} -> 192.168.31.197 data= {"id": 9, "method": "get_device_prop_exp", "params": [["lumi.158d0001f47015", "temperature", "humidity", "pressure"]]} <- 192.168.31.240 data= {"result":[[10000,0,0]],"id":9} -> 192.168.31.197 data= {"id": 10, "method": "get_battery", "params": ["lumi.158d0001f47015"]} <- 192.168.31.240 data= {"result":[60],"id":10} -> 192.168.31.197 data= {"id": 11, "method": "get_device_prop_exp", "params": [["lumi.158d000201407c", "channel_0", "load_power"]]} <- 192.168.31.240 data= {"result":[["off",0.00]],"id":11} -> 192.168.31.197 data= {"id": 12, "method": "get_battery", "params": ["lumi.158d000201407c"]} <- 192.168.31.240 data= {"result":[60],"id":12} -> 192.168.31.197 data= {"id": 13, "method": "toggle_plug", "params": ["channel_0", "toggle"], "sid": "lumi.158d000201407c"} <- 192.168.31.240 data= {"result":["ok"],"id":13}
@miway80 you could try lazy_discovery=False or a different start_id when you initialize the gateway class???
@miway80 you could try lazy_discovery=False or a different start_id when you initialize the gateway class???
Sorry but i dont understand start_id, i execute many times this code while Wireshark work
from miio import Gateway
gw = Gateway("192.168.31.240", "tokentoken")
lazy_discovery=False
print(gw.info())
gw.discover_devices() devices = gw.devices
for dev in devices: dev.update() print(dev)
In Wareshark i capture packages and put filter ip.src==192.168.31.240 or ip.dst==192.168.31.240 and later decode with json
You can pass those parameters to the Gateway constructor, like:
gw = Gateway("127.0.0.1", "tokentoken", lazy_discovery=True, start_id=1000)
You can pass those parameters to the Gateway constructor, like:
gw = Gateway("127.0.0.1", "tokentoken", lazy_discovery=True, start_id=1000)
I got error, then check in gateway.py and is lazy_discover=True
from miio import Gateway gw = Gateway("192.168.31.240", "tokentoken",lazy_discover=True, start_id=1000)
print(gw.info())
gw.discover_devices() devices = gw.devices
for dev in devices: dev.update() print(dev)
I got
-> 192.168.31.197 data= {"id": 1001, "method": "miIO.info", "params": []} <- 192.168.31.240 data= {"result":{"life":4494802,"cfg_time":0,"token":"tokentoken","mac":"78:11:DC:B2:XX:XX","fw_ver":"1.4.1_175","hw_ver":"MW300","model":"lumi.gateway.v3","mcu_fw_ver":"0220","wifi_fw_ver":"SD878x-14.76.36.p84-702.1.0-WM","ap":{"rssi":-50,"ssid":"miway","bssid":"50:64:2B:92:XX:XX"},"netif":{"localIp":"192.168.31.240","mask":"255.255.255.0","gw":"192.168.31.1","gw_mac":"50:64:2B:92:XX:XX"},"mmfree":168312,"ot":"otu","otu_stat":[290,212,84097,3134,75338,473],"ott_stat":[718, 27, 213, 335]},"id":1001} -> 192.168.31.197 data= {"id": 1002, "method": "get_device_prop", "params": ["lumi.0", "device_list"]} <- 192.168.31.240 data= {"result":["lumi.158d0001f3b1b1",1,1,0,10,"lumi.158d00015767a7",14,1,0,4,"lumi.158d00012e1f0c",9,1,21,1,"lumi.158d0001614697",9,1,21,1,"lumi.158d0001f47015",10,0,0,2,"lumi.158d000201407c",65,1,31,1],"id":1002} -> 192.168.31.197 data= {"id": 1003, "method": "get_battery", "params": ["lumi.158d0001f3b1b1"]} <- 192.168.31.240 data= {"result":[60],"id":1003} -> 192.168.31.197 data= {"id": 1004, "method": "get_battery", "params": ["lumi.158d00015767a7"]} <- 192.168.31.240 data= {"result":[60],"id":1004} -> 192.168.31.197 data= {"id": 1005, "method": "get_device_prop_exp", "params": [["lumi.158d00012e1f0c", "neutral_0"]]} <- 192.168.31.240 data= {"result":[["off"]],"id":1005} -> 192.168.31.197 data= {"id": 1006, "method": "get_battery", "params": ["lumi.158d00012e1f0c"]} <- 192.168.31.240 data= {"result":[60],"id":1006} -> 192.168.31.197 data= {"id": 1007, "method": "get_device_prop_exp", "params": [["lumi.158d0001614697", "neutral_0"]]} <- 192.168.31.240 data= {"result":[["off"]],"id":1007} -> 192.168.31.197 data= {"id": 1008, "method": "get_battery", "params": ["lumi.158d0001614697"]} <- 192.168.31.240 data= {"result":[60],"id":1008} -> 192.168.31.197 data= {"id": 1009, "method": "get_device_prop_exp", "params": [["lumi.158d0001f47015", "temperature", "humidity", "pressure"]]} <- 192.168.31.240 data= {"result":[[10000,0,0]],"id":1009} -> 192.168.31.197 data= {"id": 1010, "method": "get_battery", "params": ["lumi.158d0001f47015"]} <- 192.168.31.240 data= {"result":[60],"id":1010} -> 192.168.31.197 data= {"id": 1011, "method": "get_device_prop_exp", "params": [["lumi.158d000201407c", "channel_0", "load_power"]]} <- 192.168.31.240 data= {"result":[["on",0.00]],"id":1011} -> 192.168.31.197 data= {"id": 1012, "method": "get_battery", "params": ["lumi.158d000201407c"]} <- 192.168.31.240 data= {"result":[60],"id":1012}
@miway80 default is lazy_discover=True
(sorry for my spelling mistake)
So as I sayed I would try lazy_discover=False
, furthermore I was hoping that that could make the gateway that is not working work (so the one with ip=192.168.31.224)
The gateway with ip 192.168.31.240 seems to be working as expected so I dont think there is need for aditional packet captures from that gateway. Mostly the gateway with ip 192.168.31.224 is intresting because we are trying to get that one to work right?
So could you try with lazy_discover=False
and start_id=1000
on the gateway 192.168.31.224 that is giving you problems?
@miway80 I checked the device info from both gateways and they seem to be identical and running the same firmware, so they schould both work....
wifi signal strenght looks OK on both gateways (RSSI of -42 and -50)
basically the only diffrence I see is the otu_stat
and "ott_stat" but I do not know what those mean
@miway80 default is
lazy_discover=True
(sorry for my spelling mistake) So as I sayed I would trylazy_discover=False
, furthermore I was hoping that that could make the gateway that is not working work (so the one with ip=192.168.31.224)The gateway with ip 192.168.31.240 seems to be working as expected so I dont think there is need for aditional packet captures from that gateway. Mostly the gateway with ip 192.168.31.224 is intresting because we are trying to get that one to work right?
So could you try with
lazy_discover=False
andstart_id=1000
on the gateway 192.168.31.224 that is giving you problems?
I just try it and get same error,
Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/miio/miioprotocol.py", line 182, in send data, addr = s.recvfrom(1024) socket.timeout: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "mii.py", line 11, in
@miway80 I checked the device info from both gateways and they seem to be identical and running the same firmware, so they schould both work....
wifi signal strenght looks OK on both gateways (RSSI of -42 and -50) basically the only diffrence I see is the
otu_stat
and "ott_stat" but I do not know what those mean
This gateway is very near to router, have good signal, i think that many devices linked is the problem
I am kind of out of ideas if you can't get response of that gateway to show up in wireshark I would not know how to get it working....
You could try to remove the devices from the crouded gateway and move them to the now working gateway. Then you can test if the now working gateway stops working if you add too many devices and what the device limit is. The now broken gateway schould at some point than start to work with less devices.....
But I understand that that might mess up you current setup if you start moving devices from one gateway to the other..... So it is up to you if your are willing to try that....
I am kind of out of ideas if you can't get response of that gateway to show up in wireshark I would not know how to get it working....
You could try to remove the devices from the crouded gateway and move them to the now working gateway. Then you can test if the now working gateway stops working if you add too many devices and what the device limit is. The now broken gateway schould at some point than start to work with less devices.....
But I understand that that might mess up you current setup if you start moving devices from one gateway to the other..... So it is up to you if your are willing to try that....
Yes, i will do it, but now very busy, about 10 days i will be more quiet, then try remove device one per one and put in other gateway checking code
It could very well be that we are hitting the datagram size limitations (similar what happens with some devices when trying to request too many properties at once, hard to know without checking tho..), while it works just fine when the request is done through the cloud.
Hi all, I would like to fit into this thread, i'm looking for option to control my Xiaomi zigbee smart plug (toggle off/on). So going through this thread - i've configured my environment as follows: python-miio npm-miio wireshark Bluestack with installed mihome linked to my user. next ill try to capture and analyse the toggling packets. Surely i'll have to ask your assistance, will update on progress.
Hi all, I would like to fit into this thread, i'm looking for option to control my Xiaomi zigbee smart plug (toggle off/on). So going through this thread - i've configured my environment as follows: python-miio npm-miio wireshark Bluestack with installed mihome linked to my user. next ill try to capture and analyse the toggling packets. Surely i'll have to ask your assistance, will update on progress.
Can be is very similar to walloutlet
Create a file x.py for get info
from miio import Gateway
gateway = Gateway("192.168.1.IP", "tokentokentoken")
gateway.discover_devices() devices = gateway.devices
for dev in devices: dev.update() print(dev)
And add to gateway.py
Smart_plug = X ( X = number get in discover_devices)
DeviceType.Smart_plug: Smart_plug,
class Smart_plug(SubDevice): """Subdevice Smart_plug specific properties and methods"""
properties = ["channel_0", "load_power"]
@attr.s(auto_attribs=True)
class props:
"""Device specific properties"""
status: str = None # 'on' / 'off'
load_power: int = None # power consumption in ?unit?
@command()
def update(self):
"""Update all device properties"""
values = self.get_property_exp(self.properties)
self._props.status = values[0]
self._props.load_power = values[1]
@command()
def toggle(self):
"""Toggle Smart_plug"""
return self.send_arg("toggle_plug", ["channel_0", "toggle"]).pop()
@command()
def on(self):
"""Turn on Smart_plug"""
return self.send_arg("toggle_plug", ["channel_0", "on"]).pop()
@command()
def off(self):
"""Turn off Smart_plug"""
return self.send_arg("toggle_plug", ["channel_0", "off"]).pop()
@miway80 is right. I would like to add that you schould first update your gateway.py file inside the python-miio folder to the latest version in https://github.com/rytilahti/python-miio/blob/master/miio/gateway.py There is a good change your plug will then already be recognized if you run the test script as pointed out by @miway80:
from miio import Gateway
gateway = Gateway("192.168.1.IP", "tokentokentoken")
gateway.discover_devices()
devices = gateway.devices
for dev in devices:
dev.update()
print(dev)
@wuid24 please post the results of that test script so we can point you in the right direction.
Hi all, I would like to fit into this thread, i'm looking for option to control my Xiaomi zigbee smart plug (toggle off/on). So going through this thread - i've configured my environment as follows: python-miio npm-miio wireshark Bluestack with installed mihome linked to my user. next ill try to capture and analyse the toggling packets. Surely i'll have to ask your assistance, will update on progress.
Can be is very similar to walloutlet
Create a file x.py for get info
from miio import Gateway
gateway = Gateway("192.168.1.IP", "tokentokentoken")
gateway.discover_devices() devices = gateway.devices
for dev in devices: dev.update() print(dev)
And add to gateway.py
Smart_plug = X ( X = number get in discover_devices)
DeviceType.Smart_plug: Smart_plug,
class Smart_plug(SubDevice): """Subdevice Smart_plug specific properties and methods"""
properties = ["channel_0", "load_power"] @attr.s(auto_attribs=True) class props: """Device specific properties""" status: str = None # 'on' / 'off' load_power: int = None # power consumption in ?unit? @command() def update(self): """Update all device properties""" values = self.get_property_exp(self.properties) self._props.status = values[0] self._props.load_power = values[1] @command() def toggle(self): """Toggle Smart_plug""" return self.send_arg("toggle_plug", ["channel_0", "toggle"]).pop() @command() def on(self): """Turn on Smart_plug""" return self.send_arg("toggle_plug", ["channel_0", "on"]).pop() @command() def off(self): """Turn off Smart_plug""" return self.send_arg("toggle_plug", ["channel_0", "off"]).pop()
Hi,
trying to get the Plug type_id as @miway80 wrote,
but I can't find it from the print:
Unknown subdevice type SubDeviceInfo(sid='lumi.158d00035ab657', type_id=55, unknown=1, unknown2=0, fw_ver=4) discovered, of Xiaomi gateway with ip: 10.100.102.7 Unknown subdevice type SubDeviceInfo(sid='lumi.158d00035ab56a', type_id=55, unknown=1, unknown2=0, fw_ver=4) discovered, of Xiaomi gateway with ip: 10.100.102.7 <Subdevice SensorHT: lumi.158d00020291ea fw: 2 bat: 60 props: {'temperature': 25.7, 'humidity': 66.67, 'pressure': 0.0}> <Subdevice Plug: lumi.158d0002855e4c fw: 1 bat: 60 props: {'status': 'off', 'power': '', 'load_power': 0.0}> <Subdevice Unknown: lumi.158d00035ab657 fw: 4 bat: 60 props: {}> <Subdevice Plug: lumi.158d00025856ca fw: 1 bat: 60 props: {'status': 'off', 'power': '', 'load_power': 0.0}> <Subdevice SensorHT: lumi.158d00034f7a0b fw: 2 bat: 60 props: {'temperature': 32.12, 'humidity': 51.12, 'pressure': 0.0}> <Subdevice Plug: lumi.158d0002677318 fw: 1 bat: 60 props: {'status': 'on', 'power': '', 'load_power': 102.42}> <Subdevice Unknown: lumi.158d00035ab56a fw: 4 bat: 60 props: {}> <Subdevice SensorHT: lumi.158d0003502737 fw: 2 bat: 60 props: {'temperature': 27.38, 'humidity': 83.63, 'pressure': 0.0}>
I've also tried to work on debug mode (using pycharm) and got the following error:
dev.update() AttributeError: 'str' object has no attribute 'update'
@wuid24 alright, so there are two "unknown" devices, both with type_id=55, however in the latest python-miio gateway.py file this device type is already included as AqaraWaterLeak = 55 _zigbee_model = "lumi.sensor_wleak.aq1" _model = "SJCGQ11LM"
Is it correct that you have two of such a water leak sensors?
Besides those two water leak sensors 3 temperature sensors and 3 plugs are correctly detected. Please format the results of the test script with enters like this (for the next time):
Unknown subdevice type SubDeviceInfo(sid='lumi.158d00035ab657', type_id=55, unknown=1, unknown2=0, fw_ver=4) discovered, of Xiaomi gateway with ip: 10.100.102.7
Unknown subdevice type SubDeviceInfo(sid='lumi.158d00035ab56a', type_id=55, unknown=1, unknown2=0, fw_ver=4) discovered, of Xiaomi gateway with ip: 10.100.102.7
<Subdevice SensorHT: lumi.158d00020291ea fw: 2 bat: 60 props: {'temperature': 25.7, 'humidity': 66.67, 'pressure': 0.0}>
<Subdevice SensorHT: lumi.158d0003502737 fw: 2 bat: 60 props: {'temperature': 27.38, 'humidity': 83.63, 'pressure': 0.0}>
<Subdevice SensorHT: lumi.158d00034f7a0b fw: 2 bat: 60 props: {'temperature': 32.12, 'humidity': 51.12, 'pressure': 0.0}>
<Subdevice Plug: lumi.158d0002855e4c fw: 1 bat: 60 props: {'status': 'off', 'power': '', 'load_power': 0.0}>
<Subdevice Plug: lumi.158d0002677318 fw: 1 bat: 60 props: {'status': 'on', 'power': '', 'load_power': 102.42}>
<Subdevice Plug: lumi.158d00025856ca fw: 1 bat: 60 props: {'status': 'off', 'power': '', 'load_power': 0.0}>
<Subdevice Unknown: lumi.158d00035ab657 fw: 4 bat: 60 props: {}>
<Subdevice Unknown: lumi.158d00035ab56a fw: 4 bat: 60 props: {}>
I can see you did not update the gateway.py file from https://github.com/rytilahti/python-miio/blob/master/miio/gateway.py yet when you obtained this print. Please do update (the official version has not been released, so updating usig pip will not give you the latest version).
Regarding the error message, you will get that error once you have the latest version of gateway.py because the gateway.devices
have changed from a list to a dict. To resolve it, change the test script to (add the .values()
):
from miio import Gateway
gateway = Gateway("192.168.1.IP", "tokentokentoken")
gateway.discover_devices()
devices = gateway.devices
for dev in devices.values():
dev.update()
print(dev)
Regarding the plugs you want to integrate, as you can see you can already read out the status and load_power. Apprently the power is not a correct property since it is empty. Is there any more information available in the Mi Home App besides the status and the load_power? other properties that you could try besides "channel_0" and "load_power"are:
"power_consumed"
"energy_consumed"
"inuse"
To add functionallity the Plug
class on line 982 of the gateway.py file needs to be modified: https://github.com/rytilahti/python-miio/blob/de28e85327c5886789a54c6598005a683e111dbe/miio/gateway.py#L982
Try adding this to that class:
@command()
def toggle(self):
"""Toggle Plug."""
return self.send_arg("toggle_ctrl_neutral", ["channel_0", "toggle"]).pop()
@command()
def on(self):
"""Turn on Plug."""
return self.send_arg("toggle_ctrl_neutral", ["channel_0", "on"]).pop()
@command()
def off(self):
"""Turn off Plug."""
return self.send_arg("toggle_ctrl_neutral", ["channel_0", "off"]).pop()
@wuid24 I also noticed that the SensorHT
reports a pressure of 0.0
Does your temperature sensor report pressure in the MiHome app, or only temperature and humidity?
@starkillerOG my understanding is that the older aqara sensors (the round ones) do not have the pressure measurement, only the newer rectangular ones do.
@wuid24 I already updated the sensorHT and plug class for the properties in this PR: https://github.com/rytilahti/python-miio/pull/735
Could you let me know the unit for the load_power
as displayed in the MiHome app for the plug?
@wuid24 alright, so there are two "unknown" devices, both with type_id=55, however in the latest python-miio gateway.py file this device type is already included as
AqaraWaterLeak = 55 _zigbee_model = "lumi.sensor_wleak.aq1" _model = "SJCGQ11LM"
Is it correct that you have two of such a water leak sensors?Besides those two water leak sensors 3 temperature sensors and 3 plugs are correctly detected. Please format the results of the test script with enters like this (for the next time):
Unknown subdevice type SubDeviceInfo(sid='lumi.158d00035ab657', type_id=55, unknown=1, unknown2=0, fw_ver=4) discovered, of Xiaomi gateway with ip: 10.100.102.7 Unknown subdevice type SubDeviceInfo(sid='lumi.158d00035ab56a', type_id=55, unknown=1, unknown2=0, fw_ver=4) discovered, of Xiaomi gateway with ip: 10.100.102.7 <Subdevice SensorHT: lumi.158d00020291ea fw: 2 bat: 60 props: {'temperature': 25.7, 'humidity': 66.67, 'pressure': 0.0}> <Subdevice SensorHT: lumi.158d0003502737 fw: 2 bat: 60 props: {'temperature': 27.38, 'humidity': 83.63, 'pressure': 0.0}> <Subdevice SensorHT: lumi.158d00034f7a0b fw: 2 bat: 60 props: {'temperature': 32.12, 'humidity': 51.12, 'pressure': 0.0}> <Subdevice Plug: lumi.158d0002855e4c fw: 1 bat: 60 props: {'status': 'off', 'power': '', 'load_power': 0.0}> <Subdevice Plug: lumi.158d0002677318 fw: 1 bat: 60 props: {'status': 'on', 'power': '', 'load_power': 102.42}> <Subdevice Plug: lumi.158d00025856ca fw: 1 bat: 60 props: {'status': 'off', 'power': '', 'load_power': 0.0}> <Subdevice Unknown: lumi.158d00035ab657 fw: 4 bat: 60 props: {}> <Subdevice Unknown: lumi.158d00035ab56a fw: 4 bat: 60 props: {}>
I can see you did not update the gateway.py file from https://github.com/rytilahti/python-miio/blob/master/miio/gateway.py yet when you obtained this print. Please do update (the official version has not been released, so updating usig pip will not give you the latest version).
Regarding the error message, you will get that error once you have the latest version of gateway.py because the
gateway.devices
have changed from a list to a dict. To resolve it, change the test script to (add the.values()
):from miio import Gateway gateway = Gateway("192.168.1.IP", "tokentokentoken") gateway.discover_devices() devices = gateway.devices for dev in devices.values(): dev.update() print(dev)
Regarding the plugs you want to integrate, as you can see you can already read out the status and load_power. Apprently the power is not a correct property since it is empty. Is there any more information available in the Mi Home App besides the status and the load_power? other properties that you could try besides "channel_0" and "load_power"are:
"power_consumed" "energy_consumed" "inuse"
To add functionallity the
Plug
class on line 982 of the gateway.py file needs to be modified:Try adding this to that class:
@command() def toggle(self): """Toggle Plug.""" return self.send_arg("toggle_ctrl_neutral", ["channel_0", "toggle"]).pop() @command() def on(self): """Turn on Plug.""" return self.send_arg("toggle_ctrl_neutral", ["channel_0", "on"]).pop() @command() def off(self): """Turn off Plug.""" return self.send_arg("toggle_ctrl_neutral", ["channel_0", "off"]).pop()
@starkillerOG , i've aligned to gateway.py from master,
load_power
is the current consumption power in Wattage.
No other properties for the AqaraSmartPlug.
I've added the @command
's to the plug class and tried to turn off the plug without success.
gateway = Gateway("10.100.102.7", "token")
gateway.discover_devices()
devices = gateway.devices
for dev in devices.values():
dev.update()
print(dev)
plug_test = devices['lumi.158d0002677318']
print(plug_test.status)
plug_test.off()
time.sleep(5)
print(plug_test.status)
<Subdevice SensorHT: lumi.158d00020291ea, model: RTCGQ01LM, zigbee: lumi.sensor_ht, fw: 2, bat: 60, props: {'temperature': 26.69, 'humidity': 62.71, 'pressure': 0.0}>
<Subdevice Plug: lumi.158d0002855e4c, model: ZNCZ02LM, zigbee: lumi.plug, fw: 1, bat: 60, props: {'status': 'off', 'power': '', 'load_power': 0.0}>
<Subdevice AqaraWaterLeak: lumi.158d00035ab657, model: SJCGQ11LM, zigbee: lumi.sensor_wleak.aq1, fw: 4, bat: 60, props: {}>
<Subdevice Plug: lumi.158d00025856ca, model: ZNCZ02LM, zigbee: lumi.plug, fw: 1, bat: 60, props: {'status': 'off', 'power': '', 'load_power': 0.0}>
<Subdevice SensorHT: lumi.158d00034f7a0b, model: RTCGQ01LM, zigbee: lumi.sensor_ht, fw: 2, bat: 60, props: {'temperature': 26.89, 'humidity': 73.82, 'pressure': 0.0}>
<Subdevice Plug: lumi.158d0002677318, model: ZNCZ02LM, zigbee: lumi.plug, fw: 1, bat: 60, props: {'status': 'on', 'power': '', 'load_power': 107.19}>
<Subdevice AqaraWaterLeak: lumi.158d00035ab56a, model: SJCGQ11LM, zigbee: lumi.sensor_wleak.aq1, fw: 4, bat: 60, props: {}>
<Subdevice SensorHT: lumi.158d0003502737, model: RTCGQ01LM, zigbee: lumi.sensor_ht, fw: 2, bat: 60, props: {'temperature': 26.85, 'humidity': 64.75, 'pressure': 0.0}>
{'status': 'on', 'power': '', 'load_power': 107.19}
{'status': 'on', 'power': '', 'load_power': 107.19}
@miway80 thanks for the information.
Your test script is missing a plug_test.update()
between trying to turn it off and printing the status again.
So the script schould be:
gateway = Gateway("10.100.102.7", "token")
gateway.discover_devices()
devices = gateway.devices
for dev in devices.values():
dev.update()
print(dev)
plug_test = devices['lumi.158d0002677318']
print(plug_test.status)
print(plug_test.off())
time.sleep(5)
plug_test.update()
print(plug_test.status)
@miway80 You can also try replacing "toggle_ctrl_neutral"
with "toggle_plug"
in the control commands and/or change "channel_0"
with "neutral_0"
.
If those all don't work in the combinations that you can come up with, you will have to use bluestack to sniff the commands while turning on/off the plug and see what the exact commands are....
@miway80 You can also try replacing
"toggle_ctrl_neutral"
with"toggle_plug"
in the control commands and/or change"channel_0"
with"neutral_0"
.If those all don't work in the combinations that you can come up with, you will have to use bluestack to sniff the commands while turning on/off the plug and see what the exact commands are....
Hi,
so toggling is working with toggle_plug
and not with toggle_ctrl_neutral
.
I'm running my python scripts over pycharm and by hitting "run" the toggling doesn't work, while in debug mode it is working.
@wuid24 to be sure, it works with return self.send_arg("toggle_plug", ["channel_0", "toggle"]).pop()
right?
I added the commands in this PR: https://github.com/rytilahti/python-miio/pull/737/files
I just use python 3.7.1 and command line, so I don't know how pycharm works....
Please do update
Will this command be true for the latest update in venv?
pip install -e git+https://github.com/rytilahti/python-miio.git#egg=python-miio
pip install -e git+https://github.com/rytilahti/python-miio.git#egg=python-miio
I think so, but you can just try and then check if the gateway.py file looks the same right? (There have been a lot of changes since the last release so the diffrence schould be easy to spot).
just use python 3.7.1 and command line, so I don't know how pycharm works....
@starkillerOG sorry for the late response, busy weekend... pasted the modified lines which works for toggle,on,off commands:
@command()
def toggle(self):
"""Toggle Plug."""
# return self.send_arg("toggle_ctrl_neutral", ["channel_0", "toggle"]).pop()
return self.send_arg("toggle_plug", ["channel_0", "toggle"]).pop()
@command()
def on(self):
"""Turn on Plug."""
return self.send_arg("toggle_plug", ["channel_0", "on"]).pop()
@command()
def off(self):
"""Turn off Plug."""
return self.send_arg("toggle_plug", ["channel_0", "off"]).pop()
@wuid24 thanks for confirming. The correct commands have already been merged and are included in the latest unreleased version.
just to report an error: https://community.home-assistant.io/t/xiaomi-gateway-alarm/213638/3
when it will be possible to access the new platform via cloud for xiaomi gateways?
Hi guys,
I am starting with python, I already have token and the gateway ip but I don't know how to start my code, can somebody send me a example or explain me how can i access my gateway and see zigbee devices?
I found it, but i dont know how can i put token and ip and read zigbee goods, for example controller my Plug = 11
Thanks in advance