Xiaomi Gateway Integration

That’s great news! Will order one straight away.

Need to be in your fork @Danielhiversen to be of any use now as I am not sure when @rave will be back and also to have all the things that are already working in your fork.

Is there anything you can explore on this front?

Hi all, with the current sales I’m keen to dive in and get some of the Xiaomi temperature sensors.
I’m having trouble following HA’s support of them however. Can I please trouble someone to just check HA’s support for these 3 items?

  1. Original (round) Original Xiaomi Mi Smart Temperature and Humidity Sensor 174859503

  2. (New Square) Xiaomi Aqara Temperature Humidity Sensor 212232401

  3. Xiaomi Mi Home Air Conditioner Companion - WHITE 213962901
    As a gateway:
    http://www.gearbest.com/power-strips/pp_640724.html

Thanks very much.

  • Original (round) Original Xiaomi Mi Smart Temperature and Humidity Sensor 174859503

Supported.

  • (New Square) Xiaomi Aqara Temperature Humidity Sensor 212232401

Not supported.

  • Xiaomi Mi Home Air Conditioner Companion - WHITE 213962901 as gateway

Not supported.

Reinstalled everything from hassbian home assistant image this morning and now I can see in logs it seems to have found the gateway but getting these errors in logs that it can’t find “component gateways”?? I can’t see it on home screen but can see that it found a motion sensor…

Can I just double check that I have the custom components folder in correct location? Is /home/homeassistant/.homeassistant/custom_components correct location?

pi@hassbian:/home/homeassistant/.homeassistant $ cat home-assistant.log
2017-07-13 10:57:54 ERROR (MainThread) [homeassistant.loader] Unable to find component gateways
2017-07-13 10:57:54 ERROR (MainThread) [homeassistant.setup] Setup failed for gateways: Component not found.
2017-07-13 10:57:54 ERROR (MainThread) [homeassistant.loader] Unable to find component key
2017-07-13 10:57:54 ERROR (MainThread) [homeassistant.setup] Setup failed for key: Component not found.
2017-07-13 10:57:55 WARNING (Thread-7) [custom_components.xiaomi] Gateway Key is not provided. Only sensors will be loaded.
2017-07-13 10:57:55 INFO (Thread-7) [custom_components.xiaomi] Expecting 1 gateways
2017-07-13 10:57:55 INFO (Thread-7) [custom_components.xiaomi] Discovering Xiaomi Gateways (Try 1)
2017-07-13 10:57:55 WARNING (Thread-7) [custom_components.xiaomi] To enable discovery of switches, fill in API key in configuration.xml sid = 286c0788a6e6
2017-07-13 10:57:55 INFO (Thread-7) [custom_components.xiaomi] Xiaomi Gateway 286c0788a6e6 found at IP 192.168.0.241
2017-07-13 10:57:55 INFO (Thread-7) [custom_components.xiaomi] Discovering Xiaomi Devices
2017-07-13 10:57:55 DEBUG (Thread-7) [custom_components.xiaomi] >> b’{“cmd” : “get_id_list”}’
2017-07-13 10:57:55 DEBUG (Thread-7) [custom_components.xiaomi] << {‘cmd’: ‘get_id_list_ack’, ‘data’: ‘[“158d00012320c2”]’, ‘token’: ‘nHSSQA8qIcb3jt0v’, ‘sid’: ‘286c0788a6e6’}
2017-07-13 10:57:55 INFO (Thread-7) [custom_components.xiaomi] Found 2 devices
2017-07-13 10:57:55 DEBUG (Thread-7) [custom_components.xiaomi] >> b’{“cmd”:“read”,“sid”:“158d00012320c2”}’
2017-07-13 10:57:55 DEBUG (Thread-7) [custom_components.xiaomi] << {‘cmd’: ‘read_ack’, ‘data’: ‘{“voltage”:3025,“status”:“motion”}’, ‘short_id’: 21831, ‘sid’: ‘158d00012320c2’, ‘model’: ‘motion’}
2017-07-13 10:57:55 DEBUG (Thread-7) [custom_components.xiaomi] >> b’{“cmd”:“read”,“sid”:“286c0788a6e6”}’
2017-07-13 10:57:55 DEBUG (Thread-7) [custom_components.xiaomi] << {‘cmd’: ‘read_ack’, ‘data’: ‘{“rgb”:0,“illumination”:457,“proto_version”:“1.0.7”}’, ‘short_id’: 0, ‘sid’: ‘286c0788a6e6’, ‘model’: ‘gateway’}
2017-07-13 10:58:00 INFO (Thread-7) [custom_components.xiaomi] Gateway finding finished in 5 seconds
2017-07-13 10:58:00 INFO (Thread-7) [custom_components.xiaomi] Creating Multicast Socket
2017-07-13 10:58:00 INFO (Thread-7) [custom_components.xiaomi] Listening for broadcast
2017-07-13 10:58:13 DEBUG (Thread-12) [custom_components.xiaomi] MCAST (report) << {‘cmd’: ‘report’, ‘data’: ‘{“rgb”:0,“illumination”:456}’, ‘short_id’: 0, ‘sid’: ‘286c0788a6e6’, ‘model’: ‘gateway’}
2017-07-13 10:58:13 DEBUG (Thread-12) [custom_components.xiaomi] MCAST (report) << {‘cmd’: ‘report’, ‘data’: ‘{“rgb”:0,“illumination”:456}’, ‘short_id’: 0, ‘sid’: ‘286c0788a6e6’, ‘model’: ‘gateway’}
2017-07-13 10:58:13 DEBUG (Thread-10) [custom_components.xiaomi] PUSH >> <Entity Illuminance_286c0788a6e6: 457>: {‘illumination’: 456, ‘rgb’: 0}
2017-07-13 10:58:13 DEBUG (Thread-9) [custom_components.xiaomi] PUSH >> <Entity Illuminance_286c0788a6e6: 456>: {‘illumination’: 456, ‘rgb’: 0}
pi@hassbian:/home/homeassistant/.homeassistant $ cat home-assistant.log
2017-07-13 10:58:47 ERROR (MainThread) [homeassistant.loader] Unable to find component key
2017-07-13 10:58:47 ERROR (MainThread) [homeassistant.setup] Setup failed for key: Component not found.
2017-07-13 10:58:47 ERROR (MainThread) [homeassistant.loader] Unable to find component gateways
2017-07-13 10:58:47 ERROR (MainThread) [homeassistant.setup] Setup failed for gateways: Component not found.

