Energenie MiHome component

Hey guys,
Really loving home assistant. I have only been using it for about two weeks. I also currently have an Energenie MiHome gateway controlling some plug adapters and a light switch over 433mzh rf. Home assistant can control the adapters just fine but im having trouble getting it to control a light switch. As they can be dimmed i think its not a simple on/off rf signal. Would it be possible to build a home assistant component for the energenie mihome range? I have looked into adding the devices manually as energenie have published information about the api. If there is no component could i use home assistant control these devices over the api, maybe MQTT and JSON? Havent looked into this option much yet, still all a bit new to me. Thank you.

These are the devices im using https://energenie4u.co.uk/mihome/the_range/

Its not much help to you with the MiHome gateway, but I use the MiHome products (switches and trvs) using their two way Pi-mote and my own mqtt client.

As you correctly suggest, the on/off switches use a different protocol to the devices that need a little more control and feedback.

I don’t have a MiHome gateway, so I can’t really help with the component, but it should be possible to do.

1 Like

I have been thinking about this for the last week or so, before I installed Home Assistant and to me there a 3 way different ways of controlling the Energenie products depending on which products you have.

Old green button sockets should be able to be controlled with anything that can send 433Mhz signal, including their own Pi-mote.

Newer Mi|Home branded stuff is more complicated and the only way I can see these being controlled by Home Assistant is either to use the API which sends the requests to the Mi|Home servers and actions your request, or to use the ENER314-RT and MQTT which I think is the better solution at the moment but more complicated to implement or maybe not with @gpbenton mqtt client.

I contacted Energenie last week and asked if they had any intention of opening up the Mi|Home gateway hub to allow local API requests or use of the hub locally in some way rather than routing everything via the internet, they said not in the short term but its something they are thinking about.

I am very new to Home Assistant but hope to get it working probably via the Mi|Home API over the Xmas holidays, then move to the 314-RT in the new year. The Wife is already using the Mi|Home Alexa integration for lights and sockets and moving to the 314-RT could mess this up for a while and I could do without the complaining.

I bought a set of these - the “MiHome Gateway” bundle.

There was one deal-breaker, they wouldn’t work without an active internet connection ‘home’.

