Xiaomi Gateway Integration

Power consumption works on Daniel brunch

Try the following:

{{states.sensor.illumination_12345.state | int}}

Already tried with “int”. Or do you mean without spaces:

- platform: numeric_state
      entity_id: sensor.illumination_12345
      value_template: '{{states.sensor.illumination_12345.state | int}}'
      above: 700

? I am currently not at home so I cannot test. I’ll report back in the evening.
Or maybe the “above”-value has to be set into quotes (above: ‘700’)? Because if I check with the templates (in the developer tools) I get the following responses:

  • ‘{{states.sensor.illumination_12345.state | int}}’ --> ‘800’
  • {{states.sensor.illumination_12345.state | int}} --> 800

But this is just an idea and might be stupid due to my lack of python skills :smiley:

1 Like

I have only the Wifi one. As far as I know the Miio-component is only supporting the vacuum robot. Although there one or two approaches in the forum I haven’t been able to find a good source for the Wifi plug.

maybe this will help Xiaomi Smart Home Integration : MiiO

I’ve been kind of working on that, yes. :slight_smile: But my knowledge of python is way to little to transfer this component to work with the Wifi plug.

Someone has been trying and apparently was successful: Xiaomi mi wifi plug & air purifier

But this the author doesn’t answer so troubleshooting is very hard. I’ve been integrating his component and currently am stuck with the following error (and furthermore I’m not even sure if I stored all his files correctly :smiley: But again - troubleshooting is hard for me):

ERROR (Thread-9) [custom_components.switch.xiaomi-plug] Got exception while fetching the state: cannot import name 'Device'

(I needed to rename his component from “xiaomi.py” to “xiaomi-plug.py”)

But I’ll continue trying. … :slight_smile:

1 Like

Did any of you make a sensor with the last trigger action as name? I guess something like

sensors:
  cube_last_action:
  value_template: '{{ states.binary_sensor.cube_158d0001135c14.attributes.last_triggered }}'

ps. this code is not working :slight_smile:

OK I have been messing around for a few days now I decided to do another reset and now I’m getting new errors.
Also is there anyway to do a full factory reset?

The following errors have been logged this session:

2017-06-03 17:52:29 ERROR (MainThread) [homeassistant.setup] Error during setup of component xiaomi
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/setup.py”, line 188, in _async_setup_component
None, component.setup, hass, processed_config)
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/concurrent/futures/thread.py”, line 54, in run
result = self.fn(*self.args, **self.kwargs)
File “/home/homeassistant/.homeassistant/custom_components/xiaomi.py”, line 75, in setup
PY_XIAOMI_GATEWAY = PyXiaomiGateway(hass, gateways, interface)
File “/home/homeassistant/.homeassistant/custom_components/xiaomi.py”, line 178, in init
self._socket.bind((interface, 0))
OSError: [Errno 99] Cannot assign requested address

EDIT
Just did a fresh install of hassbian to see if it was something I had done looks like it wasn’t, if i add in interface: [gateway ip] I get the error up above if I try without it i get

Jun 04 00:18:44 hassbian hass[735]: 2017-06-04 00:18:44 INFO (Thread-12) [custom_components.xiaomi] Gateway finding finished in 5 seconds
Jun 04 00:18:44 hassbian hass[735]: 2017-06-04 00:18:44 INFO (Thread-12) [custom_components.xiaomi] Discovering Xiaomi Gateways (Try 2)
Jun 04 00:18:49 hassbian hass[735]: 2017-06-04 00:18:49 WARNING (MainThread) [homeassistant.setup] Setup of xiaomi is taking over 10 seconds.
Jun 04 00:18:49 hassbian hass[735]: 2017-06-04 00:18:49 INFO (Thread-12) [custom_components.xiaomi] Gateway finding finished in 5 seconds
Jun 04 00:18:49 hassbian hass[735]: 2017-06-04 00:18:49 INFO (Thread-12) [custom_components.xiaomi] Discovering Xiaomi Gateways (Try 3)