The custom components folder is in the correct location, otherwise you would gotten a different error.

Have you added key and sid in the config file?

xiaomi:
  gateways:
    - sid: 286c0788a6e6
      key: keyfrommiapp

Yep, they are in the configuration.yaml file

Edit: Looks like I got it working, I can see the gateway as a “light” in the light section on home page. I had to format the xiaomi config slightly differently in the confiuration.yaml!!

I asked and it seems the image is wrong, so it’s the “normal” sensor :confused:

Really!!??

I ordered this:

http://www.gearbest.com/alarm-systems/pp_659226.html

yes, check the question I asked :frowning:

You received it already?

I also ordered 3 pcs but not during the special sale time as you mentioned but few days before when it was also discounted. Below is the description on the web and look at the highlighted sentence, it does describe the light sensor.

Main Features:
Work with other Xiaomi smart devices
Intelligent induction: when somebody goes through, the night light will turn on automatically
Sense the lightness and dark of your room
Notice function: sent alert to you through the APP
ZigBee wireless connection
Built-in 1pc CR2450 cell battery
Detection distance: 7m
Detection angle: 170 degree
Working temperature: -10 - 45 Deg.C
Working humidity: 0 - 95pct RH

From your question, i believed they do not understand the word “luminance”. Anyway, my sensor should arrive very soon and we will find out. :worried:

Question:
Is this the new Aqara motion sensor that includes a luminance sensor as well?
Reply:
Hello Jonatan, 
We are sorry it doesn't has.

nop, I didn’t buy it yet… let me know if it ends up being the correct one!

@skull29 yeah, it seems so! phew!

I think is the new one, will tell you when arrives

Hello.

Just got today a brand new Xiaomi Cube to play around. It looks quite nice and adding it to the gateway was a piece of cake.

In Home Assistant, is there any way to be able to understand which event is being triggered? Entity state seems to be always off (Binary sensor?).

Still then, if I activate debug mode for Xiaomi component, I can see different events being triggered as I try them:

