Xiaomi Gateway Integration

What do you mean by lost. When I changed from lazcad, I remember at least the entity ID of the illumination gateway sensor changing name.

I just had to adapt my setup once and that’s it.

As far as I know nothing should stop working by moving from @lazcad to @Danielhiversen

Maybe you can try again and see if that was the case.

When I restarted HASS after cloning Daniel’s fork, Sensor I mentioned where not visible on the front end. I also checked dev-state and they were all gone.

This is what I get in log:
2017-06-24 23:00:50 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up platform xiaomi
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py”, line 161, in _async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
File “/usr/lib/python3.4/asyncio/tasks.py”, line 372, in wait_for
return fut.result()
File “/usr/lib/python3.4/asyncio/futures.py”, line 277, in result
raise self._exception
File “/usr/lib/python3.4/concurrent/futures/thread.py”, line 54, in run
result = self.fn(*self.args, **self.kwargs)
File “/home/homeassistant/.homeassistant/custom_components/binary_sensor/xiaomi.py”, line 43, in setup_platform
devices.append(XiaomiGasSensor(device, gateway))
NameError: name ‘XiaomiGasSensor’ is not defined

I don’t know exactly what is wrong with your setup, but @Danielhiversen definitely supports the Gas sensor.

I don’t have one myself, so I cannot help much more. Can anyone else do?

Ohh, there was a bug there. I think I have fixed it now.

3 Likes

Cool. Thanks @Danielhiversen.

This community is definitely an added value to Home Assistant.

I cloned your fork and still get errors.

Here is log maybe you can see what I am doing wrong … ?

I can not see: door/widow sensors, occupancy sensors, switches (old, round), smoke sensor …

LOG:
2017-06-25 19:08:39 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up platform xiaomi
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py”, line 161, in _async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
File “/usr/lib/python3.4/asyncio/tasks.py”, line 372, in wait_for
return fut.result()
File “/usr/lib/python3.4/asyncio/futures.py”, line 277, in result
raise self._exception
File “/usr/lib/python3.4/concurrent/futures/thread.py”, line 54, in run
result = self.fn(*self.args, **self.kwargs)
File “/home/homeassistant/.homeassistant/custom_components/binary_sensor/xiaomi.py”, line 43, in setup_platform
devices.append(XiaomiGasSensor(device, gateway))
NameError: name ‘XiaomiGasSensor’ is not defined
2017-06-25 19:08:42 WARNING (MainThread) [homeassistant.setup] Setup of sensor is taking over 10 seconds.
2017-06-25 19:08:42 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform template is taking over 10 seconds.
2017-06-25 19:08:42 WARNING (MainThread) [homeassistant.setup] Setup of camera is taking over 10 seconds.
2017-06-25 19:08:42 WARNING (MainThread) [homeassistant.setup] Setup of media_player is taking over 10 seconds.
2017-06-25 19:08:43 WARNING (MainThread) [homeassistant.setup] Setup of device_tracker is taking over 10 seconds.
2017-06-25 19:08:43 WARNING (MainThread) [homeassistant.setup] Setup of automation is taking over 10 seconds.
2017-06-25 19:08:44 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform speedtest is taking over 10 seconds.
2017-06-25 19:08:44 WARNING (MainThread) [homeassistant.components.media_player] Setup of platform cast is taking over 10 seconds.
2017-06-25 19:09:11 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
File “/usr/lib/python3.4/concurrent/futures/thread.py”, line 54, in run
result = self.fn(*self.args, **self.kwargs)
File “/home/homeassistant/.homeassistant/custom_components/xiaomi.py”, line 417, in push_data
device.push_data(jdata)
File “/home/homeassistant/.homeassistant/custom_components/xiaomi.py”, line 471, in push_data
self.schedule_update_ha_state()
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity.py”, line 301, in schedule_update_ha_state
self.hass.add_job(self.async_update_ha_state(force_refresh))
AttributeError: ‘NoneType’ object has no attribute ‘add_job’
2017-06-25 19:09:11 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Bateria - Drzwi wejściowe, the state is unknown.
2017-06-25 19:09:11 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Bateria - Drzwi balkonowe, the state is unknown.
2017-06-25 19:09:11 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Bateria - Okno balkonowe lewe, the state is unknown.
2017-06-25 19:09:11 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Bateria - Okno balkonowe prawe, the state is unknown.
2017-06-25 19:09:11 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Bateria - Okno Garderoba, the state is unknown.
2017-06-25 19:09:11 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Bateria - Okno Sypialnia, the state is unknown.
2017-06-25 19:09:11 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Bateria - Okno Pokój Zosi, the state is unknown.
2017-06-25 19:09:11 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Bateria - Okno Kuchnia, the state is unknown.
2017-06-25 19:09:11 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Bateria - Lodówka, the state is unknown.
2017-06-25 19:09:11 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Bateria - Ruch Wejście, the state is unknown.
2017-06-25 19:09:11 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Bateria - Ruch Korytarz, the state is unknown.
2017-06-25 19:09:11 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Bateria - Ruch Garderoba, the state is unknown.
2017-06-25 19:09:11 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Bateria - Ruch Kuchnia, the state is unknown.
2017-06-25 19:09:11 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Bateria - Ruch Sypialnia, the state is unknown.
2017-06-25 19:09:11 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Bateria - Ruch Łazienka, the state is unknown.
2017-06-25 19:09:11 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Bateria - Ruch WC, the state is unknown.
2017-06-25 19:09:11 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Bateria - Przełącznik RTV, the state is unknown.
2017-06-25 19:09:11 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Bateria - Przełącznik Kuchnia, the state is unknown.
2017-06-25 19:09:11 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Bateria - Przełącznik Zosia, the state is unknown.
2017-06-25 19:09:11 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Bateria - Czujnik dymu, the state is unknown.
2017-06-25 19:09:24 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
File “/usr/lib/python3.4/concurrent/futures/thread.py”, line 54, in run
result = self.fn(*self.args, **self.kwargs)
File “/home/homeassistant/.homeassistant/custom_components/xiaomi.py”, line 417, in push_data
device.push_data(jdata)
File “/home/homeassistant/.homeassistant/custom_components/xiaomi.py”, line 471, in push_data
self.schedule_update_ha_state()
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity.py”, line 301, in schedule_update_ha_state
self.hass.add_job(self.async_update_ha_state(force_refresh))
AttributeError: ‘NoneType’ object has no attribute ‘add_job’

