Xiaomi Gateway Integration

Yep changed to
sock.bind((self._interface, self.MULTICAST_PORT))

That works! Testing the rest tonight!

Just added RGB + brightness Gateway Light support :slight_smile: also fix some bug related to performance.

2 Likes

Great. If there’s no issue then i’ll update the code and do a final commit

        if self._interface != 'any':
            sock.bind((self._interface, self.MULTICAST_PORT))
            mreq = socket.inet_aton(self.MULTICAST_ADDRESS) + socket.inet_aton(self._interface)
        else:
            sock.bind((self.MULTICAST_ADDRESS, self.MULTICAST_PORT))
            mreq = struct.pack("4sl", socket.inet_aton(self.MULTICAST_ADDRESS), socket.INADDR_ANY)

to install your component xiaomi, you need to install fooxy component first??

After installing the fooxy component, run it … then reinstalling this component, now the xiaomi component works fine (so far).

SO if anyone is experiencing the same, better install the fooxy component too

Please don’t. Both component have the same purposes, which is controlling the zigbee devices on the gateway. It doesn’t make sense to install both. Use either Xiaomi or Aqara component, not both

installing, not activating. I think the fooxy components installs some code that is needed. After I install yours, I activate yours in configuration, and cancel the fooxy

Doesn’t make sense too

@rave

one thing is still not working (minor).

The motion sensor in the front end card is working well (turning yellow when on, and black when off), but the door sensor no ( it does not show anything ither on or off). I can’t use customize to fix this (?)

The motion senor and door sensor both do NOT work in the circle frontend (I don’t know how you call those circles) and this I also cannot change in customize

Try remove foxxy code, and if my component doesn’t work again, then you could be right. But you need to do more and further testing before confirming this is the case

It worked!

This is what shown on my screen. Try remove all customization and see if it is shown correctly. If it is, means there are issues with your customization

@rave

this is my customization, pretty simple

  customize:
     binary_sensor.door_window_sensor_158d00010e25c5:
        friendly_name: Hallway left light switch
        icon: mdi:door
     binary_sensor.motion_sensor_158d000112e1de:
        friendly_name: Motion sensor master bedroom
        icon: mdi:walk
     binary_sensor.motion_sensor_158d000129a3c4:
        friendly_name: Motion sensor livingroom
        icon: mdi:walk

EDIT: icon have to go, they can’t stay there. taking them out it fixes

@rave having a serious issue with the latest version :frowning:

Before the last update my lights where turned on by a motion sensor and the responding nearly real-time/instant.
Running the latest version on my laptop goes fine, but running it on a Raspberry PI introduces a delay of 5-10 sec before the lights turn on.

I’ve triple check the code on the PI and the config’s are 100% the same.
Rolling back to the previous version and the response time (running at the PI) is back to instant.

I’ve checked the CPU usage but that’s quick the same, do you have a clue where to look?
And is there anyone else facing this delay?

Btw, I used the most recent version of today (including the small bugfixes)

Hi @rave, super awesome to hear about the new version! I copied out the files, but unfortunately I am seeing new errors. All of my sensors are working, but I am not seeing a new entity_id for the gateway light. Here is the error I am getting:

17-01-14 22:43:08 homeassistant.components.light: Error while setting up platform xiaomi
Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py", line 150, in _async_setup_platform
    entity_platform.add_entities, discovery_info
  File "/usr/lib64/python3.5/asyncio/futures.py", line 361, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib64/python3.5/asyncio/tasks.py", line 296, in _wakeup
    future.result()
  File "/usr/lib64/python3.5/asyncio/futures.py", line 274, in result
    raise self._exception
  File "/usr/lib64/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.5/site-packages/homeassistant/components/light/xiaomi.py", line 26, in setup_platform
    add_devices([XiaomiGatewayLight(device, 'Gateway Light', gateway)])
  File "/usr/lib/python3.5/site-packages/homeassistant/components/light/xiaomi.py", line 70, in __init__
    XiaomiDevice.__init__(self, device, name, xiaomi_hub)
  File "/usr/lib/python3.5/site-packages/homeassistant/components/light/xiaomi.py", line 35, in __init__
    self.parse_data(device['data'])
  File "/usr/lib/python3.5/site-packages/homeassistant/components/light/xiaomi.py", line 83, in parse_data
    rgbhex = bytes.fromhex("%x" % data['rgb'])
ValueError: non-hexadecimal number found in fromhex() arg at position 6

My config:

[root@hass homeassistant]# cat configuration.yaml | grep xiaomi
xiaomi: !include includes/xiaomi.yaml

[root@hass homeassistant]# cat includes/xiaomi.yaml 
gateways:
  - sid: !secret xiaomi_sid_1
    key: !secret xiaomi_key_1

[root@hass homeassistant]# cat secrets.yaml | grep xiaomi
xiaomi_sid_1: 286c0789d4e5
xiaomi_key_1: tqy8wb5drjymk43q

(sid and key both had minor changes to protect the innocent, etc, etc).

Any idea why I’d be getting the above errors?

EDIT: Interestingly, if I have the gateway light on (any color/brightness level) when I restart hass, I don’t get an error and I see a new entity_id for the gateway light. Does the light have to be on in order for the component to properly load?

Does anyone have experience using this with a US (120V) plug? It looks like it comes with an AU plug that takes 220V, but the documentation I have found seems to indicate it works from 110V-220V, so an adapter like this should work, right?

https://www.amazon.com/gp/product/B00D4OIRTA

I’m not having this issue, the gateway light worked as expected.

Well like I said in my edit, the LED light was there and working after I restarted hass with the LED on. I have full functionality of the light, but got that error the first time around.

It seems I can’t reproduce the error now either. If I have the light off, restart hass, no error. Oh well.

It looks to me that it was expecting a hex value in order to add the entity, but it wasn’t giving a non-hexadecimal number which caused it to freak. I guess once it gets the entity added, that’s no longer a concern.

Tom, this is the adapter I am using with my Gateway and the plug:
https://www.amazon.com/gp/product/B01BH6PW58

I’m in the US, so 120V, and it is working fine. My understanding is that the Gateway can handle an input between 110-220V, so just a plug converter is needed. Any should do, as long as it can physically plug in.

1 Like

I also receive that error sometimes, but everything seems to be working anyway.

EDIT: it happens when the brightness is too low, and the first ARGB component is less than 1F (0F). I’ll submit a PR soon. Also fixed the brightness level not being correct (it was not being converted from 100 to 255 as HA expects).

EDIT2: Pull request submited.

1 Like