SmartThings Community

[RELEASE] MiHome (Connect) V2.0.1 [Energenie] (not Xiaomi MiHome)


(Mark C) #247

just needed to know what the double light was called. updated my fork

(Nav) #248


Could someone confirm if I should be able to get the house energy monitor to work?

I am using the smartapp and have tried the MiHome monitor DH.

All devices below just say: can’t add:

(Mark C) #249

Are you logged in? Do you have any other devices?

(Nav) #250

Yes - it is logged in and authenticated. This one is my first Energenie device.

(steve holt) #251

Hi Mark just for future reference were would i insert that code, i am willing to learn what i can and appreciate all help provided. I have a MiHome Click being delivered this week so something else to have a look at.


(Mark C) #252

I’d try a switch 1st. There isnt a DH for just a monitor. 1 could b built

(Mark C) #253

Have a look in the smartapp for the section i sent you. If you compare the differences you will see a added a log.debug line which effectively prints the data returned back from mihome.
If you Google mihome api it will explain the response and if you look around you will see what paths you need to send messages to do actions.

If you have any specific questions about what bits do in the code just ask. To be honest the hardest bit is understanding ST documents as the groovy language is quite slack and there doc’s arnt consistent

(Nav) #254

Thanks for your help Mark.

Could you be specific on which DH to use…I can’t see the one you mean that I should try. (I have tried all the above in post 1).

Also - there is a screenshot right at the top of this thread (3rd one down on the right): X: MiHome Energy M…

Is that just for illustration purposes…to show what it could look like?

(Mark C) #255

looks like its set up to do it
just creat a device handle using this code and pubilish it, then you should be able to add a monitor in the smart app (2nd from bottom on the add devices page)

(Nav) #256

Thanks again Mark,

Yeah - that is the one I tried and have tried again (removed both Smartapp and DH) and re-done.
(I have done this before - so am familiar with the process for other DHs).

When I go to the smartapp and authenticate - and then the choose devices - they all show as per my previous screenshot…

(0 found) - you can’t currently add this.

My username/password for authenticating are just fine - as I can log in on the mihome website with those.

Do I need to enable anything else…in the smartapp…elsewhere to allow access?

(Mark C) #257

do any device show up?

(Nav) #258

Nope - they all show as:

(0 found) - you can’t currently add this.

(Mark C) #259

you need to enusre this log.debug line is in place (around line 593)
def devicesList() {
logErrors([]) {
def resp = apiGET(“subdevices/list”)
log.debug "device list all ‘$’"

then see what comes up on the ide live logging

(Nav) #260

OK - getting closer…

This is what I get:

861602ef-25cc-42e5-b3e7-c28c17a58cd9 11:44:00 AM: debug device list all ‘[time:0.01, flags:[:], status:success, data:[[timer3_on_time:null, parent_device_last_seen_at:2018-08-08T10:43:04.000Z, socket4_label:null, timer2_friday:null, firmware_version:null, timer2_off_time:null, startup_mode:0, timer2_wednesday:null, real_power:831.0, timer1_sunday:null, timer1_enabled:null, timer1_saturday:null, timer3_monday:null, device_groups:[[id:136137, name:My Devices, user_id:122311]], extra_data:null, timer3_sunday:null, timer2_thursday:null, label:HEM, unknown_state:false, aggregated_daily_at:2018-08-07T17:52:36.000Z, rate_limit_tokens_updated_at:null, timer3_wednesday:null, target_temperature:null, updated_at:2018-08-08T10:10:19.000Z, voltage:4.45703, timer1_tuesday:null, timer3_tuesday:null, timer2_monday:null, aggregated_hourly_at:2018-08-08T10:09:59.000Z, timer3_enabled:null, energenie_thermostat_id:null, reactive_power:null, device_type:house, socket2_label:null, timer1_thursday:null, timer3_friday:null, frequency:null, id:137068, timer1_off_time:null, timer3_saturday:null, today_wh:17394, timer1_monday:null, voltage_reported_at:2018-08-08T10:43:53.000Z, side:null, timer3_off_time:null, unknown_state?:false, timer2_enabled:null, created_at:2018-07-14T17:52:36.000Z, timer2_tuesday:null, nest_thermostat_id:null, socket1_label:null, rate_limit_tokens_used:null, timer2_on_time:null, timer3_thursday:null, container_number:null, power_state:1, timer1_on_time:null, power_state_4:null, last_data_instant:814, socket3_label:null, device_id:18404, power_state_1:null, timer2_saturday:null, power_state_2:null, power_state_3:null, timer1_friday:null, timer2_sunday:null, today_wh_range:high, remote_id:1, timer1_wednesday:null, hardware_version:null]]]’
cbfb26ca-81e2-43da-b2db-fe9e5e268f2d 11:43:53 AM: trace getPhrases(), state.welcomeIssue = null

I can see ‘HEM’ - which is the label I have given the device.
I can also see a few figures…for example: 814…which is the current Watt usage. I can also see the Voltage figure in the above debug.

(Mark C) #261

do you get any debug messgaes starting
“Identified: device …”

(Nav) #262


Everything I pasted above was the complete debug…

(Mark C) #263

im confused because it should flow into the rest of the code

def updateDevices() {
log.debug “updateDevices”
if (!state.devices) {
state.devices = [:]
def devices = devicesList() this calls the list data
log.debug “updateDevices post device list”
state.miETRVDevices = [:]
state.miLightDevices = [:]
state.miAdapterDevices = [:]
state.miAdapterPlusDevices = [:]
state.mi4GangExtensionDevices = [:]
state.miSocketDevices = [:]
state.miMotionSensors = [:]
state.miMonitorDevices = [:]

def selectors = []
devices.each { device ->
    if (device.device_type == 'etrv') {
		**some stuff**
    else if (device.device_type == 'monitor' || device.device_type == 'home') { //this is the identify device
    	log.debug "Identified: device ${}: ${device.device_type}: ${device.label}"
        def value = "${device.label} Monitor"
		def key =
		state.miMonitorDevices["${key}"] = value
        //Update names of devices with MiHome
 		def childDevice = getChildDevice("${}")
 		if (childDevice) {
 			//Update name of device if different.
 			if( != device.label + " Monitor") { = device.label + " Monitor"
				log.debug "Device's name has changed."

(Dom Harvey) #264

I had some fun with the Energy monitor a while back. I had to change the device type from ‘home’ to ‘house’ in the connect app i.e.

else if (device.device_type == ‘monitor’ || device.device_type == ‘home’)
else if (device.device_type == ‘monitor’ || device.device_type == ‘house’)

I thought my system was just a special case so I stuck with editing the app each time it was updated.
I suppose it may be better to keep the ‘home’ and just add ‘house’ to the if.

(Mark C) #265

Yep your right. If you look though the debug details its house not home insert || device.device_type == ‘house’ it will.cover all eventualities

|| means or

(Nav) #266

Perfect! That has allowed me to add it now.

Does it take a while to work? I updated the smartapp about 20 minutes ago and added it in…but the power is showing as 0 Watts.