Xiaomi Gateway Integration

We are not sure if lux is the correct unit. So it would be great if you can compare it with your other sensor and find the correct unit.

You’ve mistyped. It should be

{{states.sensor.illumination_12345.state}} 

sure, I will investigate luminosity units and see what I can find out!

2 Likes

I trying to change my brightnessof a lamp, with the use of the xiaomi cube. Inspired my Daniel i use this code in my automation:


brightness_pct: >
{% set state = states.light.kmpe_lampe.attributes.brightness + (trigger.event.data.action_value|float) -%}

but it only seems on get brighter.
Can any my of you help me out here?

i posted the code i use couple days ago Xiaomi Gateway Integration

1 Like

Thanks for the hint. Unfortunately still no luck with my trigger: :frowning:

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

On another subject: Are the Mi WiFi Plugs supported? On the first view only a device_tracker gets recognized which tells me if my plug is at home or not. :smiley:

Take note there are two versions of wall plugs.
The wifi only version is supported through another component (miio) since it connects through wifi only,
zigbee one should be supported by this component, although power consumption tracking doesn’t work on all branches.

Hey all.
The French hacker who is trying to liberate xiaomi sensors from the xiaomi gateway has posted a review of three of the new Aqara sensors:

In French. Google translate does a reasonable job.

Very interesting:

  • push button has single/double/triple/quad click events
  • temp sensor now include barometer
1 Like

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?