Xiaomi Gateway Integration

Cheers matt. So it goes into /home/homeassistant/.homeassistant where the configuration.yaml etc is? And I obviously change "default_key=“xxxxxxxxx” to my device id?

Yep thats where you need to put the custom_components folder and inside that you’d have xiaomi.py and the other folders with sensors and switches etc…

Added my key where default_key=xxxxxx is but still not seeing the gateway in home-assistant… Config errors are gone now though!

I think the sid is more important than the key, are you using the key from in the mi home app?

yep exactly

If you need help figuring out which one goes where and where to find each one, check out my mini tutorial… shameless plug

It’s vice versa. The “key” is used for the encryption. The “sid” is just necessary if you have more than one gateway - to identify the right one.

Cheers but still no joy, gateway not appearing on home page of home-assistant :frowning:

Please enable the logger by

logger:
  default: warn
  logs:
    custom_components.xiaomi: debug
    custom_components.sensor.xiaomi: debug
    custom_components.binary_sensor.xiaomi: debug
    custom_components.light.xiaomi: debug
    custom_components.switch.xiaomi: debug

And post the content of your home-assistant.log after a restart of home assistant.

see below: (i’ve taken the links out of the IP address’s as it wouldnt let me post with them in)

cat home-assistant.log
2017-07-12 14:54:25 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/lib/python3.4/asyncio/tasks.py”, line 233, in _step
result = coro.throw(exc)
File “/usr/local/lib/python3.4/dist-packages/homeassistant/setup.py”, line 61, in async_setup_component
return (yield from task)
File “/usr/lib/python3.4/asyncio/futures.py”, line 388, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.4/asyncio/tasks.py”, line 286, in _wakeup
value = future.result()
File “/usr/lib/python3.4/asyncio/futures.py”, line 277, in result
raise self._exception
File “/usr/lib/python3.4/asyncio/tasks.py”, line 237, in _step
result = next(coro)
File “/usr/local/lib/python3.4/dist-packages/homeassistant/setup.py”, line 141, in _async_setup_component
component = loader.get_component(domain)
File “/usr/lib/python3.4/unittest/mock.py”, line 896, in call
return _mock_self._mock_call(*args, **kwargs)
File “/usr/lib/python3.4/unittest/mock.py”, line 962, in _mock_call
ret_val = effect(*args, **kwargs)
File “/usr/local/lib/python3.4/dist-packages/homeassistant/scripts/check_config.py”, line 179, in mock_get
module = MOCKS[‘get’]1
File “/usr/local/lib/python3.4/dist-packages/homeassistant/loader.py”, line 141, in get_component
module = importlib.import_module(path)
File “/usr/lib/python3.4/importlib/init.py”, line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 2254, in _gcd_import
File “”, line 2237, in _find_and_load
File “”, line 2226, in _find_and_load_unlocked
File “”, line 12017-07-12 14:54:35 WARNING (Thread-9) [netdisco.ssdp] Found malformed XML at 192.168.0.101:49153/description1.xml:
2017-07-12 14:54:35 WARNING (Thread-9) [netdisco.ssdp] Found malformed XML at 192.168.0.101:49153/description2.xml:
2017-07-12 14:54:35 WARNING (Thread-9) [netdisco.ssdp] Found malformed XML at 192.168.0.101:49153/description3.xml:
2017-07-12 14:54:35 WARNING (Thread-9) [netdisco.ssdp] Found malformed XML at 192.168.0.101:49153/description5.xml:

I don’t understand the error messages. They have nothing to do with the xiaomi component I think. If you remove the xiaomi block

xiaomi:
  gateways:
    - sid: !secret xiaomi_sid
      key: !secret xiaomi_key

does the errors disappear? I don’t think so.

Nope, exact same

one thing i was thinking, the lights were setup on the singapore server and the gateway on the chinese server. Would that matter?

What lights you are talking about? :slight_smile: The communication between the gateway and home assistant is a multicast broadcast at your local network.

I have 2 yeelights that appear on home assistant straight away.

I have another router at home that I’ll try set this up with. Maybe the VM router is blocking something on the network

Definitely looks like you have not loaded the Xiaomi component. The Yeelight uses a different component which is part of HA.

see below my configuration.yaml
Shoud the multicast address be changed in the xiaomi.py file?

Name of the location where Home Assistant is running

name: Home

Location required to calculate the time the sun rises and sets

latitude: 53.3389
longitude: -6.2595

Impacts weather/sunrise data (altitude above sea level in meters)

elevation: 0

metric for Metric, imperial for Imperial

unit_system: metric

Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones

time_zone: Europe/Dublin

Show links to resources in log and frontend

introduction:

Enables the frontend

frontend:

Enables configuration UI

config:

http:

Uncomment this to add a password (recommended!)

api_password: PASSWORD

Uncomment this if you are using SSL or running in Docker etc

base_url: example.duckdns.org:8123

Checks for available updates

Note: This component will send some information about your system to

the developers to assist with development of Home Assistant.

For more information, please see:

https://home-assistant.io/blog/2016/10/25/explaining-the-updater/

updater:

Optional, allows Home Assistant developers to focus on popular components.

include_used_components: true

Discover some devices automatically

discovery:

Allows you to issue voice commands from the frontend in enabled browsers

conversation:

Enables support for tracking state changes over time.

history:

View all events in a logbook

logbook:

Track the sun

sun:

Weather Prediction

sensor:
platform: yr

Text to speech

tts:
platform: google

group: !include groups.yaml
automation: !include automations.yaml

xiaomi:
gateways:
- sid:
key: keyfrommiapp

logger:
default: warn
logs:
custom_components.xiaomi: debug
custom_components.sensor.xiaomi: debug
custom_components.binary_sensor.xiaomi: debug
custom_components.light.xiaomi: debug
custom_components.switch.xiaomi: debug

Does your directory structure look like this?

./configuration.yaml
./home-assistant_v2.db
./known_devices.yaml
./home-assistant.log
./.HA_VERSION
./groups.yaml
./custom_components
./custom_components/switch
./custom_components/switch/xiaomi.py
./custom_components/sensor
./custom_components/sensor/xiaomi.py
./custom_components/light
./custom_components/light/xiaomi.py
./custom_components/xiaomi.py
./custom_components/binary_sensor
./custom_components/binary_sensor/xiaomi.py

Just saw you said you added the key to default_key. You DO NOT and are not supposed to do anything to the xiaomi.py files. All you have to do is copy the files to the respective location and then add the xiaomi settings to the configuration.yaml

Hopefully this will resolve it :wink:

Maybe it’s time to separate this topic into
“Xiaomi problem solving” and “Xiaomi development and news?”

As i understand rave is MIA? Code is very stable. Is there anyway to rewrite the code so there won’t be a violation of rave’s copyright and pull it as a component?

And does anybody already have a xiaomi curtain motor? Any chances of getting it into HA? Price is very sweet

And does anybody already have a xiaomi curtain motor? Any chances of getting it into HA? Price is very sweet

Someone has just added support for it:

1 Like