Xiaomi Smart Socket Plug WiFi

Others (MiLight, Hue, Toon etc...)

Moderator: leecollings

Post Reply
juzx
Posts: 16
Joined: Thursday 23 March 2017 14:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Xiaomi Smart Socket Plug WiFi

Post by juzx »

Since there are more people trying to get this working and the Xiaomi main threat was getting floated I decided to make a dedicated topic to hopefully solve this issue to get the Xiaomi Smart Socket Plug WiFi working in Domoticz.

Running nmap gave me the following info
Running: iRobot embedded
OS CPE: cpe:/h:irobot:roomba_980
OS details: iRobot Roomba 980 vacuum cleaner

A wifi access point (open) is used to configure the device out of box
UDP Port 5353 is open (ZeroConf)
UDP Port 54321 is open to receive switch commands

Switch 'On' and 'Off' and 'Status' commands appear to be send as a UDP packet with a data payload.

I tried the same Method as Sevift did with the Vacuum Cleaner. I think indeed they use some sort of same way of communication. My results so far with the BlueStacks > WireShark > PacketSender method.

It looks like the socket is working with some kind of handshake method where 2 packages are sent and two are received.

If you try to turn on the socket from the App it always sents the following message
21310020ffffffffffffffffffffffffffffffffffffffffffffffffffffffff

The answer on this message changes. It seems that there is some sort of counter in it. Below are 3 different responses from 3 different tries. You see a pattern that the first part is always the same and the last part. Only the middle part changes.

213100200000000003499f5d000 17 d5d 716ef1302435d69990f86a8c784db01f

213100200000000003499f5d000 18 3da 716ef1302435d69990f86a8c784db01f

213100200000000003499f5d000 18 4b1 716ef1302435d69990f86a8c784db01f

After this the app sents the following messages (again 3, also the 3 responses from the received signals from above). Here you also see a pattern. It uses the first part of the received message and then adds something probably encrypted?

213100600000000003499f5d000 17 d5d d531bc1c897ebfb15f5341678a6d0eba34cb5514fc89cb573d80d9617e9cf0e23ccf9685f7415287c2149336f51211ba817d8101670106990945d6daf0630546f6f42ab4547f92ef4f0aed6f78dc7ffb

213100600000000003499f5d000 18 3da 6315570f8702ce010b9d9562093474b660e38047a77a80588dee67ca90326f4586c1aad9f4e434c6083408e3211dad488c5509e04b6cbddc398bd95da60396c9edf821d224b951aa40f1a59a71f5ead5

213100600000000003499f5d000 18 4b1 aa2db754bec96fdd156abe56a2e2cfbecff67a91c17e502e744a72928bb1130def5e7be78e04c24921dfdf65a91514e070984b09a8a5f4b8e09903d64303a7a5dedea888a2a1137edee2f1051cddb795

After this you receive another package from the socket but this is probably not necessary to decrypt for now since it is the confirmation

I think the vacuumcleaner, air purifier and the wifi wall socket all use the same method of communication.

Someone who got experience with this kind of decrypthing?
juzx
Posts: 16
Joined: Thursday 23 March 2017 14:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi Smart Socket Plug WiFi

Post by juzx »

For the people interested, there is progress.

The communication protocol used, miio
https://github.com/aholstenson/miio

Homebridge implementation
https://github.com/Bluebie/homebridge-miio
ToneStrife
Posts: 20
Joined: Sunday 16 April 2017 17:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi Smart Socket Plug WiFi

Post by ToneStrife »

So it will be possible?

Anything I can do to test? I have to of them.

Do you it will be able to make the xiaomi IR blaster work too?
juzx
Posts: 16
Joined: Thursday 23 March 2017 14:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi Smart Socket Plug WiFi

Post by juzx »

It is working for me with Homebridge and the Homebridge-miio plugin. So it is definitely working but there is no Domoticz plugin yet.

These WiFi plugs are ideal now since you don't need the gateway and are not depending on anything from Xiaomi anymore since there is direct communication to the plug.
ToneStrife
Posts: 20
Joined: Sunday 16 April 2017 17:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi Smart Socket Plug WiFi

Post by ToneStrife »

