Xiaomi Gateway Integration

how to do this?

energy (kwh) and power (w) not voltage

Add to your configuration.yaml following lines:
logger: default: warning logs: custom_components.xiaomi: debug custom_components.sensor.xiaomi: debug custom_components.switch.xiaomi: debug custom_components.binary_sensor: debug custom_components.light.xiaomi: debug

Could you show example from debug log?

not sure which version. Mine does not

I have that already. WHat shall I look for in the log?

17-04-19 21:24:26 DEBUG (Thread-8) [custom_components.xiaomi] << {'cmd': 'read_ack', 'short_id': 24419, 'sid': '______________', 'model': 'plug', 'data': '{"voltage":3600,"status":"off","inuse":"0","power_consumed":"117","load_power":"0"}'}

Switch plug and go to developer tools about section. There is log window. Latest entities (bottom one) should be about plug.
Something like >>PUSH a{…

i have
manual
how to use
forum on xxxx
local area network communication protocol (former chinese menu)
gateway information (former chinese menu)

where shall I look?

Instructions are related to hass
Open hass and go to developer tools, about section

17-04-19 21:25:57 DEBUG (Thread-5) [custom_components.xiaomi] PUSH >> : {‘voltage’: 3600, ‘load_power’: ‘0’, ‘status’: ‘off’, ‘power_consumed’: ‘117’, ‘inuse’: ‘0’}

Great!
Could you post example with turned on plug?
BTW wich fork do you use? Is power details available in you interface?

No fork
Power details are available in MiHome app only

Could you please post debug log with turned on plug

Does anyone know how difficult it would be to ad a radio switch to this component? Ive managed to get local radio streaming through the hub, just after a way to turn it on and off as its now set as the default station.

cheers

1 Like

Wow, this is the missing piece!
I will check it out in a few hours, just got some new plugs, hopefully they have the data.
Is there anything specific you are after?

unfortunately no usage data here:

 [custom_components.xiaomi] << {'short_id': 55552, 'data': '{"voltage":3600,"status":"on","inuse":"0"}', 'sid': 'XXX', 'cmd': 'write_ack', 'model': 'plug'}

might try the newest version of the code… I think I am on Daniel’s fork

OK, updated code worked.
So I have the switch with a lamp plugged in

Switch on - Lamp on

17-04-20 20:17:20 DEBUG (Thread-11) [custom_components.xiaomi] >> b'{"data": {"status": "on", "key": "xxx"}, "cmd": "write", "sid": "aaa"}'
17-04-20 20:17:20 DEBUG (Thread-11) [custom_components.xiaomi] << {'data': '{"voltage":3600,"status":"off","inuse":"0","power_consumed":"4","load_power":"0"}', 'cmd': 'write_ack', 'sid': 'aaa', 'short_id': 16269, 'model': 'plug'}
17-04-20 20:17:20 DEBUG (Thread-17) [custom_components.xiaomi] MCAST (report) << {'data': '{"status":"on"}', 'cmd': 'report', 'sid': 'aaa', 'short_id': 16269, 'model': 'plug'}
17-04-20 20:17:20 DEBUG (Thread-1) [custom_components.xiaomi] PUSH >> <Entity Plug_aaa: on>: {'status': 'on'}
17-04-20 20:17:34 DEBUG (Thread-17) [custom_components.xiaomi] MCAST (heartbeat) << {'data': '{"voltage":3600,"status":"on","inuse":"1","power_consumed":"4","load_power":"12"}', 'cmd': 'heartbeat', 'sid': 'aaa', 'short_id': 16269, 'model': 'plug'}
17-04-20 20:17:34 DEBUG (Thread-11) [custom_components.xiaomi] PUSH >> <Entity Plug_aaa: on>: {'status': 'on', 'voltage': 3600, 'load_power': '12', 'power_consumed': '4', 'inuse': '1'}

keep it on and wait …

17-04-20 20:22:53 DEBUG (Thread-17) [custom_components.xiaomi] MCAST (heartbeat) << {'data': '{"voltage":3600,"status":"on","inuse":"1","power_consumed":"4","load_power":"13"}', 'cmd': 'heartbeat', 'sid': 'aaa', 'short_id': 16269, 'model': 'plug'}
17-04-20 20:22:53 DEBUG (Thread-9) [custom_components.xiaomi] PUSH >> <Entity Plug_aaa: on>: {'status': 'on', 'voltage': 3600, 'load_power': '13', 'power_consumed': '4', 'inuse': '1'}

switch on - lamp off (20:24)

some gateway log, maybe triggered by the illumination going down

17-04-20 20:24:16 DEBUG (Thread-17) [custom_components.xiaomi] MCAST (report) << {'data': '{"rgb":0,"illumination":613}', 'cmd': 'report', 'sid': 'bbb', 'short_id': 0, 'model': 'gateway'}
17-04-20 20:24:16 DEBUG (Thread-9) [custom_components.xiaomi] PUSH >> <Entity Illumination_bbb: 595>: {'illumination': 613, 'rgb': 0}
17-04-20 20:24:16 DEBUG (Thread-9) [custom_components.xiaomi] PUSH >> <Entity Gateway Light_bbb: off>: {'illumination': 613, 'rgb': 0}

waiting …

17-04-20 20:29:48 DEBUG (Thread-17) [custom_components.xiaomi] MCAST (heartbeat) << {'data': '{"voltage":3600,"status":"on","inuse":"0","power_consumed":"5","load_power":"0"}', 'cmd': 'heartbeat', 'sid': 'aaa', 'short_id': 16269, 'model': 'plug'}
17-04-20 20:29:48 DEBUG (Thread-8) [custom_components.xiaomi] PUSH >> <Entity Plug_aaa: on>: {'status': 'on', 'voltage': 3600, 'load_power': '0', 'power_consumed': '5', 'inuse': '0'}

switch off

17-04-20 20:31:08 DEBUG (Thread-10) [custom_components.xiaomi] << {'data': '{"voltage":3600,"status":"on","inuse":"1","power_consumed":"5","load_power":"13"}', 'cmd': 'write_ack', 'sid': 'aaa', 'short_id': 16269, 'model': 'plug'}
17-04-20 20:31:08 DEBUG (Thread-17) [custom_components.xiaomi] MCAST (report) << {'data': '{"status":"off"}', 'cmd': 'report', 'sid': 'aaa', 'short_id': 16269, 'model': 'plug'}
17-04-20 20:31:08 DEBUG (Thread-11) [custom_components.xiaomi] PUSH >> <Entity Plug_aaa: off>: {'status': 'off'}
17-04-20 20:31:09 DEBUG (Thread-17) [custom_components.xiaomi] MCAST (report) << {'data': '{"rgb":0,"illumination":619}', 'cmd': 'report', 'sid': 'bbb', 'short_id': 0, 'model': 'gateway'}

I especially like the inuse 0/1 flag. Could be usefull to detect a wash-cycle to have finished :slight_smile:

Hope this is usefull, otherwise let me know what you need and I am happy to log some more

1 Like

Thank you.

I’m a little bit confused by voltage parameter. It’s constant. Maybe it’s your main voltage. What is normal voltage in your region?

No, I think it is the battery voltage. (if the plug has a battery)
We are on 240V in Australia

1 Like

Hi Daniel,

It is possible now to use the gateway as speaker for notifications? (i.e.: welcome greetings)?

TY

Hi Daniel,

Excellent work of you and others to incorporate battery status, ringtone, and illumination support. I found a small typo in your code, but I don’t know how to create a pull request. It’s in homeassistant/components/xiaomi.py.

In the following lines of rigtone is written instead of ringtone.

143 hass.services.async_register(DOMAIN, 'play_rigtone', play_ringtone_service, description=None, schema=None)
144 hass.services.async_register(DOMAIN, 'stop_rigtone', stop_ringtone_service, description=None, schema=None)