Xiaomi Gateway Integration

Again: You must not use the button of the gateway. The button is wired to the internal logic of Mi Home which cannot be used with home assistant. Ignore the button of the gateway!

i’m tolk about this button and not the gateway button… i never use gateway button…

Nice :+1:

Waiting for my new PIR sensor to arrive and see how good is the light sensor. Among the new sensors, I feel the PIR update is the most practical followed by the Wireless switch (still need to be tested as 4-clicks could be a challenge). For Temp/Hum, not sure how relevant is Pressure indoor?

Great! Just try this:


alarm_control_panel:
  - platform: manual
#    code: 1111

automation:
  - alias: Alarm triggered
    hide_entity: true
    trigger:
      platform: state
      entity_id: alarm_control_panel.ha_alarm
      state: 'triggered'
    action:
      - service: xiaomi.play_ringtone
        data:
          ringtone_id: 2
          ringtone_vol: 99
          gw_sid: !secret xiaomi_sid
  
  - alias: Turn off alarm
    hide_entity: true
    trigger:
      platform: state
      entity_id: alarm_control_panel.ha_alarm
      state: 'disarmed'
    action:
      - service: xiaomi.stop_ringtone
        data:
          gw_sid: !secret xiaomi_sid
  
  
  
  - alias: Trigger alarm while armed away
    trigger:
      # alarm on fire
      - platform: state
        entity_id: binary_sensor.smoke_sensor_158d0xxxxxxxxx
        to: 'on'
  
      # door opened
      - platform: state
        entity_id: binary_sensor.door_window_sensor_158d0xxxxxxxxx
        to: 'on'
  
      # motion detected
      - platform: state
        entity_id: group.all_motion
        to: 'on'
  
      # window opened
      - platform: state
        entity_id: group.all_windows
        from: 'off'
        to: 'on'
    condition:
      - condition: state
        entity_id: alarm_control_panel.ha_alarm
        state: armed_away
    action:
      service: alarm_control_panel.alarm_trigger
      entity_id: alarm_control_panel.ha_alarm
  
  
  
  - alias: Arm away by wireless button
    trigger:
      - platform: event
        event_type: click
        event_data:
          entity_id: binary_sensor.switch_158d0xxxxxxxxx
          click_type: single
  
    action:
      - service: xiaomi.play_ringtone
        data:
          ringtone_id: 10
          ringtone_vol: 8
          gw_sid: !secret xiaomi_sid
  
      - service: alarm_control_panel.alarm_arm_away
        entity_id: alarm_control_panel.ha_alarm
  
  - alias: Disarm by wireless button
    trigger:
      - platform: event
        event_type: click
        event_data:
          entity_id: binary_sensor.switch_158d0xxxxxxxxx
          click_type: double
    action:
      - service: xiaomi.play_ringtone
        data:
          ringtone_id: 11
          ringtone_vol: 8
          gw_sid: !secret xiaomi_sid
  
      - service: alarm_control_panel.alarm_disarm
        entity_id: alarm_control_panel.ha_alarm
  
  - alias: Arm home by wireless button
    trigger:
      - platform: event
        event_type: click
        event_data:
          entity_id: binary_sensor.switch_158d0xxxxxxxxx
          click_type: long_click_press
    action:
      - service: xiaomi.play_ringtone
        data:
          ringtone_id: 12
          ringtone_vol: 8
          gw_sid: !secret xiaomi_sid
  
      - service: alarm_control_panel.alarm_arm_home
        entity_id: alarm_control_panel.ha_alarm

2 Likes

If you want to use a code to arm/disarm the alarm the configuration must be extended a little bit:

# configuration.yaml

alarm_control_panel:
  - platform: manual
    code: !secret alarm_pin

