Xiaomi Gateway Integration

I tried the Bruh example. The light sensor is not working

I’m using this new device to trigger the light in the bathroom… It is true that the luminance sensor is not updated often, but when the motion part of the sensor capture a motion it also updates the luminance value, so the automation work perfectly for me :wink:

Any luck getting frindly name to work? Most of them doen´t work only humidity sensors worked well

sensor.temperature_158d000114322c:
friendly_name: My Bedroom Temp
icon: mdi:temperature-celsius
sensor.humidity_158d000114322c:
friendly_name: My Bedroom Humi
icon: mdi:water-percent
sensor.humidity_158d0001178591:
friendly_name: Room Humidity
icon: mdi:water-percent
binary_sensor.Illumination_f0b4299aed85:
friendly_name: Gateway Light Sensor
switch.plug_158d0001101848:
friendly_name: Wall Plug
binary_sensor.Switch_158d0001152507:
friendly_name: Button Switch
binary_sensor.Cube_158d000101aa4c:
friendly_name: Cube Xiaomi
light.Gateway Light_f0b4299aed85:
friendly_name: Gateway Light
light.yeelight_white_f0b4299562f7:
friendly_name: Luz escadas

There are a few errors in your device names. Do you know this page: http://192.168.x.x:8124/dev-state? Just use copy & paste the entity ids. It should look like this:

    binary_sensor.door_window_sensor_158d00018765b0:
      friendly_name: Window Livingroom

    binary_sensor.motion_sensor_158d00013fa58e:
      friendly_name: Motion Livingroom

    binary_sensor.switch_158d000128ac22:
      friendly_name: Coffee machine

    switch.plug_158d00012a9aa5:
      friendly_name: Microwave
2 Likes

Apologies if this has been asked, is there anyway to continuously play a ringtone until the stop service is called?

No. The feature does not exist unfortunately.

It is a fact what syssi said above, but I managed to make it work (in a far from perfect way, but it works).

### Input boolean to mute gateway sound ###
input_boolean:
  mute_gateway_sounds:
    name: Mute
    icon: mdi:volume-off
### Scripts to play gateway sounds ###
script:
  play_sel_sound:
    alias: "Loop Play Sound"
    sequence:
      - condition: state
        entity_id: input_boolean.mute_gateway_sounds
        state: 'off'
      - service: xiaomi.play_ringtone
        data_template:
          gw_mac: !secret xiaomi_mac
          ringtone_id: "{{ states.input_select.gateway_sound.state.split('-')[0] }}"
          ringtone_vol: "{{ states.input_slider.gateway_volume.state|int }}"
      - delay: '00:00:{{ states.input_slider.loop_delay.state | int }}'
      - service: script.play_sel_sound_loop

  play_sel_sound_loop:
    alias: "Play selected sound in Loop"
    sequence:
      - condition: state
        entity_id: input_boolean.mute_gateway_sounds
        state: 'off'
      - delay: '00:00:{{ states.input_slider.loop_delay.state | int }}'
      - service: script.play_sel_sound

  play_sel_sound_single:
    alias: "Single Play Sound"
    sequence:
      - condition: state
        entity_id: input_boolean.mute_gateway_sounds
        state: 'off'
      - service: xiaomi.play_ringtone
        data_template:
          gw_mac: !secret xiaomi_mac
          ringtone_id: "{{ states.input_select.gateway_sound.state.split('-')[0] }}"
          ringtone_vol: "{{ states.input_slider.gateway_volume.state|int }}"

### Input slider to control gateway volume ###
input_slider:
  gateway_volume:
    name: Volume
    initial: 10
    min: 0
    max: 100
    step: 2
    icon: mdi:volume-high

### Input slider to control loop delay ###
  loop_delay:
    name: "Loop Delay"
    initial: 1
    min: 0
    max: 15
    step: 1
    icon: mdi:loop

### Input select to select sound to play ###
input_select:
  gateway_sound:
    name: Ringtone
    options: 
      - "0 - Police car 1"
      - "1 - Police car 2"
      - "2 - Accident"
      - "3 - Countdown"
      - "4 - Ghost"
      - "5 - Sniper rifle"
      - "6 - Battle"
      - "7 - Air raid"
      - "8 - Bark"
#      - "9 - None"
      - "10 - Doorbell"
      - "11 - Knock at a door"
      - "12 - Amuse"
      - "13 - Alarm clock"
#      - "14 - None"
#      - "15 - None"
#      - "16 - None"
#      - "17 - None"
#      - "18 - None"
#      - "19 - None"
      - "20 - MiMix"
      - "21 - Enthusiastic"
      - "22 - GuitarClassic"
      - "23 - IceWorldPiano"
      - "24 - LeisureTime"
      - "25 - ChildHood"
      - "26 - MorningStreamLiet"
      - "27 - MusicBox"
      - "28 - Orange"
      - "29 - Thinker"
      - "10001 - Alarm Sound 3"
      - "10002 - Beep 2x"
      - "10003 - Time beep 3x"
      - "10004 - Alarm Sound 1"
      - "10005 - Alarm Sound 2"
      - "10006 - Time beeps long"      
    icon: mdi:music-note