Its driving me crazy trying to get this to work

EDIT2

It still works if I unplug the gayway and then restart HASS but still only for a minuet or 2, I looked at the logs just after clicks of a button stoped showing up and there was this

Jun 04 00:38:37 hassbian hass[735]: 2017-06-04 00:38:37 ERROR (Thread-11) [custom_components.xiaomi] Got error element in data {“error”:“Invalid key”}

I know the key is the same in my config as the app on my android phone.

SOLUTION
OK I have it working now it turns out that my router doesn’t play nice with the gateways multicast, so I have a new router in and its all working.

Just received my Xiaomi button Switch (the circle one) however in HA it’s being recognised as a binary sensory instead of a switch. Is this correct?

This is correct. The xiaomi plug is a “switch”.

Just got my Xiaomi Wireless switch working with this code, it seems normal to look like a sensor on HA (I’ve been reading the components files on github). Hope you find it useful:

# Xiaomi Wireless switch
- id: xiaomiwireless
  alias: 'Xiaomi wireless button'
  trigger:
    platform: event
    event_type: click
    event_data:
        entity_id: binary_sensor.switch_158d00013e4cca
        click_type: single
  action:
    service: light.toggle
    entity_id: light.luz_oficina
2 Likes

Do you also have the MiWifi Plug? If yes would you share your config snippet?

nop sorry, I don’t have that one :frowning:

First, I want to say thanks to Rave and Daniel for their work on xiaomi smart home devices support. You do a great job!

Now the bad part. It’s a bit pain for me to use these components. Two parallel branches that are frequently updating. You need to read commit messages to understand which one is more up-to-date. Rave’s branch still didn’t fix threading issue, it has some amount of frozen issues and pull requests.
Daniel’s branch looks more up-to-date for me, but these commit messages: “Update xiaomi.py”, “Update xiaomi.py” :confounded:

I’m waiting for the time when somebody of you will make a PR to main HA repo, so components will get a good code review, will become more stable and usable.

4 Likes

Two quick questions: I’ve been using a couple of Xiaomi sensors through my SmartThings hub and then into Home Assistant through the MQTT bridge. It works fine but of course everything is processed through the ST cloud servers. Does this integration work completely locally?

Second, I see there are new Temp sensors labeled Aqara and they include a Barometer. Are these currently supported? Thanks

I feel your pain :smiley:
I’ve also considered changing to Daniel’s branch but the lack of commit history put me away :confused: I’m not trying to criticize and I am very tankful for their work! But commit messages are important in this type of thing. Please don’t see this in a super negative way Daniel :slight_smile: Not my intention at all.

@rave said he would be submitting the component to HA soon…

  1. the integration does work locally as long as you have a way to block the gateway from the internet (router firewall rules, use other subnet/vlan for IOT devices etc). If not the gw will talk to xiaomi servers, but this is NOT required behaviour for HA

  2. AFAIK the new sensors are not yet fully working. Someone mentioned they had problems with the new square switch in the last week or two. IMO its only a matter of time…

Xiaomi wifi switch (@xavV) is working with the xiaomi gateway integration - see here
Maybe someone can merge the two into one platform?

1 Like

OK I have it working now it turns out that my router doesn’t play nice with the gateways multicast, so I have a new router in and its all working.

Hey Guys,
I’m trying to add a Xiaomi Aqara Window Door Sensor and a Xiaomi Aqara Temperature Humidity Sensor (the square shaped ones) to HA but i’m getting the below error. I’ve added the devices to the gateway and it says 2 devices so I think that is working OK. Since theses are my first 2 devices I just wanted to check they are unsupported atm and i’m not doing something dumb.

2017-06-06 06:34:40 ERROR (Thread-3) [custom_components.xiaomi] Unsupported devices :
Temp sensor
http://www.gearbest.com/access-control/pp_626702.htm
Door sensor
http://www.gearbest.com/access-control/pp_626703.html