openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.88k stars 3.59k forks source link

[mihome] Add Support for Xiaomi Aqara Smart Wall Socket (86plug) #4511

Closed git4pbp closed 5 years ago

git4pbp commented 5 years ago

Binding: mihome-2.5.0-SNAPSHOT.jar OpenHAB 2.4 Raspberry Jessy

@dimalo

This device is not supported by the binding but it can be added to OpenHAB configuration using Basic Xiaomi MiHome Device configuration.

here some traces: {"cmd":"report","model":"ctrl_86plug.aq1","sid":"158d000201017c","short_id":34496,"data":"{\"status\":\"on\"}"} {"cmd":"report","model":"ctrl_86plug.aq1","sid":"158d000201017c","short_id":34496,"data":"{\"status\":\"off\"}"} {"cmd":"heartbeat","model":"ctrl_86plug.aq1","sid":"158d000201017c","short_id":34496,"data":"{\"voltage\":3600,\"status\":\"off\",\"inuse\":\"0\",\"power_consumed\":\"23\",\"load_power\":\"0.00\"}"}

This is my second issue, so I would like to thank all the OpenHAB team for the excellent work and support available on the web.

dimalo commented 5 years ago

You're welcome, sir! If you add it as a basic device can you copy the output of all channels, as soon as they have values? For write_ack of course you have to send a command to it... 😄 Just want to make sure we don't miss any info. Thanks!

dimalo commented 5 years ago

For the time being, if there is no new info the plug sends I added it to the models. It's just two lines as there is already a plug device implemented 👍

cweitkamp commented 5 years ago

@github4pbp Are you able to test the changes in #4512?

git4pbp commented 5 years ago

@cweitkamp @dimalo

Tested with org.openhab.binding.mihome-2.5.0-SNAPSHOT.jar 04-Jan-2019 15:25 96.36 KB

Unfortunately auto discovery still report it as Unsupported Xiaomi MiHome Device "ctrl_86plug.aq1"

prt_scr

==> /var/log/openhab2/events.log <== 2019-01-04 20:05:41.062 [ome.event.ItemCommandEvent] - Item '86_Socket' received command ON 2019-01-04 20:05:41.072 [nt.ItemStatePredictedEvent] - 86_Socket predicted to become ON 2019-01-04 20:05:41.085 [vent.ItemStateChangedEvent] - 86_Socket changed from OFF to ON

==> /var/log/openhab2/openhab.log <== 2019-01-04 20:05:41.074 [DEBUG] [rnal.handler.XiaomiDeviceBaseHandler] - Device 158d000201017c on channel mihome:sensor_plug:158d000201017c:power received command ON 2019-01-04 20:05:41.093 [DEBUG] [internal.handler.XiaomiBridgeHandler] - Send to bridge mihome:bridge:7811dcxxxxxx: {"cmd": "write", "sid": "158d000201017c", "data": "{\"status\": \"on\", \"key\": \"BF33BDB4BD800C3CF5BD1397AFD1B16B\"}"} 2019-01-04 20:05:41.097 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Sending message: {"cmd": "write", "sid": "158d000201017c", "data": "{\"status\": \"on\", \"key\": \"BF33BDB4BD800C3CF5BD1397AFD1B16B\"}"} to /192.168.1.6:9898 2019-01-04 20:05:41.108 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.1.6:9898 on Port 9898 2019-01-04 20:05:41.112 [TRACE] [internal.handler.XiaomiBridgeHandler] - Received message {"cmd":"write_ack","model":"ctrl_86plug.aq1","sid":"158d000201017c","short_id":34496,"data":"{\"voltage\":3600,\"status\":\"off\",\"inuse\":\"0\",\"power_consumed\":\"23\",\"load_power\":\"0.00\"}"} 2019-01-04 20:05:41.116 [TRACE] [internal.handler.XiaomiBridgeHandler] - Updated "last time seen" for device 158d000201017c 2019-01-04 20:05:41.127 [DEBUG] [internal.handler.XiaomiBridgeHandler] - Cancelled running timer 2019-01-04 20:05:41.131 [DEBUG] [internal.handler.XiaomiBridgeHandler] - Device 158d000201017c honored write request 2019-01-04 20:05:41.134 [DEBUG] [rnal.handler.XiaomiDeviceBaseHandler] - Item got update: {"cmd":"write_ack","model":"ctrl_86plug.aq1","sid":"158d000201017c","short_id":34496,"data":"{\"voltage\":3600,\"status\":\"off\",\"inuse\":\"0\",\"power_consumed\":\"23\",\"load_power\":\"0.00\"}"} 2019-01-04 20:05:41.143 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners 2019-01-04 20:05:41.146 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-3418,5,main] waiting for data on port 9898