I do not see a new repo commit yet, so possibly it is not yet fixed/released.

1 Like

Oh, ok … too quick :wink:

Hey all,
I’ve just upgraded to Dan’s fork and now I get the below errors. Any Idea what i’m missing?
I copied the components folder contents from Dan’s fork and pasted it in my custom_components folder (After removing the old stuff), installed pycrypto just in case.

I didn’t change my config, its still:

xiaomi:
gateways:
- sid:
key: 25pxxxxxxxx2fqrl

2017-06-25 23:55:30 ERROR (Thread-8) [custom_components.xiaomi] No gateway discovered 2017-06-25 23:55:30 ERROR (MainThread) [homeassistant.setup] Setup failed for xiaomi: Component failed to initialize.

2017-06-26 00:10:03 WARNING (MainThread) [homeassistant.setup] Setup of xiaomi is taking over 10 seconds.
2017-06-26 00:10:03 INFO (Thread-12) [custom_components.xiaomi] Gateway finding finished in 5 seconds
2017-06-26 00:10:03 INFO (Thread-12) [custom_components.xiaomi] Discovering Xiaomi Gateways (Try 3)
2017-06-26 00:10:03 WARNING (MainThread) [homeassistant.components.media_player] Setup of platform cast is taking over 10 seconds.
2017-06-26 00:10:08 INFO (Thread-12) [custom_components.xiaomi] Gateway finding finished in 5 seconds
2017-06-26 00:10:08 ERROR (Thread-12) [custom_components.xiaomi] No gateway discovered
2017-06-26 00:10:08 ERROR (MainThread) [homeassistant.setup] Setup failed for xiaomi: Component failed to initialize. 2017-06-26 00:10:08 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=message=The following components and platforms could not be set up: * xiaomi Please check your config, notification_id=invalid_config, title=Invalid config, domain=persistent_notification, service_call_id=1978049360-5, service=create>
2017-06-26 00:10:08 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state persistent_notification.invalid_config=The following components and platforms could not be set up: * xiaomi

Ok, FINALLY my Xiaomi stuff arrived and I made it work so far. At least I can see the Gateway (light) and the sensors that came with the starter pack.

But when I try to turn on the gateway light, I can see the following error in the log file:

