Xiaomi Gateway Integration

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

Wrong mac address?

Is it necessary?
I only got the key.

Worth a try.

Nope.

This was not the solution. I can see all the sensors but not gateway.

Only the key should work.
Make sure the firmware of the gateway not is very old.

My fault. FW update was the solution. Thanks for the heads up.

Hello

I am completely lost trying to understand HA, probably the installation of hass.io has been so simple that I lack basic knowledge, and the examples in documentation apaprently do not do anything remotely useful and every test requires a reboot of the raspberry pi that takes AGES.

Can anyone please post an example that is just one file configuration.yaml (separation in multiple files with includes I understand that is good and necessary for real, complex, installations, but makes very difficult learning for a newbie) that uses a xiaomi gateway and a xiaomi switch and a xiaomi temperature sensor and as few other things as possible? Maybe with some simple functionality, for example, the gateway emits some sound every XX minutes when the temperature is over certain level, and the light in the gateway toggles on/off everytime the switch is pressed. Or something similar to that.

I cannot find examples that are simple, real/tangible and concise, and the documentation in the xiaomi component in https://home-assistant.io/components/ for xiaomi is almost non-existant

Thank you

Hi @pko

This might be helpful, I split my Xiaomi config into a separate package.

2 gateways and a few sensors. The automation switches on the GW light when there is movement.

https://github.com/Data-Monkey/Home-Assistant-Config/blob/master/includes/packages/Xiaomi_Package.yaml