So, sorry for my ignorance hehe. What is exactly Homebridge? Is there anyway that-domoticz hombridge can communicate.
juzx
Posts: 16
Joined: Thursday 23 March 2017 14:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi Smart Socket Plug WiFi

Post by juzx »

https://github.com/nfarina/homebridge

Simulates that your stuff is HomeKit licensed
ToneStrife
Posts: 20
Joined: Sunday 16 April 2017 17:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi Smart Socket Plug WiFi

Post by ToneStrife »

Thanks, so I have installed HomeBridge and the HomeBridge plugin for Domoticz.
My Hombridge config.json file is

Code: Select all

{
    "bridge": {
        "name": "Homebridge",
        "username": "CC:21:3E:E4:DE:33",
        "port": 51826,
        "pin": "031-45-154"
    },
    "description": "Configuration file for (e)xtended Domoticz platform.",
    "platforms": [
        {
            "platform": "eDomoticz",
            "name": "eDomoticz",
            "server": "127.0.0.1",
            "port": "8080",
            "ssl": 0,
            "roomid": 4,
            "mqtt": 1
        },
    {
      "platform" : "XiaomiMiio",
      "name" : "XiaomiMiio",
      "pollChanges": true,
      "pollInterval": 15
    }
    ],
    "accessories": []
}
But now I don't know what to do. I don't have an apple device to control Homekit. Is there anything I can do?
ToneStrife
Posts: 20
Joined: Sunday 16 April 2017 17:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi Smart Socket Plug WiFi

Post by ToneStrife »

Ok. Now I have follow the isntructions to Add and configure the device to miio. My next thing is to configure it in domoticz. Any advice?
juzx
Posts: 16
Joined: Thursday 23 March 2017 14:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi Smart Socket Plug WiFi

Post by juzx »

Homebridge is ONLY for Apple devices. Like I said before it simulates HomeKit for your iPad or iPhone.

The way you want to use it doesn't work. Homebridge uses information from DOmoticz, not the other way around. So you can control Domoticz with homebridge, but not homebridge with Domoticz.
juzx
Posts: 16
Joined: Thursday 23 March 2017 14:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi Smart Socket Plug WiFi

Post by juzx »

You can get the WiFi wallplugs working with the same method as the air purifier. See topic viewtopic.php?f=56&t=15537

I have it working now. There is some on/off switching delay but yes it is working.
Wob76
Posts: 110
Joined: Wednesday 19 April 2017 6:31
Target OS: Linux
Domoticz version:
Contact:

Re: Xiaomi Smart Socket Plug WiFi

Post by Wob76 »

Just looking at this, I have found a nodered module that will talk to the wifi plug, as well as the gateway and associated devices, since the gateway has native domoticz support you don't really need any of that.

I have MQTT and nodered working for my AC, so it is an easier route for me, I did a quick test with inject buttons and it turns on and off fine, fairly quickly too, just need to put the MQTT done from domoticz as the input and translate the associated dummy switch to a ON\OFF payload.

Anyway here it is for anyone wanting to go that path.
https://flows.nodered.org/node/node-red ... mi-devices

He also states the wifi code is taken from the miio code on github, if someone smarter than me can build that into Domoticz it would be great.
https://github.com/aholstenson/miio

Wob
Diab
Posts: 3
Joined: Thursday 20 April 2017 8:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: Xiaomi Smart Socket Plug WiFi

Post by Diab »

Hi Wob.
I'm quite familiar with MQTT but just learned about Nodered that is recently implemented on my PI. Can you share the module you are speaking about?
I know the address and the token of my devices but I'm not able to capture packets in order to broadcast Wifi messages towards sockets? Isn't there any other solution?
Thanks for your help.
Diab
goshi0
Posts: 6
Joined: Sunday 31 December 2017 17:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi Smart Socket Plug WiFi

Post by goshi0 »

Hi just found an easy way to control this plugs, only to change state, without Matt and nodered, only installing python miio and creating a script in the on /off section of the switch Wich call :

Code: Select all

miplug --ip <here goes plug ip> --token <here goes the plug token> on 
To obtain the IP and token just :

Code: Select all