==> /var/log/openhab2/events.log <== 2019-01-04 20:05:41.148 [vent.ItemStateChangedEvent] - 86_Socket changed from ON to OFF

==> /var/log/openhab2/openhab.log <== 2019-01-04 20:05:41.200 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.1.6:4321 on Port 9898 2019-01-04 20:05:41.202 [TRACE] [internal.handler.XiaomiBridgeHandler] - Received message {"cmd":"report","model":"ctrl_86plug.aq1","sid":"158d000201017c","short_id":34496,"data":"{\"status\":\"on\"}"} 2019-01-04 20:05:41.204 [TRACE] [internal.handler.XiaomiBridgeHandler] - Updated "last time seen" for device 158d000201017c 2019-01-04 20:05:41.207 [DEBUG] [internal.handler.XiaomiBridgeHandler] - Cancelled running timer 2019-01-04 20:05:41.211 [DEBUG] [rnal.handler.XiaomiDeviceBaseHandler] - Item got update: {"cmd":"report","model":"ctrl_86plug.aq1","sid":"158d000201017c","short_id":34496,"data":"{\"status\":\"on\"}"} 2019-01-04 20:05:41.214 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners 2019-01-04 20:05:41.216 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-3418,5,main] waiting for data on port 9898

==> /var/log/openhab2/events.log <== 2019-01-04 20:05:41.220 [vent.ItemStateChangedEvent] - 86_Socket changed from OFF to ON

==> /var/log/openhab2/openhab.log <== 2019-01-04 20:05:41.291 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.1.6:4321 on Port 9898 2019-01-04 20:05:41.293 [TRACE] [internal.handler.XiaomiBridgeHandler] - Received message {"cmd":"heartbeat","model":"gateway","sid":"7811dcxxxxxx","short_id":"0","token":"ccH1IvSMdQXERXNq","data":"{\"ip\":\"192.168.1.6\"}"} 2019-01-04 20:05:41.295 [TRACE] [internal.handler.XiaomiBridgeHandler] - Updated "last time seen" for device 7811dcxxxxxx 2019-01-04 20:05:41.298 [DEBUG] [internal.handler.XiaomiBridgeHandler] - Cancelled running timer 2019-01-04 20:05:41.301 [DEBUG] [discovery.XiaomiItemDiscoveryService] - Detected Xiaomi smart device - sid: 7811dcxxxxxx model: gateway 2019-01-04 20:05:41.305 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners 2019-01-04 20:05:41.307 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-3418,5,main] waiting for data on port 9898 2019-01-04 20:05:51.285 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.1.6:4321 on Port 9898 2019-01-04 20:05:51.288 [TRACE] [internal.handler.XiaomiBridgeHandler] - Received message {"cmd":"heartbeat","model":"gateway","sid":"7811dcxxxxxx","short_id":"0","token":"7sOabTGkiZcEsXw0","data":"{\"ip\":\"192.168.1.6\"}"} 2019-01-04 20:05:51.291 [TRACE] [internal.handler.XiaomiBridgeHandler] - Updated "last time seen" for device 7811dcxxxxxx 2019-01-04 20:05:51.299 [DEBUG] [internal.handler.XiaomiBridgeHandler] - Cancelled running timer 2019-01-04 20:05:51.304 [DEBUG] [discovery.XiaomiItemDiscoveryService] - Detected Xiaomi smart device - sid: 7811dcxxxxxx model: gateway 2019-01-04 20:05:51.310 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners 2019-01-04 20:05:51.313 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-3418,5,main] waiting for data on port 9898

==> /var/log/openhab2/events.log <== 2019-01-04 20:05:51.935 [ome.event.ItemCommandEvent] - Item '86_Socket' received command OFF 2019-01-04 20:05:51.943 [nt.ItemStatePredictedEvent] - 86_Socket predicted to become OFF