They ‘phone home’ very frequently, and each & every time a switch is used! :((

Turned off my net connection and they stopped responding to the phone app commands.

The phone app came with the usual eye-watering list of permissions (e.g. camera access, to turn off a plug?)

Mine have been gathering dust since, though if there were a way to talk to them without the constant snitching I’d be interested.

In contrast the Belkin Wemo work fine without a net connection. They do ‘phone home’ a bit, ~2000 a day, but it’s easily and happily silenced at the router or with Pi-Hole etc.

My main reason for using home assistant and the energenie gateway is for Alexa control. I had issues setting up the emulated hue component so i bought the gateway as it works with alexa as standard and hopefully reliable. I have now got haaska working and alexa can see all my home assistant devices so very happy and would prefer to have everything controlled from one main platform. Im still waiting for my echo so i havent used Alexa yet, have you found it reliable with the Mi|Home gateway?

I’m not a fan of having it rely on the internet to operate but for £55 with a gateway and 3 switches I thought it was worth a shot. You could still setup the adapters with home assistant using a 433mhz transmitter, better than them gathering dust.

If there is anyway I can use them without the gateway I will give it a go, I would much rather use home assistant. Thank you so much for the info. I’ll hopefully have time to give it a go over the next few weeks.

I’ve been using the Mi|Home hub with 3 Echo Dots for about 3 weeks with 2 old style plugs, an energenie 4 gang switchable extension and so far 2 light switches. The Alexa/Echo integration works perfectly using the energenie skill.

I would prefer when I have Home Assistant fully configured to use it rather than the Energenie Skill with Alexa.

“Alexa Turn off Xmas” and the Xmas lights go off. Always realise when we are in bed so saves a trip downstairs or having to use the Mi|Home app and that annoying music each time it starts.

A side note to this I’ve had a couple of problems with the Energenie light switches, first a switch started to get very hot once connected it was working OK but started to smell. I disconnected it and checked with a Part P registered friend who confirmed wiring was fine. Returning it to Amazon and let Energenie know. Replacement works fine.
The other problem I currently have, is when our second switch turns off the bedroom LED light, it flashes twice before it goes off completely. Just changed it to an LED bulb after a regular bulb blew 2 days after installing the new switch. Maybe it blew because of this problem, never noticed it flashing thought.

Thank you for the info. I’ll keep a close eye on the switches. Have you been able to dim the lights using Alexa?

I’m considering buying an Energenie MiHome gateway and would like to the be integrated into Home Assistant. A quick google search shows there’s an API available - https://mihome4u.co.uk/docs/api-documentation

I guess the problem is that the switches only have one-way feedback so it would be very easy for the controller and/or Home Assistant to get out of sync.

I’d like to get stated on a component for Home Assistant once I buy the gateway and a few switches - but they are currently out of stock. I’m new to Home Assistant and haven’t programmed in python before, but I’d be up for the challenge if I could get the equipment + time.

I haven’t had as much time over the Xmas break to work on this as I had hoped but I have managed to get Home Assistant working with the online API.

So far the only MiHome devices I’ve had chance to add in are a 4 gang extension, which I used Command line switch component to add each of the 4 sockets and 1 that would turn off all 4 at once. The last bit I got working late last night was to pull the power usage from an Adapter Plus. This adapter and the other new (blue writing) MiHome devices do report their status, so should not go out of sync but they are on back order.

The way I got it working was to use the Command Line Switch and use Curl to interact with the API.

For pulling the current usage I used the Command Line Sensor rather than the switch.

Once I’m back home I will try to write the exact config I’ve used. It can be annoying that the devices that aren’t 2 way (light switches, extensions, old green adapters) go out of sync.

This is one reason I went with the Belkin Wemo plugs over the Energenie ones.

Wemo plugs are generally more expensive. The MIHO002 devices from Energenie are cheaper for 3 than for 1 of the Wemo, when they are back in stock and should report status so they don’t go out of sync.

I wish there was a version of the light switches and wall sockets that were 2 way though, don’t think Belkin do those.

Yeah, the Belkin’s don’t do it but they’re so reliable it hasn’t mattered to me yet.

When I used the Energenies they just didn’t behave consistently. After a few hours, they would go off and wouldn’t reappear until I restarted the whole Hass + devices setup.

I got frustrated and went with the Wemos, no regrets even with the higher price.

I have been using mine for a year and haven’t seen any behaviour like this. They have occasionally (about once or twice a month) failed to turn on, but I’m sure that is just radio signal interference. Have you complained to Energenie?

Cheers, that does sound like I was unlucky. I gave them two days, and they just kept doing it.

Combined with their need to be internet connected (a deal-breaker for me), I just stopped using them.

The Wemos work without the net, so my automations aren’t interrupted or broken by periodic internet disconnects.

As I said earlier in the thread, I use a Pimote and my own software, just to avoid this.

Ok, so I’ve just done a little bit more research and it appears there’s no python library available for accessing the internet API. The one that’s on github is for if you have the Pi boards.

As a first step forward we need to get a python library that’s capable of retrieving/modifying the MiHome state using the public API.

I had some problems with my hub not working but think it was all down to a faulty power supply and its now up and running. Would really appreciate any examples of how to use the api. I have had a go and im able to turn on devices using the command line on my pi but havent had much luck with the home assistant command line component. Thanks in advance.

Apologies for not getting back sooner, had some bug for over a week.

Anyway in the short term the easiest way I got things to work was by adding a command line switches and sensors. A more complicated example would be to add the following to your configuration.yaml.

switch:
  platform: command_line
  switches:
    4_gang_extension:
      command_on: 'curl -u "<YOURUSERNAME>:<YOURPASSWORD>" -X POST -H "Content-Type: application/json" -d "{\"id\":54321}" https://mihome4u.co.uk/api/v1/subdevices/power_on'
      command_off: 'curl -u "<YOURUSERNAME>:<YOURPASSWORD>" -X POST -H "Content-Type: application/json" -d "{\"id\":54321}" https://mihome4u.co.uk/api/v1/subdevices/power_off'
      friendly_name: TV Extension
    4_gang_extension_a:
      command_on: 'curl -u "<YOURUSERNAME>:<YOURPASSWORD>" -X POST -H "Content-Type: application/json" -d "{\"id\":54321,\"socket\":0}" https://mihome4u.co.uk/api/v1/subdevices/power_on'
      command_off: 'curl -u "<YOURUSERNAME>:<YOURPASSWORD>" -X POST -H "Content-Type: application/json" -d "{\"id\":54321,\"socket\":0}" https://mihome4u.co.uk/api/v1/subdevices/power_off'
      friendly_name: Living Room Lamp
    4_gang_extension_b:
      command_on: 'curl -u "<YOURUSERNAME>:<YOURPASSWORD>" -X POST -H "Content-Type: application/json" -d "{\"id\":54321,\"socket\":1}" https://mihome4u.co.uk/api/v1/subdevices/power_on'
      command_off: 'curl -u "<YOURUSERNAME>:<YOURPASSWORD>" -X POST -H "Content-Type: application/json" -d "{\"id\":54321,\"socket\":1}" https://mihome4u.co.uk/api/v1/subdevices/power_off'
      friendly_name: TV
    4_gang_extension_c:
      command_on: 'curl -u "<YOURUSERNAME>:<YOURPASSWORD>" -X POST -H "Content-Type: application/json" -d "{\"id\":54321,\"socket\":2}" https://mihome4u.co.uk/api/v1/subdevices/power_on'
      command_off: 'curl -u "<YOURUSERNAME>:<YOURPASSWORD>" -X POST -H "Content-Type: application/json" -d "{\"id\":54321,\"socket\":2}" https://mihome4u.co.uk/api/v1/subdevices/power_off'
      friendly_name: FireTV Stick
    4_gang_extension_d:
      command_on: 'curl -u "<YOURUSERNAME>:<YOURPASSWORD>" -X POST -H "Content-Type: application/json" -d "{\"id\":54321,\"socket\":3}" https://mihome4u.co.uk/api/v1/subdevices/power_on'
      command_off: 'curl -u "<YOURUSERNAME>:<YOURPASSWORD>" -X POST -H "Content-Type: application/json" -d "{\"id\":54321,\"socket\":3}" https://mihome4u.co.uk/api/v1/subdevices/power_off'
      friendly_name: Audio Splitter

You just need to change <YOURUSERNAME> and <YOURPASSWORD> to whatever you use to login to the mihome4u website. You also need to change the id, in my example 54321 to your device ID. The easiest way to get this is to login to the mihome4u website and click on the manage link for the device you want to use in Home Assistant. The look at the url and you want the number just before “/edit”, so in my example my url would be:

https://mihome4u.co.uk/devices/4409/subdevices/54321/edit

This above example is for a 4 gang extension so what is does is send on and off states for each socket and one to turn all sockets on/off.

If you are only controlling a single socket it would be something like this:

switch:
  platform: command_line
  switches:
    dining_lamp:
      command_on: 'curl -u "<YOURUSERNAME>:<YOURPASSWORD>" -X POST -H "Content-Type: application/json" -d "{\"id\":54321}" https://mihome4u.co.uk/api/v1/subdevices/power_on'
      command_off: 'curl -u "<YOURUSERNAME>:<YOURPASSWORD>" -X POST -H "Content-Type: application/json" -d "{\"id\":54321}" https://mihome4u.co.uk/api/v1/subdevices/power_off'
      friendly_name: Dining Lamp

To pull current usage data from a mi|Home Adapter Plus socket I do it like this:

sensor:
  platform: command_line
  command: 'curl -u "<YOURUSERNAME>:<YOURPASSWORD>" -X POST -H "Content-Type: application/json" -d "{\"id\":12345}" https://mihome4u.co.uk/api/v1/subdevices/show'
  name: Washer
  unit_of_measurement: w
  value_template: '{{ value_json.data.last_data_instant }}'

Hope all that makes sense, once you’ve done a couple it’s actually quite easy and works well. Ultimately it would be better to have a proper Python component like @curtisjk mentioned but this is easy for now.

1 Like