Xiaomi Gateway Integration

The sensor gets polled if there is continuous motion. The interval is 30 seconds. Take look here: Xiaomi Human / Body / Motion Sensor - Timeout - #21 by sjee

Than i’m stuck. Just relaunched the HA. And then in the logs i see sensor reporting motion.
Definetly there is no motion involved and the logs in Mi Home prove that.
What steps should i take to debug further?

2017-08-17 08:49:06 DEBUG (Thread-8) [homeassistant.components.xiaomi] PUSH >> : {‘status’: ‘motion’, ‘voltage’: 3015}
2017-08-17 08:49:37 DEBUG (Thread-8) [homeassistant.components.xiaomi] PUSH >> : {‘status’: ‘motion’, ‘voltage’: 3015}
2017-08-17 08:50:07 DEBUG (Thread-2) [homeassistant.components.xiaomi] PUSH >> : {‘status’: ‘motion’, ‘voltage’: 3015}
2017-08-17 08:50:38 DEBUG (Thread-2) [homeassistant.components.xiaomi] PUSH >> : {‘status’: ‘motion’, ‘voltage’: 3015}
2017-08-17 08:51:09 DEBUG (Thread-3) [homeassistant.components.xiaomi] PUSH >> : {‘status’: ‘motion’, ‘voltage’: 3015}

In the past it was enough to do “real motion” in front of the motion sensor. A few minutes later it will fall back to no_motion and the problem is gone. If this does not help. Remove the battery for a moment.

The motion is correctly reported in the log of MiHome app. So it is hard to blame the hardware issue.
Currently fixed it by removing and re adding to the MiHome.

2017-08-17 09:01:10 DEBUG (Thread-4) [homeassistant.components.xiaomi] PUSH >> : {‘no_motion’: ‘120’}

So is there anyway to dive deeper and gather more information by debugging?

It’s a firmware issue. The communication between your gateway and the chinese servers (mi home app) uses another protocol. Home assistant uses the local procotol which has some flaws. Just monitor (debug log) the events. You will see home assistant just shows what’s reported from the gateway. If the gateway reports a lie we are lost.

If you want to go deeper: Build a zigbee sniffer

and decode the traffic between gateway and motion sensor. Is the issue visible here, too?

So indeed they have changed something in 149. So recommendation is not to update. I believe nobody knows yet how to downgrade on Xiaomi…
Wonder if the all in one zigbee USB stick developed by a french guy and which he states can control xiaomi will make it to the market

The “stuck motion sensor” is not an issue of 149. It pops up from time to time unfortunately and is a pretty old bug. I had the same problem right after the update to 148.

I have enabled logging, edited the xiaomi file and this is from the states page for the switch:

Power consumed: null
Load power: null
friendly_name: Night Light
In use: null
battery_level: 100
icon: mdi:lightbulb-on

Nothing is usable here. Meanwhile as of before the current power value is valid in the mi home app.

And this is the event it creates when switched on:
2017-08-17 16:44:16 DEBUG (Thread-6) [homeassistant.components.xiaomi] PUSH >> <Entity Wall Switch LN_158dxxxxxxxxx: on>: {'channel_0': 'on'}

A pity. The events does not contain the informations at the local network protocol so far.

I now tried this:

  - platform: template
      entity_id: switch.plug_158dXXXXXXXXX
      value_template: '{{ states.switch.plug_158dXXXXXXXXX.attributes["Load power"] < 40 }}'

…and without the “-” before platform:, both gives me errors on automation at startup.

2017-08-17 15:06:56 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: [entity_id] is an invalid option for [automation].

yeah you are right. you are using a platform template for trigger and it doesn’t have the entity_id part.

I finally integrated two of the plugs last night, and noticed the same thing on the Mi app.
I would love to be able to capture daily consumption through HA.

Basically I have a package and for each battery-powered sensor, this is what I add for the package:

sensor:
### Battery level for Bedroom Temperature Sensor ###
  - platform: template
    sensors:
      battery_bedroom_temp_sensor:
        friendly_name: 'Sensor Quarto'
        value_template: "{{ states.sensor.temperature_158dxxxxxxxxxx.attributes.battery_level|default(-1)|int if states.sensor.temperature_158dxxxxxxxxxx is not none }}"
        unit_of_measurement: '%'
        icon_template: '{% if states.sensor.temperature_158dxxxxxxxxxx.attributes.battery_level == 100 %}
                           mdi:battery
                        {% elif states.sensor.temperature_158dxxxxxxxxxx.attributes.battery_level >= 90 %}
                           mdi:battery-90
                        {% elif states.sensor.temperature_158dxxxxxxxxxx.attributes.battery_level >= 80 %}
                           mdi:battery-80
                        {% elif states.sensor.temperature_158dxxxxxxxxxx.attributes.battery_level >= 70 %}
                           mdi:battery-70
                        {% elif states.sensor.temperature_158dxxxxxxxxxx.attributes.battery_level >= 60 %}
                           mdi:battery-60
                        {% elif states.sensor.temperature_158dxxxxxxxxxx.attributes.battery_level >= 50 %}
                           mdi:battery-50
                        {% elif states.sensor.temperature_158dxxxxxxxxxx.attributes.battery_level >= 40 %}
                           mdi:battery-40
                        {% elif states.sensor.temperature_158dxxxxxxxxxx.attributes.battery_level >= 30 %}
                           mdi:battery-30
                        {% elif states.sensor.temperature_158dxxxxxxxxxx.attributes.battery_level >= 20 %}
                           mdi:battery-20
                        {% elif states.sensor.temperature_158dxxxxxxxxxx.attributes.battery_level >= 10 %}
                           mdi:battery-10
                        {% else %}
                           battery-outline
                        {% endif %}'
        entity_id: sensor.temperature_158dxxxxxxxxxx

### Battery level lower than 10% ###
  - platform: template
    sensors:
      bedroom_sensor_battery_low:
        value_template: '{{ states.sensor.temperature_158dxxxxxxxxxx.attributes.battery_level < 10 }}'
        friendly_name: 'Bedroom sensor battery is low'

alert: 
### Alert via iOS notification when Bedroom sensor battery < 10% ###
  bedroom_sensor_battery_low:
    name: Bedroom sensor battery is low
    entity_id: sensor.bedroom_sensor_battery_low
    state: 'True'
# Repeat in minutes (1 day = 1440 minutes)
    repeat: 1440
    skip_first: False
    notifiers:
      - ios

What is shown:
image

Please bare in mind that alert repetition (in my case, once per day), period is back to zero on every HASS restart.

8 Likes

Does the double key wireless switch support double click on each button?

It supports double click on any key: Xiaomi - Home Assistant

Events of the round wireless button: single, double, hold, long_click_press, long_click_release
Events of the squared wireless button: single, double
Events of the wireless wall switch (single-key): single
Events of the wireless wall switch (double-key): single, single, both

if you don’t update to the latest firmware :slight_smile:

Thanks for this!

2 Likes

I am to interested in if Kettle can be integrated :slight_smile: It is bluetooth so perhaps an approach like for the mi flora (already integrated) can be used?

The kettle doesnt allow remote boil using the official app either.

As far as I am aware, I dont think the functionality is there yet. Only setting the temperature for keeping the heat at a specific temperature via the app.

I hope there is an update one day that allows the remote boil function, when that happens, we can be sure someone will connect it to Home Assistant.

Just got a new square button.
Aesthetically good - I prefer to the original (I have 4 of them)
Functionally no where near as good. I hope its a limitation in the gateway firmware and can be changed, and not in the button.

Hey there,

So far is my xiaomi setup working, but I cannot access the gateway. I.e. Changing the light. It is not listed under light.xxxx devices.

Log gives:
2017-08-18 17:07:05 ERROR (Thread-4) [PyXiaomiGateway] Not a device

Any suggestions?

Thanks