==> /var/log/openhab2/openhab.log <== 2019-01-04 20:05:51.943 [DEBUG] [rnal.handler.XiaomiDeviceBaseHandler] - Device 158d000201017c on channel mihome:sensor_plug:158d000201017c:power received command OFF 2019-01-04 20:05:51.949 [DEBUG] [internal.handler.XiaomiBridgeHandler] - Send to bridge mihome:bridge:7811dcxxxxxx: {"cmd": "write", "sid": "158d000201017c", "data": "{\"status\": \"off\", \"key\": \"E8D80CACCA06A1154AD1775D44682768\"}"}

==> /var/log/openhab2/events.log <== 2019-01-04 20:05:51.963 [vent.ItemStateChangedEvent] - 86_Socket changed from ON to OFF

==> /var/log/openhab2/openhab.log <== 2019-01-04 20:05:51.960 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Sending message: {"cmd": "write", "sid": "158d000201017c", "data": "{\"status\": \"off\", \"key\": \"E8D80CACCA06A1154AD1775D44682768\"}"} to /192.168.1.6:9898 2019-01-04 20:05:51.974 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.1.6:9898 on Port 9898 2019-01-04 20:05:51.978 [TRACE] [internal.handler.XiaomiBridgeHandler] - Received message {"cmd":"write_ack","model":"ctrl_86plug.aq1","sid":"158d000201017c","short_id":34496,"data":"{\"voltage\":3600,\"status\":\"on\",\"inuse\":\"0\",\"power_consumed\":\"23\",\"load_power\":\"0.00\"}"} 2019-01-04 20:05:51.982 [TRACE] [internal.handler.XiaomiBridgeHandler] - Updated "last time seen" for device 158d000201017c 2019-01-04 20:05:51.991 [DEBUG] [internal.handler.XiaomiBridgeHandler] - Cancelled running timer 2019-01-04 20:05:51.995 [DEBUG] [internal.handler.XiaomiBridgeHandler] - Device 158d000201017c honored write request 2019-01-04 20:05:51.998 [DEBUG] [rnal.handler.XiaomiDeviceBaseHandler] - Item got update: {"cmd":"write_ack","model":"ctrl_86plug.aq1","sid":"158d000201017c","short_id":34496,"data":"{\"voltage\":3600,\"status\":\"on\",\"inuse\":\"0\",\"power_consumed\":\"23\",\"load_power\":\"0.00\"}"} 2019-01-04 20:05:52.004 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners 2019-01-04 20:05:52.006 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-3418,5,main] waiting for data on port 9898

==> /var/log/openhab2/events.log <== 2019-01-04 20:05:52.008 [vent.ItemStateChangedEvent] - 86_Socket changed from OFF to ON

==> /var/log/openhab2/openhab.log <== 2019-01-04 20:05:52.075 [DEBUG] [.mihome.internal.socket.XiaomiSocket] - Received Datagram from 192.168.1.6:4321 on Port 9898 2019-01-04 20:05:52.077 [TRACE] [internal.handler.XiaomiBridgeHandler] - Received message {"cmd":"report","model":"ctrl_86plug.aq1","sid":"158d000201017c","short_id":34496,"data":"{\"status\":\"off\"}"} 2019-01-04 20:05:52.079 [TRACE] [internal.handler.XiaomiBridgeHandler] - Updated "last time seen" for device 158d000201017c 2019-01-04 20:05:52.081 [DEBUG] [internal.handler.XiaomiBridgeHandler] - Cancelled running timer 2019-01-04 20:05:52.084 [DEBUG] [rnal.handler.XiaomiDeviceBaseHandler] - Item got update: {"cmd":"report","model":"ctrl_86plug.aq1","sid":"158d000201017c","short_id":34496,"data":"{\"status\":\"off\"}"} 2019-01-04 20:05:52.088 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Data received and notified 1 listeners 2019-01-04 20:05:52.090 [TRACE] [.mihome.internal.socket.XiaomiSocket] - Thread Thread[Thread-3418,5,main] waiting for data on port 9898

==> /var/log/openhab2/events.log <== 2019-01-04 20:05:52.094 [vent.ItemStateChangedEvent] - 86_Socket changed from ON to OFF

git4pbp commented 5 years ago

You're welcome, sir! If you add it as a basic device can you copy the output of all channels, as soon as they have values? For write_ack of course you have to send a command to it... 😄 Just want to make sure we don't miss any info. Thanks!

