miio icon indicating copy to clipboard operation
miio copied to clipboard

No event emmited for gateway subdevices

Open Mathieu2301 opened this issue 4 years ago • 1 comments

I have 2 door sensor, 1 movement sensor and 1 thermometer but I can't listen to any event from them. Moreover, the door sensor always says that the door is open and the movement sensor that there is no movement. I configurated them with Xiaomi Home,

When I try :

miio.device({
	address: '192.168.1.36', token: 'c9d5c9d3f8fa70810bcd88d60a01d762'
}).then(device => {
	console.log('Connected to device');
	console.log(device);

	if(device && device.matches('type:miio:gateway')) {
		const children = device.children();
		for(const child of children) {
			if(child.matches('type:miio:subdevice') && child.matches('cap:contact')) {
				console.log('magnet');
				child.on('opened', () => console.log("opened"));
				child.on('closed', () => console.log("opened"));
				child.isOpen().then((o) => console.log('o:' + o));
			}
		}
	}
}).catch(err => console.log('Error occurred:', err));

I get this :

  thing:miio:pending Using manual token: c9d5c9d3f8fa70810bcd88d60a01d762 +0ms
  thing:miio:pending <- Handshake reply: <Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00> +12ms
  thing:miio:275201436 Identifier of device updated +0ms
  thing:miio:275201436 -> (5) {"method":"miIO.info","params":[],"id":1} +3ms
  thing:miio:275201436 <- Message: `{"result":{"life":4914,"cfg_time":0,"token":"c9d5c9d3f8fa70810bcd88d60a01d762","mac":"50:EC:50:C5:3C:0B","fw_ver":"1.4.1_170","hw_ver":"MW300","model":"lumi.gateway.v3","mcu_fw_ver":"0158","wifi_fw_ver":"SD878x-14.76.36.p84-702.1.0-WM","ap":{"rssi":-49,"ssid":"freebox_COLMON","bssid":"70:FC:8F:EE:D7:90"},"netif":{"localIp":"192.168.1.36","mask":"255.255.255.0","gw":"192.168.1.254","gw_mac":"70:FC:8F:51:9C:EE"},"mmfree":171888,"ot":"otu","otu_stat":[328,362,564,34,530,402],"ott_stat":[0, 0, 0, 0]},"id":1}` +17ms
  thing:miio:275201436 -> (5) {"method":"get_prop","params":["illumination","rgb"],"id":2} +4ms
  thing:miio:275201436 <- Message: `{"result":[307,0],"id":2}` +6ms
  thing:miio:275201436 Property illuminance changed from undefined to 307 +0ms
  thing:miio:275201436 Property rgb changed from undefined to { red: 0, green: 0, blue: 0 } +1ms
  thing:miio:275201436 Property brightness changed from undefined to 0 +1ms
  thing:miio:275201436 -> (5) {"method":"get_lumi_dpf_aes_key","params":[],"id":3} +3ms
  thing:miio:275201436 <- Message: `{"result":["oq3tb276vefbeboe"],"id":3}` +16ms
  thing:miio:275201436 DEV BROADCAST -> {"cmd":"whois"} +24ms
  thing:miio:275201436 DEV <- Timeout for whois +1s
  thing:miio:275201436 -> (5) {"method":"get_device_prop","params":["lumi.0","device_list"],"id":4} +1s
  thing:miio:275201436 <- Message: `{"result":["lumi.158d0003cd7340",10,1,0,2,"lumi.158d00044c567a",2,1,0,11,"lumi.158d0003f87dd9",3,1,0,10,"lumi.158d0003f37b72",3,1,0,10],"id":4}` +41ms
  thing:miio:275201436 DEV -> {"cmd":"read","sid":"158d0003cd7340"} +46ms
  thing:miio:275201436 DEV -> {"cmd":"read","sid":"158d00044c567a"} +1ms
  thing:miio:275201436 DEV -> {"cmd":"read","sid":"158d0003f87dd9"} +1ms
  thing:miio:275201436 DEV -> {"cmd":"read","sid":"158d0003f37b72"} +0ms
  thing:miio:158d0003cd7340 Read via DEV timed out, using fallback API +0ms
  thing:miio:158d00044c567a Read via DEV timed out, using fallback API +0ms
  thing:miio:275201436 -> (5) {"method":"get_device_prop_exp","params":[["lumi.158d0003cd7340","temperature","humidity"]],"id":5} +1s
  thing:miio:275201436 -> (5) {"method":"get_device_prop_exp","params":[["lumi.158d00044c567a","voltage"]],"id":6} +0ms
  thing:miio:158d0003f87dd9 Read via DEV timed out, using fallback API +0ms
  thing:miio:158d0003f37b72 Read via DEV timed out, using fallback API +0ms
  thing:miio:275201436 -> (5) {"method":"get_device_prop_exp","params":[["lumi.158d0003f87dd9","voltage","status"]],"id":7} +3ms
  thing:miio:275201436 -> (5) {"method":"get_device_prop_exp","params":[["lumi.158d0003f37b72","voltage","status"]],"id":8} +0ms
  thing:miio:275201436 <- Message: `{"result":[[1967,5156]],"id":5}` +52ms
  thing:miio:158d0003cd7340 Property temperature changed from undefined to 19.67 +57ms
  thing:miio:158d0003cd7340 Property humidity changed from undefined to 51.56 +2ms
  thing:miio:275201436 <- Message: `{"result":[[]],"id":6}` +10ms
  thing:miio:275201436 <- Message: `{"result":[[,]],"id":7}` +19ms
  thing:miio:275201436 <- Message: `{"result":[[,]],"id":8}` +15ms
Connected to device
MiioDevice {
  model=lumi.gateway.v3,
  types=sensor, miio:gateway, miio,
  capabilities=illuminance, state, children
}
magnet
magnet
o:true
o:true

Actually, the first door is closed and the second is open.

For the temperature I use :

d.values().then(val => {
    console.log('Temperature:', val.temperature.celsius+'°C');
    console.log('Humidity:', val.relativeHumidity+'%');
});

And it's working ! But when i try to listen to the event like that :

d.on('temperatureChanged', e => console.log("temperatureChanged", e));
d.on('relativeHumidityChanged', e => console.log("relativeHumidityChanged", e));
d.on('stateChanged', e => console.log("stateChanged", e));

Then I get NOTHING 😞

(I tried these scripts on Windows 10 and on Ubuntu 19.04)

Thanks 👍

Mathieu2301 avatar Nov 30 '19 23:11 Mathieu2301

I tried with "0.15-fixes" branch and I get same results...

Please help !

Mathieu2301 avatar Dec 23 '19 14:12 Mathieu2301