Xiaomi Gateway Integration

Hi there excelent work you guys did here. My whit bulb just connect googd but the colored one don´t connect is there any config I have to do?

What’s the product name of the device you are talking about?

I am using the latest HA official version. The temperature and light sensor not update frequently, i like it update about 1 per minute . Anyone know how to fix the problem?

why you need temperature updates every one minute?

For battery powered devices that might be excessive battery consuming times

But the sensor is useless if it not “sens” current value, like temperature and light. Because i want to use it for automation. 1 minute is just an example. The light sensor from the gateway some time delay for about 1 hour and temperature delay for 60 minutes

In the official document it says that the lux readings are done hourly or when a motion is detected. I am talking about the new combined light and motion detectors. So if you want to make an automation relying on motion detection and the luminance as a condition only, the sensors are usable. But if you want to use the luminance as a trigger they won’t be usable. Use the gateway’s light sensor in that case. It is much much more frequent (hours vs seconds).
I am using the gateway’s light sensor by the way, it seems much more reliable.

I understand light sensor every minute (actually I would like even more frequent l, temperature every minute I don’t see the use

Are there any powered light sensor in the market (cheap)?

I want to use light gateway sensor and temperature/humidity sensor for automation like automatic turn on aircon, light or dryer. But those value delay much. I know that sensor run with battery(temperature/humidity) so it just delay or just update when temperature change like 0.3 C deg, but delay too much, and the value delay is random. I read that those sensor use MTTQ implementation, but without fast update it can not use for automation.

You can built one based on a ESP8266 pretty cheap

1 Like

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…