2017-06-26 11:32:08 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/lib/python3.4/asyncio/tasks.py”, line 233, in _step
result = coro.throw(exc)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py”, line 1015, in _event_to_service_call
yield from service_handler.func(service_call)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/light/init.py”, line 265, in async_handle_light_service
yield from light.async_turn_on(**params)
File “/usr/lib/python3.4/asyncio/futures.py”, line 388, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.4/asyncio/tasks.py”, line 286, in _wakeup
value = future.result()
File “/usr/lib/python3.4/asyncio/futures.py”, line 277, in result
raise self._exception
File “/usr/lib/python3.4/concurrent/futures/thread.py”, line 54, in run
result = self.fn(*self.args, **self.kwargs)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/light/xiaomi.py”, line 109, in turn_on
if self.xiaomi_hub.write_to_hub(self._sid, **{self._data_key: rgbhex}):
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/xiaomi.py”, line 393, in write_to_hub
data[‘key’] = self._get_key()
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/xiaomi.py”, line 425, in _get_key
encryptor = AES.new(self.key.encode(), AES.MODE_CBC, IV=init_vector)
File “/home/homeassistant/.homeassistant/deps/Crypto/Cipher/AES.py”, line 95, in new
return AESCipher(key, *args, **kwargs)
File “/home/homeassistant/.homeassistant/deps/Crypto/Cipher/AES.py”, line 59, in init
blockalgo.BlockAlgo.init(self, _AES, key, *args, **kwargs)
File “/home/homeassistant/.homeassistant/deps/Crypto/Cipher/blockalgo.py”, line 141, in init
self._cipher = factory.new(key, *args, **kwargs)
ValueError: Key cannot be the null string

pycrypto is installed…

Requirement already satisfied (use --upgrade to upgrade): pycrypto in /usr/local/lib/python3.4/dist-packages
Cleaning up…

Thanks for your help,

Daniel

One other thing: the sid has to be in lowercase without the ":"

{"ringtone_id":"13", "ringtone_vol":"8", "gw_sid":"286c0789161d"}

Hi,

I received the new Aqara temp sensor a few days ago: http://www.gearbest.com/access-control/pp_626702.html

At first it didn’t appear in the XIaomi App, but now it shows: reports temp/humidity and pressure in the app, but is not showing in HA.

Any luck with this one?

ask @rave , he is not allowing the integration of the component in HASS, hence less developer are improving the component

Hi Guys,

Thanks for the work, it’s really awesome to have this.

I’ve installed it on mine and everything seems to work, buttons, door sensors and motion all shows up on HA with status etc and I can control the hub light. Friendly names set up and ID’ed which sensor is which. However, I can’t get the automation to work properly. I followed the readme for the triggers and the buttons work fine.

For the Door sensors, I had to use on/off status as the trigger rather than motion.

For Motion sensors, I tried both event and status exactly as in the readme but neither worked (below). HA logs the on/off actions from the sensors and on the status page it also shows the motion status but the automation just won’t get triggered for some reason. (FYI, I tried this same thing but with button click trigger and it works, so I am just failing the trigger bit…)

Do I need to add extra code on the config file to get the sensor status and events working other than the “Xiaomi:” bits in the readme? I am quite new to HA and so I could be missing something very basic. Any ideas would be much appreciated.

alias: Test
trigger:
  platform: event
  event_type: motion
  event_data:
    entity_id: binary_sensor.motion_sensor_XXXXXXX
action:
  service: notify.GPhone
  data:
    message: "Hello, it works!"
    title: "Yo"

Why is this still not integrated into main HA repo? We have so many forks now because of that… and the development is scattered and slow… @rave you could just merge your repo to HA, and make any improvements you are planing to do latter directly to HA, or give permission to someone else to do that.

4 Likes

Which is the difference between

  trigger:
    platform: event
    event_type: motion
    event_data:
        entity_id: binary_sensor.motion_sensor_158d000113702f

and

trigger:
      - platform: state
        entity_id:  binary_sensor.motion_sensor_158d000113702f
        from: 'off'
        to: 'on'

I guess one’s an event and the other’s a state, I tried both and neither worked for me. (and also with motion/no motion as the state)

the second I have in my configuration and it works. Just wondering if the first is better or different

I might try that again tonight, there must be something elementary that I missed…

When you installed your sensors, did you have to add other lines other than these four lines?

xiaomi:
 gateways:
   - sid:
     key: xxxxxxxxxxxxxxxx

This is what I have and everything is working. :slight_smile:

xiaomi:
  gateways:
    - sid: !secret xiaomi_sid_bedroom2
      key: !secret xiaomi_key_bedroom2
    - sid: !secret xiaomi_sid_bedroom3
      key: !secret xiaomi_key_bedroom3

and

- id: auto_foyer_on
  alias: On foyer light when there is movement
  trigger:
    - platform: state
      entity_id: binary_sensor.door_window_sensor_xxxxxxxxxx
      to: 'on'
    - platform: state
      entity_id: binary_sensor.motion_sensor_xxxxxxxxxx
      to: 'on'
  action:
    - service: homeassistant.turn_on
      entity_id: switch.foyer
    - service: notify.ios_iphone
      data:
        message: "Motion detected! Foyer light switched on."