Xiaomi Gateway Integration

After a whole night of not connecting, I somehow finally got my gateway to connect. I’ve followed the steps and got the LAN communication protocol password and turned it on. Added it to the configuration.yaml like so

xiaomi:
  gateways:
    - sid:
      key: pcnee20omc4bidal

yamllint.com says it’s valid, yet I’m getting this error… What am I doing wrong? :frowning:

Given the other errors you’re having I’d say your problem isn’t the gateway configuration. Do they still occur if you comment (# at start of line) out the xiaomi stuff?

Is the gateway on the same switch/router as your server?

You can try just with

xiaomi:

But I wouldn’t hold my breath that would fix it. I’m very much an amateur so my ability to help is limited. If it’s still giving those other errors probably best to make a new post, if you can’t find the answer in existing ones, in the Configuration forum as that way those who are more experienced with problems like that can help you.

Remember Home Assistant is very much in development so having issues getting it working ok is sort of normal. It took me about a week and three times I had to wipe the sd and start again to get my server working, though I did learn so much along the way.

Once you’ve solved those other problems hopefully the xiaomi stuff will work.

alias: Cube Brightness Chambre
trigger:
  platform: event
  event_type: cube_action
  event_data:
      entity_id: binary_sensor.cube_158d00011064e0
      action_type: rotate

action:
  service: homeassistant.turn_on
  data_template:
      entity_id: group.lights_chambre
      brightness: >
                    {% set state = states.group.lights_chambre.attributes.brightness + (trigger.event.data.action_value|float) -%}
                    {%-  if state > 255 -%}
                       {%- set state  = 255 -%}
                    {%-  elif state < 0 -%}
                       {%- set state  = 0 -%}
                    {%- endif %}
                    {{ state }}

Tried this but it’s not working :frowning:

What is not working?
Errors in your log?
Have you tested your code at your_ip:8123/dev-template ?

I don’t know how to use the dev-template tool :frowning:

Hi @rave and @Danielhiversen.
What are your maturity criteria to add the beta xiaomi component to HA main?
I’ve been watching the emergence of the ikea TRÅDFRI component go from nothing to included in main in 2 weeks and (imo) it’s at nowhere near the level of maturity and received the amount of community testing as this huge effort!

1 Like

I agree, and I think it should have been added to the main HA repo a long time ago.

But it is up to @rave to decide when he wants to do so.
Rave has written some arguments for not adding it to the main repo earlier. Even if we disagree with his decision, we have to respect it.

1 Like

I would first test with a single light, not a whole group. Also maybe it’s the float, try it with int. But indeed a bit more specifics why and what does not work would be nice…

1 Like

I also agree we should be moving to the main repo. The component is working pretty solid. API is stable. New things are added, but so far nothing has been broken. Only known issue is that door/window and motion sensors flip to “open”/“movement” state on power loss, but this can be solved by removing/making optional functionality.

I have found the reason I was getting the “Invalid Key” messages.

In order for the key to work, the HA server needs to receive a Token from the gateway. This Token is only sent over IP multicast, not as a direct unicast to your HA server. If your HA server does not receive these multicast packets, it will not have all the data it needs to properly calculate the key that the gateway expects, and it will attempt with an invalid key.

For whatever reason my ESXi-hosted virtual machine running the HA installation is not receiving the multicast packets even though it is supposed to be on the same subnet and switch.

I installed Domoticz on a windows laptop that I could connect directly to the same WLAN SSID that the gateway is connected to, and it can control the gateway light just fine. I’d imagine HA would do the same, but I couldn’t bother trying to get it installed on Windows.

Now I just need to figure out why these multicast packets don’t reach the VM.

1 Like

I’m replying to Ordep so (s)he’ll also see this. I can now confirm what I wrote above about why the key was invalid.

I have my HA network segregated to VLAN 60 so I can keep it away from the secure networks.
I have a vSwitch in my ESXi 5.5 host that has a Trunk port group with VLAN ID 4096 (All) and another with VLAN ID 60 which is for home automation use. I had my firewall connected to the Trunk port group and my HA machine connected to VLAN 60 port group. As long as it was there, it would not receive any multicast packets. When I put the HA machine into the trunk port group and configure a VLAN 60 in it, suddenly it can receive the multicasts and no more Invalid Key messages! I can control the GW fully now.

Lesson learned: On your HASS host, run “tcpdump net 224.0.0.0/4” and see if you can spot multicast packets from your gateway. If not, your HASS can’t receive the token from the gateway and that’s why your key comes across as invalid.

Next stop: VMWare forums!

thanks with an int I see this in error log:

17-04-14 21:49:12 ERROR (MainThread) [homeassistant.core] Invalid service data for light.turn_on: expected int for dictionary value @ data[‘brightness’]. Got ‘12.95’

@rave I also agree that this is ready for being included in the main HA repo. You can have a personal fork of HA so that you can quickly work on the component and submit PR’s to HA…

So you need to convert it to an int

I have a Gateway and several sensors which worked flawlessly until recent firmware update. Now I cannot connect the gateway via the Mi Home App after reset via router. Only way I can connect is via a mobile phone tether. Is it possible to use HA if I am unable to connect gateway using Mi Home App? Newbie.

Can someone please help me to setup the xiaomi button to switch on all the lights in a single room?

this is the code in my automation.yaml

- alias: switch on lights in dining room
  trigger:
- platform: event
  event_type: click
  event_data:
    entity_id: binary_sensor.switch_15xxxxxxx6b
    click_type: single
  action:
    service: light.toggle
    entity_id: 
     - group.lights_diningroom

where am I wrong?

thank you!

I can’t seem to quote properly but…

I don’t think the dash belongs next to platform for the trigger and perhaps not the list of entity IDs in your action. Try

- alias: switch on lights in dining room
  trigger:
    platform: event
    event_type: click
    event_data:
        entity_id: binary_sensor.switch_15xxxxxxx6b
        click_type: single
  action:
    service: light.toggle
    entity_id: group.lights_diningroom

If that does not work instead of group on last line put lights individually with comma between

  action:
    service: light.toggle
    entity_id: light.dining, light.tableside, light.lamp

Anyone got the Xiaomi Kettle and wanting to try and integrate into HA?

http://www.gearbest.com/kitchen-appliances/pp_366782.html

Is cool but I would not rely automating an object with electricity and hot water

I’m sure it’d have a water sensor inside, so it wouldn’t boil if empty etc.