Here’s how it looks on the frontend:
image

And here’s an example of usage in an automation:

automation:
    ### Play specific sound while alarm is arming ###
      - alias: "Alarm arm pending"
        trigger:
          platform: state
          entity_id: alarm_control_panel.home_alarm
          to: 'pending'
        action:
    ### Turn off gateway mute to play sound ###
          - service: input_boolean.turn_off
            data:
              entity_id: input_boolean.mute_gateway_sounds
    ### Play ringtone sound in loop until arm is done ###
          - service: script.play_sound
            data:
              ringtone_id: 10006
              ringtone_vol: 4
              delay: 2
    ### Stop sound when alarm is disarmed or armed ###
      - alias: "Alarm Turn off or Armed"
        trigger:
          - platform: state
            entity_id: alarm_control_panel.home_alarm
            to: 'disarmed'
          - platform: state
            entity_id: alarm_control_panel.home_alarm
            to: 'armed_away'
          - platform: state
            entity_id: alarm_control_panel.home_alarm
            to: 'armed_home'
        action:
    ### Turn on gateway mute NOT to play sound ###
          - service: input_boolean.turn_on
            data:
              entity_id: input_boolean.mute_gateway_sounds
    ### Stop ringtone sound --> didn't seem to work due to loop ###
          - service: xiaomi.stop_ringtone
            data:
              gw_mac: !secret xiaomi_mac
    ### Wait 10 seconds & then turn off gateway mute ###
          - delay: 
              seconds: 10
          - service: input_boolean.turn_off
            data:
              entity_id: input_boolean.mute_gateway_sounds

    ### Alarm trigger while armed away ###
      - alias: "Alarm trigger while armed away"
        trigger:
    ### Front Door opened ###
          - platform: state
            entity_id: binary_sensor.door_window_sensor_158d00019f302c
            to: 'on'
    ### Any movement detected ###
          - platform: state
            entity_id: group.all_motion
            to: 'on'
    ### Alarm status is armed away ###
        condition:
          condition: state
          entity_id: alarm_control_panel.home_alarm
          state: 'armed_away'
        action:
    ### Turn off gateway mute to play sound ###
          - service: input_boolean.turn_off
            data:
              entity_id: input_boolean.mute_gateway_sounds
    ### Trigger alarm ###
          - service: alarm_control_panel.alarm_trigger
            entity_id: alarm_control_panel.home_alarm
    ### Play ringtone sound in loop ###
          - service: script.play_sound
            data:
              ringtone_id: 10004
              ringtone_vol: 50
              delay: 2

You may need to adjust the delays to best fit your requirements, but here it works properly.

I hope this may give you ideas on how to use it.

25 Likes

FYI: The Water Leak Sensor is on sale. $12.99 at GearBest

https://www.gearbest.com/home-smart-improvements/pp_668897.html

ordered 3 of them, are they already supported?

I don’t think so (unless I missed sth in this thread) but it’s just a matter of time.

I’m about to order some as well…

I wrote the support a few days ago. The sensor will be part of HA 0.53:

1 Like

Awesome… I missed that for sure. A reason more to order asap.

If I have a Zigbee usb stick, do I need xiaomi hub or I can use only the sensors?

you need a hub. Well worth it as I didn’t want yet another hub, but they just plug into a power socket - bosh done :slight_smile:

There is no plug and play solution for zigbee sticks. Depending on your hardware this would be the difficult route: ConBee ZigBee Stick and HA, will this work together?

I have a VLAN sub interface in HASS server, gateway in the VLAN, but discovery always failed, HASS is 0.53. Put gateway out of VLAN, no any problem.

config:

xiaomi:                                                                                                                                     
  discovery_retry: 5
  interface: "10.85.10.85"
  gateways:
   - sid:
     key: 236***6FB

tcpdump -A udp port 4321 or udp port 9898

21:41:35.805844 IP 10.85.85.68.4321 > 224.0.0.50.9898: UDP, length 134
E...2.....H.
UUD...2..&....@{"cmd":"heartbeat","model":"gateway","sid":"34ce***55ec","short_id":"0","token":"Vq8b***3CIc","data":"{\"ip\":\"10.85.85.68\"}"}

any idea to fix this?

Does your VLAN support multicast traffic? :wink: How did you configure the VLAN? Which devices are involved?

hi, the tcpdump result can explain multicast support? or can you provide a reliable method to test it?

vlan config:

auto ens160.50
iface ens160.50 inet static
    address 10.85.10.85
    netmask 255.255.0.0
    broadcast 10.85.255.255
    vlan-raw-device ens160

the device is xiaomi gateway(lumi.gateway.v3)

Thanks.

Can you tell me the name of the other VLAN-aware device(s) in your network? Did you tag the port of your accesspoint properly?

What type of power adapter are you using? I’m having trouble finding a power adapter for my Xiaomi Gateway for a US outlet.