Sure! Here what I've got when using the following item (text file) configuration: Switch sw "86_Socket" {channel="mihome:sensor_plug:158d000201017c:power"}

initially the socket was off and I have turned it ON (without power load)

reportMessage: {"status":"on"} heartbeatMessage: {"voltage":3600,"status":"off","inuse":"0","power_consumed":"23","load_power":"0.00"} readAckMessage: {"voltage":3600,"status":"off","inuse":"0","power_consumed":"23","load_power":"0.00"} writeAckMessage: {"voltage":3600,"status":"off","inuse":"0","power_consumed":"23","load_power":"0.00"} lastMessage:{"cmd":"report","model":"ctrl_86plug.aq1","sid":"158d000201017c","short_id":34496,"data":"{\"status\":\"on\"}"} writeMessage: NULL

then after 10 seconds i have turned it OFF

reportMessage: {"status":"off"} heartbeatMessage: {"voltage":3600,"status":"off","inuse":"0","power_consumed":"23","load_power":"0.00"} readAckMessage: {"voltage":3600,"status":"off","inuse":"0","power_consumed":"23","load_power":"0.00"} writeAckMessage: {"voltage":3600,"status":"on","inuse":"0","power_consumed":"23","load_power":"0.00"} lastMessage:{"cmd":"report","model":"ctrl_86plug.aq1","sid":"158d000201017c","short_id":34496,"data":"{\"status\":\"off\"}"} writeMessage: NULL

Also during the tests I can see clearly in Mi Home App that socket was turned ON and then switched OFF.

dimalo commented 5 years ago

Thanks @github4pbp! There is no new data the plug sends, so the old implementation can be used. Please make suer you have that change in the snapshot version, I'm pretty sure it should work - even if it doesn't look like that in your tests. If you look here and here it has worked with other models as well.

git4pbp commented 5 years ago

Tested with the latest snapshot version and everything is working as designed with no issues.

One suggestion - the new plug should be recognized as Xiaomi Aqara Smart Wall Socket instead Xiaomi Aqara Smart Socket Plug socket

and as well should be added to the binding supported things (ctrl_86plug.aq1) here: sc

@dimalo Thank you very much!

roha999 commented 5 years ago

hi i install Binding: mihome-2.5.0-SNAPSHOT.jar , 209 │ Active │ 80 │ 2.5.0.201902140720 │ Xiaomi Mi Smart Home Binding

restart openhab but still get Unsupported Xiaomi MiHome Device "86plug" Basic Xiaomi MiHome Device (http://prntscr.com/mo9d3y)

what i am doing wrong?

git4pbp commented 5 years ago

@roha999

try using configuration files and it should work. Example for things:

Thing mihome:sensor_plug:158d000xxxxxxx "Aqara Socket Plug" @ "Kitchen" [item Id="158d000xxxxxxx"]

roha999 commented 5 years ago

try for this one "Unsupported Xiaomi MiHome Device "86plug" Basic Xiaomi MiHome Device 158d000182450a"

add a record to things file as Thing mihome:sensor_plug:158d000182450a "Aqara Socket Plug" @ "Kitchen" [itemId="158d000182450a"] and get no new device http://prntscr.com/mot8yq

git4pbp commented 5 years ago

You sould define it also as switch in items for example try creating test.items file (/etc/openhab2/items/test.items) with the following line:

Switch 86plug_test "Power socket" {channel="mihome:senso r_plug:158d000182450a:power"}

git4pbp commented 5 years ago

But first this thing should be defined as child of your gateway (hub) in things file.

As example:

Bridge mihome:bridge:7811dc64xxxx "Control hub" [serialNumber="7811dc64xxxx", ipAddress="192.168.x.x", port=9898, key="1sit7w7srrweujfd", pollingInterval= 6000] { Thing mihome:sensor_plug:158d000182450a "Aqara Socket Plug" @ "Kitchen" [itemId="158d000182450a"] }

roha999 commented 5 years ago

thanks, problem solved, forgot to link it to bridge :(

do you know can we get Power Consumed data on aqara wall switch same as on wall socket?

git4pbp commented 5 years ago

Think that this is not yet supported by the binding. There is only control channel(s) and e.g. ":powerConsumed" channel is unavailable.