Integration in home assistant
Hi,
does someone plan to integrate this into home assistant?
A very basic support is already available in this repository, I have avoided submitting it yet as I have felt the library has not received enough testing (e.g. the problem described in #1 is just fixed since yesterday.
Ah sorry! I just saw the documentation on it. Can you add some lines on what is currently possible via home assistant? E.g. start the robot in an action? This would help to decide if I should go through the install and test it 😃
It's currently a switch component, which can be used to start vacuuming (turning on) and stopping and going back to charger (turning off). Besides that it can display some information about the state of the vacuum, I haven't found out a nice way to allow controlling the fanspeed yet.

Hi rytilahti,
Many thanks for all your great work.. I just started to integrate the Xiaomi Mi Air Purifier and wifi mi plug into HASS (there). It works perfectly with one device, but as soon as I put 2 (air purifier + wifi plug), it leads to a checksum error:
got error when receiving: wrong checksum, read b'ffffffffffffffffffffffffffffffff', computed b'd244a4aeb1074936b12dcac897c0799f'
Do you have any idea what is happening there??
My config is as folow: switch:
- platform: xiaomi host: 192.168.1.103 name: air_purifier token: 90e359e00383bc7912ba845388fa8110
- platform: xiaomi host: 192.168.1.110 name: switch_chauffe_eau token: 3d497faf3391594bc496ab4794a770e9
Traceback (most recent call last): File "/usr/lib/python3.4/asyncio/tasks.py", line 233, in _step result = coro.throw(exc) File "/usr/local/lib/python3.4/dist-packages/homeassistant/core.py", line 1014, in _event_to_service_call yield from service_handler.func(service_call) File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/switch/init.py", line 108, in async_handle_switch_service yield from switch.async_turn_off() 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 "/home/pi/.homeassistant/custom_components/switch/xiaomi.py", line 89, in turn_off File "/usr/local/lib/python3.4/dist-packages/xiaomi/xiaomi.py", line 142, in stop return self.send("set_power", ["off"]) File "/usr/local/lib/python3.4/dist-packages/xiaomi/xiaomi.py", line 127, in send m = Message.parse(data) File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 165, in parse return self.parse_stream(BytesIO(data), context, **kw) File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 176, in parse_stream return self._parse(stream, context, "parsing") File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 849, in _parse subobj = sc._parse(stream, context, path) File "/usr/local/lib/python3.4/dist-packages/construct/core.py", line 2709, in _parse raise e.class("%s\n %s" % (e, path)) construct.core.ChecksumError: wrong checksum, read b'ffffffffffffffffffffffffffffffff', computed b'2075dd492010d77ea224728458a0a06a' parsing -> checksum
Just created a topic on homeassistant as I think it's mainly related to it.
I'd seriously appreciate if you'd be willing to try to get your changes included to this repository instead of creating a fork to maintain..
Now that being said, I think it may indeed be an issue how homeassistant handles the config files. The common way is to pass a list inside the same platform definition and then loop over it to create the linked devices, see e.g. https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/light/yeelight.py#L81 .
Sorry for your first point Rytilahti, I'm quite new to Github. I will make a fork of your repo and include those changes. In the meantime I found out a work around: resend the token to Utils each time we send a request. In that case I can control multiple devices.
Ok, not a problem. And yeah, the token handling in the library is currently awfully done, good to hear that you got it working though!
I have been using this on HA for a few weeks now and it works very nice, you should submit it!
I'm getting this on my log when I restart HA but still works perfectly!
2017-05-27 22:02:21 ERROR (<concurrent.futures.thread.ThreadPoolExecutor object at 0x2ad41a109dd8>_1) [mirobo.vacuum] got error when receiving: timed out
2017-05-27 22:02:21 ERROR (<concurrent.futures.thread.ThreadPoolExecutor object at 0x2ad41a109dd8>_1) [custom_components.switch.mirobo] Got exception while fetching the state: timed out
Thanks a lot for creating this!
@jcastro I'm getting the same errors in my HA log, although up until now it's been working, I have a automation to start the mi robot later today so I'll see for sure if it still responds, this is pretty cool!
Also agree on that this should be submitted :)
Not seeing the error mentioned here, running it in HA for 3 weeks now. Only thing I'm seeing is that the bot turns on if the boolean is switched to on, and then the boolean immediately switches back to off. After some time HA sees it is on and reflects the correct state.
You should seriously consider to create a PR on HA for this component, as it works flawlessly. Thanks for your work!
I have tested this for a few days now and it works great (despite the errors/warning in the log as mentioned above) being part of HA and my automations there! Thanks again for this! Just awesome!
nice one!. I got mine automated so when no one is at home it turns on. Then when someone arrives it turns off
@xavV : Where to put your files? I just renamed your xiaomi.py to xiaomy.plug.py (because as @flyguy729 I too have already the Gateway as xiaomi.py integrated) and put it under custom_components. Anything more? Because I only get the following error:
ERROR (Thread-3) [custom_components.switch.xiaomi.plug] Got exception while fetching the state: cannot import name 'Device'
Any ideas? +1 on @jcastro. I'd love to see it being integrated into HomeAssistant
@lv-88 Cool, do you have the automations for the scheduler somewhere on github by any chance? I already created template sensors for everything except the scheduler. The scheduling would be the finishing touch :)
Hi all, I am trying to use it in HASS 0.46 and I get the following error: ERROR (Thread-5) [custom_components.switch.mirobo] Got exception while fetching the state: must be str, not int Any idea where the issue can be?
Thank you!
@jcastro the error happens sometimes when the robot doesn't answer. Maybe the component could do a retry if it fails to receive a response, but this is not a priority at the moment.
@UltraSub the toggling issue sounds like something that could be avoided by setting the is_on in the component after a successful start.
@UltraSub, @jcastro, I haven't yet submitted it to homeassistant because lack of polishing (that error, maybe a custom card for vacuums in general like @lv-88 had done?) and the fact that it'd require writing some documentation about how to fetch the token and how to use it. It's on my todo list though.
@santirguez could you modify the line containing the error by adding exc_info=True (_LOGGER.error("Got exception while fetching the state: %s" % ex, exc_info=True) and see which line causes the error?
@UltraSub I don't have it up somewhere yet, the automations are really simplistic, they are based on the same concept like the Alarm Clock code on the HA forums. Works great for me! Here is one of the automations (the first one activated in the screenshot) You can tweak these to make it fit you.
- alias: 'Mi Week (workdays)'
trigger:
platform: template
value_template: '{{ states.sensor.time.state == states.sensor.mi_time.state }}'
condition:
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: state
entity_id: !secret emil_device
state: 'not_home'
action:
- service: homeassistant.turn_on
entity_id:
- switch.mi_robot_vacuum
And then the sensor templates (that use input_sliders as you can see, so create those as well and you're good to go!):
- platform: template
sensors:
mi_time_hour:
value_template: '{{ states("input_slider.mi_timehour") | round(0) }}'
friendly_name: 'Hour'
mi_time_minutes:
value_template: '{{ states("input_slider.mi_timeminutes") | round(0) }}'
friendly_name: 'Minutes'
mi_time:
friendly_name: 'Time'
value_template: '{{ "%0.02d:%0.02d" | format(states("input_slider.mi_timehour") | int, states("input_slider.mi_timeminutes") | int) }}'
icon_template: mdi:clock
Hi @rytilahti
Thank you for the hint. It was catching the token as int so i put the token in 'XXXXXXXXXX' instead of XXXXXXXXX format, and now working as a charm!
Thank you!
@rytilahti I could help you write the documentation!