automation:
  - alias: Alarm triggered
    hide_entity: true
    trigger:
      platform: state
      entity_id: alarm_control_panel.ha_alarm
      state: 'triggered'
    action:
      - service: xiaomi.play_ringtone
        data:
          ringtone_id: 2
          ringtone_vol: 8
          gw_sid: !secret xiaomi_sid
  
  - alias: Turn off alarm
    hide_entity: true
    trigger:
      platform: state
      entity_id: alarm_control_panel.ha_alarm
      state: 'disarmed'
    action:
      - service: xiaomi.stop_ringtone
        data:
          gw_sid: !secret xiaomi_sid
  
  
  
  - alias: Trigger alarm while armed away
    trigger:
      # alarm on fire
      - platform: state
        entity_id: binary_sensor.smoke_sensor_158d0xxxxxxxxx
        to: 'on'
  
      # door opened
      - platform: state
        entity_id: binary_sensor.door_window_sensor_158d0xxxxxxxxx
        to: 'on'
  
      # motion detected
      - platform: state
        entity_id: group.all_motion
        to: 'on'
  
      # window opened
      - platform: state
        entity_id: group.all_windows
        from: 'off'
        to: 'on'
    condition:
      - condition: state
        entity_id: alarm_control_panel.ha_alarm
        state: armed_away
    action:
      service: alarm_control_panel.alarm_trigger
      entity_id: alarm_control_panel.ha_alarm
  
  
  - alias: Alarm arm away
    trigger:
      - platform: event
        event_type: click
        event_data:
          entity_id: binary_sensor.switch_158d0xxxxxxxxx
          click_type: single
  
    action:
      - service: xiaomi.play_ringtone
        data:
          ringtone_id: 10
          ringtone_vol: 8
          gw_sid: !secret xiaomi_sid
  
      - service: alarm_control_panel.alarm_arm_away
        entity_id: alarm_control_panel.ha_alarm
        data:
          code: !secret alarm_pin
  
  - alias: Alarm disarm
    trigger:
      - platform: event
        event_type: click
        event_data:
          entity_id: binary_sensor.switch_158d0xxxxxxxxx
          click_type: double
    action:
      - service: xiaomi.play_ringtone
        data:
          ringtone_id: 11
          ringtone_vol: 8
          gw_sid: !secret xiaomi_sid
  
      - service: alarm_control_panel.alarm_disarm
        entity_id: alarm_control_panel.ha_alarm
        data:
          code: !secret alarm_pin
  
  - alias: Alarm arm home
    trigger:
      - platform: event
        event_type: click
        event_data:
          entity_id: binary_sensor.switch_158d0xxxxxxxxx
          click_type: long_click_press
    action:
      - service: xiaomi.play_ringtone
        data:
          ringtone_id: 12
          ringtone_vol: 8
          gw_sid: !secret xiaomi_sid
  
      - service: alarm_control_panel.alarm_arm_home
        entity_id: alarm_control_panel.ha_alarm
        data:
          code: !secret alarm_pin
# secrets.yaml

alarm_pin: 1111
xiaomi_sid: TheMacAddressOfTheGatewayWithoutColonsInLowerCase
3 Likes

Interested in giving my decoupled Aqara Wall Switch code a try? in decoupled mode when you press the switch, it generates a click(single click) that HA can react to. One big CAVEAT is that you can’t use the Mi Home app’s automation on that switch, otherwise it will generate erroneous clicks when mi home’s native automation routine triggers.

you can find it at my repo [email protected]:tommycheng/homeassistant.git

1 Like

Hello,

Is there a way to create an automation (such as the one in gateway) to switch colors between a preset list when triggered?

Is this automation, what you are looking for?

input_select:
  color_mode:
    name: Color mode
    options:
      - "red"
      - "green"
      - "blue"
    icon: mdi:format-color-fill

automation:
  - alias: Input select triggered
    hide_entity: true
    trigger:
      platform: state
      entity_id: input_select.color_mode
    action:
      - service: light.turn_on
        entity_id: light.gateway_light_28xxxxxxxxxx
        data_template:
          color_name: '{{ states.input_select.color_mode.state }}'
  
  - alias: Next color by wireless button
    trigger:
      - platform: event
        event_type: click
        event_data:
          entity_id: binary_sensor.switch_158d0xxxxxxxxx
          click_type: single
    action:
       - service: input_select.select_next
         entity_id: input_select.color_mode