mirobo discover
I am trying to make work the ir remote but without success.
renedis
Posts: 1
Joined: Wednesday 22 June 2016 12:01
Target OS: Linux
Domoticz version:
Contact:

Re: Xiaomi Smart Socket Plug WiFi

Post by renedis »

You need to install https://github.com/aholstenson/miio

after that you need to do a discovery:
sudo miio discover

Or:
sudo mirobo --discover


Commando to read internal temperature (if available):
sudo mirobo --ip PLUGORPWRSTRIP-IP --token TOKEN raw_command get_prop '["temperature"]' | tail -1 | awk '{print substr($0, 2, length($0) - 2)}'

Commando to read current wattage usage (if available):
sudo mirobo --ip PLUGORPWRSTRIP-IP --token TOKEN raw_command get_prop '["power_consume_rate"]' | tail -1 | awk '{print substr($0, 2, length($0) - 2)}'

Commando to turn on:
sudo mirobo --ip PLUGORPWRSTRIP-IP --token TOKEN raw_command set_power '["on"]'

Or:
sudo miplug --ip PLUGORPWRSTRIP-IP --token TOKEN on

Commando to turn off:
sudo mirobo --ip PLUGORPWRSTRIP-IP --token TOKEN raw_command set_power '["off"]'

Or:
sudo miplug --ip PLUGORPWRSTRIP-IP --token TOKEN off
User avatar
fubar
Posts: 14
Joined: Friday 19 January 2018 3:44
Target OS: Linux
Domoticz version: beta
Location: Sydney
Contact:

Re: Xiaomi Smart Socket Plug WiFi

Post by fubar »

An update for anyone interested in the xiaomi mi plug mini wifi version. It has the big advantage that once set up, you don't need to put it within range of a xiaomi aqara gateway - it can be anywhere your local wifi network will reach.

The miio project is now available as python-miio http://python-miio.readthedocs.io/en/latest/

I could not get the CLI to work with the old M1 model I got cheaply from gearbest - I updated the firmware as soon as I got it via the awful mihome app and that may have been a mistake as xiaomi sometimes upgrade the firmware to make it harder to use the device outside their ecosystem. Ain't capitalism grand?

Fortunately the classes work fine when called directly in python, so I can switch on and off with some tiny python scripts - use:

Code: Select all

miio discover
to learn the token and ip for your device, then create a text file something like:

Code: Select all

#!/usr/bin/python3
import miio

good = {'ok'}
foo = miio.chuangmi_plug.ChuangmiPlug(ip="your device ip",debug=1,token="your device token")
res = foo.on()
# want to be able to rely on a non-zero exit to indicate failure to the calling script..
if res==good:
    exit(0)
else:
    exit(1)

seems to do the needful.

use foo.off() in a copy of the above script to turn it off.
foo.status() can be used to get the status including temperature and power for printing if they're available.
Mine shows:
<ChuangmiPlugStatus power=False, usb_power=None, temperature=40load_power=None, wifi_led=None>

I'll update here when I get these little scripts working in domoticz - I want to be able to control a heater...
ruchita
Posts: 1
Joined: Wednesday 13 March 2019 11:08
Target OS: Linux
Domoticz version:
Contact:

Re: Xiaomi Smart Socket Plug WiFi

Post by ruchita »

It is working for me with Homebridge and the Homebridge-miio module. So it is unquestionably working yet there is no Domoticz module yet.

These WiFi plugs are perfect now since you needn't bother with the passage and are not relying upon anything from Xiaomi any longer since there is immediate correspondence to the fitting.
Mazur
Posts: 3
Joined: Friday 01 November 2019 13:47
Target OS: Windows
Domoticz version:
Contact:

Re: Xiaomi Smart Socket Plug WiFi

Post by Mazur »

Hello! Please tell me how to do it on windows ?
rippe
Posts: 7
Joined: Monday 07 October 2019 18:33
Target OS: Windows
Domoticz version:
Contact:

Re: Xiaomi Smart Socket Plug WiFi

Post by rippe »

Yes, as Mazur said, Any way of doing this in Windows. Some time has passed since the last comment so I'm hoping that something happened in this area.

Best regards,
Richard
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest