And you’re right: the plug does not provide power consumption as it’s the “basic” version (non-Zigbee). But the power strip should provide it, as you can see it in “Mi Home” app. I’ve read miiodevice documentation and teoretically it should provide 2 additional capabilities: power-load and power-usage, but I could’nt retrieve them via the miio command line.
I’ll keep trying to get them later.
EDIT:
I found a new attribute that’s present in power strip (but not in power plug): current. It’s a decimal number and it’s proportional to instant consumption showed in Mi Home, but I don’t know yet the proportions.
I’ve been thinking that the current is expressed as Amps (0.06A), but Xiaomi erroneously calculates the Watts, as in Mi Home app, this is equivalent to about 6.6W. It seems like it thinks that the input voltage is 110V:
Took me 3 hours to find that out, because I’m a complete and utter noob.
I think that’s a pretty big thing, because this way you can override Xiaomi’s target Aqi of 30 to the Aqi of your liking using automations and much more in Home Assistant.
I have another question about your devices. Can you tell me the reported types (“devtype”) of your devices? At discovery there should be some output which looks like this:
_LOGGER.debug("Discovered %s %s with ts: %s" % (self._devtype, self._serial, self._device_ts))
alias: Mi Air Mode
trigger:
platform: state
entity_id: input_select.air_purifier_mode
action:
service_template: shell_command.miair_{{ states.input_select.air_purifier_mode.state.lower() }}
I do not know why when my Home Assistant is working for some time, I cannot switch the xiaomi sockets any more:
2017-07-17 17:16:59 ERROR (Thread-18) [xiaomiplug.device] got error when receiving: timed out
2017-07-17 17:16:59 ERROR (Thread-18) [custom_components.switch.xiaomiplug] Got exception while fetching the state:
2017-07-17 17:17:09 ERROR (Thread-12) [xiaomiplug.device] got error when receiving: timed out
2017-07-17 17:17:09 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/var/lib/home-assistant/xiaomiplug/device.py", line 129, in send
data, addr = s.recvfrom(1024)
socket.timeout: timed out
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/lib/python3.5/asyncio/tasks.py", line 241, in _step
result = coro.throw(exc)
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 1023, in _event_to_service_call
yield from service_handler.func(service_call)
File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/switch/__init__.py", line 109, in async_handle_switch_service
yield from switch.async_turn_off()
File "/usr/lib/python3.5/asyncio/futures.py", line 361, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup
future.result()
File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
raise self._exception
File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
File "/var/lib/home-assistant/custom_components/switch/xiaomiplug.py", line 86, in turn_off
self.switch.stop()
File "/var/lib/home-assistant/xiaomiplug/plug.py", line 20, in stop
return self.send("set_power", ["off"])
File "/var/lib/home-assistant/xiaomiplug/device.py", line 143, in send
raise DeviceException from ex
xiaomiplug.device.DeviceException
I added a reconnect on connection failure. Please update the custom_component. Next step will be a rewrite of the component and use this 3rd party library: https://github.com/SchumyHao/python-miio
@syssi & @xavV, do you have plans try to get this included into the upstream at some point? It is open for PRs and I have even refactored it to be more easily extendable and not so vacuum-centric, but maybe it should be renamed to be less bound to the vacuum part?