Every time the wireless button is pushed the color of the gateway changes to the next input_select option.

4 Likes

Works perfectly, thank you.

Although not every color name from the css3 color map (link: CSS Color Module Level 3) works. I was getting the error:

[homeassistant.util.color] unknown color supplied sky default to white

I tried to use rgb_color with no prevail. (was getting: expecting data['rgb_color'] got "[255,255,255]" type errors.)

After some fiddling I found the best matching available colors. For anyone interested these are the color names matching the default scenes in the gateway:

  gateway_color_mode:
    name: Color mode
    options:
      - "darkviolet" #romantic       
      - "hotpink" #pink             
      - "gold" #wheat           
      - "deepskyblue" #sky              
      - "springgreen" #forest          
      - "blue" #tranquil         
      - "white" #white           
    icon: mdi:format-color-fill
2 Likes

Can anyone help with implementing some wifi mini plugs. I am really struggling.

I have the gateway all up and running, I can see the temperature, luminance and humidity all loaded into Home Assistant. I can turn the light on and off etc on the gateway etc.

I also have three mi plug mini’s. I have used miio to find out the token details etc.
However I don’t know what to put into the configuration.yaml to get them working (Or should they be automatically found?). They are all working on the MiHome App, but I can’t seem to load them into the Home Assistant to control them via the UI.

I currently have files all loaded into the custom_components folder on my HASSBIAN.

I have tried everything I can think of. Can anyone give an example of their configuration.yaml or give me to some tips?

Thanks in advance

This could help: Xiaomi mi wifi plug & air purifier - #17 by Regularj

You’ve to setup two plattforms. The one for the xiaomi gateway + zigbee devices and the renamed one of GitHub - xavV/xiaomi to control the plug.

Just installed the new Door/Window sensor which arrive today. Works great in Mi Home app but not in HA. :disappointed:

Log of HA as below:

2017-07-11 18:31:57 DEBUG (Thread-11) [homeassistant.components.xiaomi] >> b'{"cmd":"read","sid":"158d000xxxxxxx"}'
2017-07-11 18:31:57 DEBUG (Thread-11) [homeassistant.components.xiaomi] << {'data': '{"voltage":3055}', 'model': '', 'sid': '158d000xxxxxxx', 'short_id': 60491, 'cmd': 'read_ack'}
2017-07-11 18:31:57 ERROR (Thread-11) [homeassistant.components.xiaomi] Unsupported devices :

Firstly thanks syssi for the advice! I am new to this and really struggling. I will try implementing the xavV version today and renaming it.

I have a quick question though; can’t I use the “switch” that is included in “Xiaomi Gateway Integration” by Rave? I ask because it seems to be more regularly updated and has more development coming with power consumption etc?

With either methodology, should I use the switch the Rave or xavV version, is it just renaming the xiaomi.py file in the switch folder? Or are there other elements which also need to be renamed?

Apologies if this is a total newbie question. Any help would be greatly appreciated. I am also doing a thorough write up of my build for some friends. I will share with the community when completed.

Thanks again. Fastrax

Hi there,

I just looked a bit into the new square aqara switch - I can read the voltage, but I don’t think the gateway forwards the events as the normal Xiaomi components.

Might be a firmware issue.

Furthermore the MiHome Android app can’t add the Aqara switch - using the IOS MiHome app it succeeds.
Strange

No problem. :wink: Nevertheless you are mixing things up. There is a plattform called “xiaomi” from @Rave and a fork from @danielhiversen which implements the xiaomi gateway plus zigbee devices. The xiaomi wifi plug is another protocol. That’s why another home assistant component is needed. This component is called “xiaomi” also annoyingly. Because of the name conflict you have to rename some stuff…

Yes it’s a firmware issue. Just wait for the next release of the local network protocol (xiaomi gateway firmware).

Do you know when it will happen

Nope. It will be a nice surprise for all of us. :slight_smile:

I’m lost :weary: - how can I find the key for the gateway? I can’t seem to get there from the MI Home app - I think maybe the app has changed?

Thanks,

Tom

Used region mainland China?