2017-07-13 22:00:51 DEBUG (Thread-13) [custom_components.xiaomi] MCAST (report) << {'model': 'cube', 'sid': '158d0001135dbf', 'data': '{"status":"shake_air"}', 'short_id': 16197, 'cmd': 'report'}
2017-07-13 22:00:51 DEBUG (Thread-9) [custom_components.xiaomi] PUSH >> <Entity Cube_158d0001135dbf: off>: {'status': 'shake_air'}
2017-07-13 22:02:24 DEBUG (Thread-13) [custom_components.xiaomi] MCAST (report) << {'model': 'cube', 'sid': '158d0001135dbf', 'data': '{"status":"free_fall"}', 'short_id': 16197, 'cmd': 'report'}
2017-07-13 22:02:24 DEBUG (Thread-6) [custom_components.xiaomi] PUSH >> <Entity Cube_158d0001135dbf: off>: {'status': 'free_fall'}
2017-07-13 22:08:29 DEBUG (Thread-13) [custom_components.xiaomi] MCAST (report) << {'model': 'cube', 'sid': '158d0001135dbf', 'data': '{"status":"alert"}', 'short_id': 16197, 'cmd': 'report'}
2017-07-13 22:08:29 DEBUG (Thread-5) [custom_components.xiaomi] PUSH >> <Entity Cube_158d0001135dbf: off>: {'status': 'alert'}
2017-07-13 22:08:47 DEBUG (Thread-13) [custom_components.xiaomi] MCAST (report) << {'model': 'cube', 'sid': '158d0001135dbf', 'data': '{"status":"flip90"}', 'short_id': 16197, 'cmd': 'report'}
2017-07-13 22:08:47 DEBUG (Thread-12) [custom_components.xiaomi] PUSH >> <Entity Cube_158d0001135dbf: off>: {'status': 'flip90'}
2017-07-13 22:08:49 DEBUG (Thread-13) [custom_components.xiaomi] MCAST (report) << {'model': 'cube', 'sid': '158d0001135dbf', 'data': '{"status":"flip180"}', 'short_id': 16197, 'cmd': 'report'}
2017-07-13 22:08:49 DEBUG (Thread-3) [custom_components.xiaomi] PUSH >> <Entity Cube_158d0001135dbf: off>: {'status': 'flip180'}
2017-07-13 22:11:50 DEBUG (Thread-13) [custom_components.xiaomi] MCAST (report) << {'model': 'cube', 'sid': '158d0001135dbf', 'data': '{"status":"tap_twice"}', 'short_id': 16197, 'cmd': 'report'}
2017-07-13 22:11:50 DEBUG (Thread-10) [custom_components.xiaomi] PUSH >> <Entity Cube_158d0001135dbf: off>: {'status': 'tap_twice'}
2017-07-13 22:16:27 DEBUG (Thread-13) [custom_components.xiaomi] MCAST (report) << {'model': 'cube', 'sid': '158d0001135dbf', 'data': '{"rotate":"-34,500"}', 'short_id': 16197, 'cmd': 'report'}
2017-07-13 22:16:27 DEBUG (Thread-5) [custom_components.xiaomi] PUSH >> <Entity Cube_158d0001135dbf: off>: {'rotate': '-34,500'}`

I suppose this means that HA is properly capturing the cube motion events.
What I’d like would be to get this status information into HA frontend. Is that even possible using @Danielhiversen repo?

Thanks in advance.

I’ve uploaded a few sounds to my gateway to play around with the cube:


- alias: Cube flip90
  trigger:
    platform: event
    event_type: cube_action
    event_data:
      entity_id: binary_sensor.cube_158d00011a052e
      action_type: flip90
  action:
    - service: script.turn_on                                                                                                                                                                      
      entity_id: script.play_sound                                                                                                                                                                 
      data:                                                                                                                                                                                        
        variables:                                                                                                                                                                                 
          ringtone_vol: 8                                                                                                                                                                          
          ringtone_id: 10002                                                                                                                                                                       
                                                                                                                                                                                                   
- alias: Cube flip180                                                                                                                                                                              
  trigger:                                                                                                                                                                                         
    platform: event                                                                                                                                                                                
    event_type: cube_action                                                                                                                                                                        
    event_data:                                                                                                                                                                                    
      entity_id: binary_sensor.cube_158d00011a052e                                                                                                                                                 
      action_type: flip180                                                                                                                                                                         
  action:                                                                                                                                                                                          
    - service: script.turn_on                                                                                                                                                                      
      entity_id: script.play_sound                                                                                                                                                                 
      data:                                                                                                                                                                                        
        variables:                                                                                                                                                                                 
          ringtone_vol: 8                                                                                                                                                                          
          ringtone_id: 10003                                                                                                                                                                       
                                                                                                                                                                                                   
- alias: Cube move                                                                                                                                                                                 
  trigger:                                                                                                                                                                                         
    platform: event                                                                                                                                                                                
    event_type: cube_action                                                                                                                                                                        
    event_data:                                                                                                                                                                                    
      entity_id: binary_sensor.cube_158d00011a052e                                                                                                                                                 
      action_type: move                                                                                                                                                                            
  action:                                                                                                                                                                                          
    - service: script.turn_on                                                                                                                                                                      
      entity_id: script.play_sound                                                                                                                                                                 
      data:                                                                                                                                                                                        
        variables:                                                                                                                                                                                 
          ringtone_vol: 8                                                                                                                                                                          
          ringtone_id: 10009                                                                                                                                                                       
                                                                                                                                                                                                   
- alias: Cube tap_twice                                                                                                                                                                            
  trigger:                                                                                                                                                                                         
    platform: event                                                                                                                                                                                
    event_type: cube_action                                                                                                                                                                        
    event_data:
      entity_id: binary_sensor.cube_158d00011a052e
      action_type: tap_twice
  action:
    - service: script.turn_on
      entity_id: script.play_sound
      data:
        variables:
          ringtone_vol: 8
          ringtone_id: 10008

- alias: Cube shake_air
  trigger:
    platform: event
    event_type: cube_action
    event_data:
      entity_id: binary_sensor.cube_158d00011a052e
      action_type: shake_air
  action:
    - service: script.turn_on
      entity_id: script.play_sound
      data:
        variables:
          ringtone_vol: 8
          ringtone_id: 10007

- alias: Cube swing
  trigger:
    platform: event
    event_type: cube_action
    event_data:
      entity_id: binary_sensor.cube_158d00011a052e
      action_type: swing
  action:
    - service: script.turn_on
      entity_id: script.play_sound
      data:
        variables:
          ringtone_vol: 8
          ringtone_id: 10006

- alias: Cube alert
  trigger:
    platform: event
    event_type: cube_action
    event_data:
      entity_id: binary_sensor.cube_158d00011a052e
      action_type: alert
  action:
    - service: script.turn_on
      entity_id: script.play_sound
      data:
        variables:
          ringtone_vol: 8
          ringtone_id: 10005

- alias: Cube free_fall
  trigger:
    platform: event
    event_type: cube_action
    event_data:
      entity_id: binary_sensor.cube_158d00011a052e
      action_type: free_fall
  action:
    - service: script.turn_on
      entity_id: script.play_sound
      data:
        variables:
          ringtone_vol: 8
          ringtone_id: 10004
3 Likes

And you can dim your light. But the code is bogus because the brightness attribute is not available if my light is off. Because of this fact I have to turn on the light first before I can dim the light with the cube. May be somebody can improve it:

- alias: Set brightness by rotating cube
  trigger:
    platform: event
    event_type: cube_action
    event_data:
      entity_id: binary_sensor.cube_158d00011a052e
      action_type: rotate
  action:
    service: light.turn_on
    data_template:
      entity_id: light.couch
      brightness: >
        {% set state = states.light.couch.attributes.brightness|int + ((trigger.event.data.action_value|float)*1.25)|int -%}
        {%-  if state > 255 -%}
          {%- set state  = 255 -%}
        {%-  elif state < 0 -%}
          {%- set state  = 0 -%}
        {%- endif %}
        {{ state }}
2 Likes

Very cool… how do you upload sounds to the gateway?

Thanks,

Tom

1 Like

It’s a feature of the Mi Home app: Select the gateway from the list view of “My devices” → Switch to “devices” at the top navigation → select the gateway again → Ringtone settings → Doorbell ring tone → Add ringtone → Phone music list → All audio files of your android smartphone will be listed, select a audio file → Confirm with “Yes” in the top right corner.

I uploaded a bunch of short notification sounds which can be accessed by the high ringtone ids (> 100001).

5 Likes

@Danielhiversen just merged the new feature (curtain device support): https://github.com/Danielhiversen/homeassistant/pull/20