Xiaomi Gateway Integration

@rave, @Danielhiversen I think this is more or less ready for production. One thing that’s needed is an option to disable polling and rely solely on the gateways reports. Otherwise every power cut will bring a flood of complaints about false positives.

Unfortunately I’m unable to get my devices (2 hygrometers and one motion sensor) discovered.

pi@hassbian:~ $ cat /home/homeassistant/.homeassistant/home-assistant.log | grep xiaomi
17-04-02 20:10:51 INFO (MainThread) [homeassistant.loader] Loaded xiaomi from custom_components.xiaomi
17-04-02 20:10:51 INFO (MainThread) [homeassistant.setup] Setting up xiaomi
17-04-02 20:10:51 INFO (Thread-6) [custom_components.xiaomi] Expecting 1 gateways
17-04-02 20:10:51 INFO (Thread-6) [custom_components.xiaomi] Discovering Xiaomi Gateways (Try 1)
17-04-02 20:10:51 INFO (Thread-6) [custom_components.xiaomi] Xiaomi Gateway f0b429cc315f found at IP 192.168.0.12
17-04-02 20:10:52 INFO (Thread-6) [custom_components.xiaomi] Discovering Xiaomi Devices
17-04-02 20:10:52 DEBUG (Thread-6) [custom_components.xiaomi] >> b'{"cmd" : "get_id_list"}'
17-04-02 20:10:52 DEBUG (Thread-6) [custom_components.xiaomi] << {'data': '["158d00010f859c","158d00011172f3","158d0001100456"]', 'cmd': 'get_id_list_ack', 'sid': 'f0b429cc315f', 'token': 'lxvXftEO5K3JBY5y'}
17-04-02 20:10:55 ERROR (MainThread) [homeassistant.setup] Error during setup of component xiaomi
  File "/home/homeassistant/.homeassistant/custom_components/xiaomi.py", line 77, in setup
  File "/home/homeassistant/.homeassistant/custom_components/xiaomi.py", line 167, in discover_gateways
  File "/home/homeassistant/.homeassistant/custom_components/xiaomi.py", line 262, in __init__
  File "/home/homeassistant/.homeassistant/custom_components/xiaomi.py", line 271, in _discover_devices
  File "/home/homeassistant/.homeassistant/custom_components/xiaomi.py", line 368, in update_key

To me it looks like he discovers the gateway but not the devices. Any idea how to start solving this thing?

I double-checked the gateway key

Thanks for helping a beginner,
RegularJ!

I used this code for the Open/Closed feature. It creates a new sensor which you use instead of the binary one.

- platform: template
  sensors:
    front_door_status:
      value_template: '{% if states.binary_sensor.door_window_sensor_158d00011c7eac %}
        {% if states.binary_sensor.door_window_sensor_158d00011c7eac.state == "on" %}
          Open
        {% else %}
          Closed
        {% endif %}
        {% else %}
          n/a
        {% endif %}'
      friendly_name: 'Front Door'
1 Like

Thanks mate - I might do the same. Does this flow down into the log - so that a door reports as opened or closed in the log, or is it still on/off?

Would be good though if the core code had this I think? Or am I missing something - does on/off make more sense in some way?

Anyway - thanks again!

My guess would be as it is a binary_sensor it only support on/off in the HA core. Iirc all door / window sensors are this way in HA.

~Cheers

1 Like

After months of flawless operation all of a sudden it seems that when I reboot HASS I need to power cycle my hub!

I was previously having this issue with my TP-Link router, so I setup an linksys access point (old router) that solved the issue… but it seems to have returned.

Any recommendation on the process to start debugging why I lose the hub on a HASS reboot (and why a power cycle of the hub would fix it?)

Maybe you lose Wi-Fi connectivity at the hub?

Finally got my smoke sensor. Looks great. Added initial code for Smoke Sensor. Anyone got a sample code for a smoke sensor in HA? Basically, the sensor returns whether there’s smoke and also the density of the smoke.

2 Likes

How does it mount? Is it wired? Running on mains AC power or with DC adaptor?
Or does it run on internal e.g. pp3 battery like “dumb” smoke detectors?

Did you test it? (safely :))

On DX.com mentioned 3v power, so I guess 2xaa(a) batteries?

Hello I am sorry for the noob question but how do I install this custom component? I did the following but without any success. Furthermore about the key, should it be what comes next to “token”,“xxxxxxxxxxxxxxxxxxxxxxxx” on the app?

Here is the process I’ve made without success:

    pi@hassbian:/home/homeassistant/.homeassistant $ sudo mkdir custom_components
pi@hassbian:/home/homeassistant/.homeassistant $ sudo chown homeassistant:homeassistant custom_components/
pi@hassbian:/home/homeassistant/.homeassistant $ sudo su homeassistant
homeassistant@hassbian:~/.homeassistant $ cd custom_components/
homeassistant@hassbian:~/.homeassistant/custom_components $ git clone https://github.com/lazcad/homeassistant

I’ve added the key restarted and got many errors just wanted to make sure I am doing the installation correctly which I guess I am not.

Once again I am sorry for the noob question but I’ve just started today :x:

Thank you

Replying to myself: If anyone has the same issue - use virtualenv. This did the trick for me.

Hi to everyone,

I have a doubt and hope that someone can help me. After xioami did the firmware update where we can see the battery level in HA as @Bieniu says, https://community-assets.home-assistant.io/original/2X/c/c06223f3cb159154da8f01b5c62374e9a394ca84.PNG

How i can show only the battery levels in a group in main page of HA?

thanks

9v battery i think. Mounted to the ceiling using screws

Yeah. Of course i tested it to test the API :grinning: the alarm sounded in about 5 seconds when smoke is detected.

Hi,

new firmware version of smart home gateway 1.4.1_145 someone knows what’s new in this version?

Create template sensors for the battery and then add those to the group^^

~Cheers

You could use that Dynamic icon based on battery level (iOS)

Can someone help me? I am looking forward to test this. Again I know it is a noob question sorry for that.

I’m using this for my iPhones (*3) but unless I am missing something its necessary to define the template for every battery.
Its quite a lot of work. I have ~10 sensors and decided not to bother :slight_smile:

Don’t put the whole repository inside the custom_components. Put only what is inside the components folder in the custom_components folder.

1 Like