Energenie MiHome API help

I’m looking for some guidance on how to post the following request through openhab so that I can then connect it to habpanel.

I have all the specifics for the code just need to know how to run it.

Can anyone help?

curl -u "<email address>:<password>" -X POST -H "Content-Type: application/json" -d "{\"id\":<device_group_id_number>}" https://mihome4u.co.uk/api/v1/device_groups/power_on

Hello @Nathan_Wilcox, we have implemented a binding for Energenie Mi|Home and created a Pull Request in the openhab2-addons repository. - https://github.com/openhab/openhab2-addons/pull/2054

Would you like to try it out ?

1 Like

@svilenvul

That’s great news! I’d love to give it a go, I have two openhab systems that I can run this with, one that is an initial install with nothing on, I use this to test whenever I have something new to try out.

I also have one running my actual system that controls various things around the home which is where I want this the most.

Is this all ready to go as it is now? If so can you point me in the direction of installing the binding so I can give it a go.

Thanks

Great !

The binding now supports the following devices:

  • MIHO001 Home Gateway;
  • MIHO006 House Monitor;
  • MIHO032 Motion Sensor;
  • MIHO033 Open Sensor.

It is still not merged in the OH2 addons master, so I can send you the jar file with the binding. I have tried to upload it here, but it is not allowed extension. You can add this jar file in the addons folder.

@svilenvul

I will pm you my email address for the jar to test. When you say it supports the devices can you tell me what exactly it supports with regards to the MIHO001 Home Gateway.

Also any rough idea as to how long until you can look at the MIHO024 1 Gang Light Switch (This is the nickel version that I have installed already but I am led to believe the coding is the same between all the versions and that the only difference being the faceplate material/colour)

I also have MIHO021 Double Wall Socket installed (again I believe coding is the same as the plain original white version)

Cheers
Nathan

@Nathan_Wilcox

I have sent you the jar file.

Also any rough idea as to how long until you can look at the MIHO024 1 Gang Light Switch

I also have MIHO021 Double Wall Socket installed

We have bought a starter kit that included the devices listed above (MIHO001, MIHO006, MIHO032 and MIHO033). The API calls for the different devices are the same and the JSON messages look almost identically, but until we have example messages from the devices that you have mentioned (MIHO024 and MIHO021), we can’t add a support for them.

In your original post, I see you had some problems sending requests to the MiHome servers. Have you solved them ? I can help you with the requests and the responses I think will be enough to add the devices (MIHO024 and MIHO021) to the supported one by the binding :slight_smile: .

@svilenvul

Hi,

I’ve finally got around to installing the binding. A first issue I have come across is that my Gateway Code actually has a number appear within it and does not conform to the 10 Capital Letter requirement, resulting in:

Status: OFFLINE - CONFIGURATION_ERROR Invalid gateway code. 10 capital letters expected

from Paper UI.

The number is the 5th character in my gateway code, as symbolised below:

GATEWAY CODE: LLLLNLLLLL

L= Letter N=Number

Thanks! I will fix it and I will send you the updated version.

Great news!

My first post was all about running the curl command from openhab in order to try and control devices. I had come across a link where it gave one example as shown in the first post which is used to turn a group on or off.

The command works perfectly, but I could never issue a command to turn a single socket on or off.

I’d be more than willing to run some things on my end in order to test responses so you could add them to your Binding. The only issue being I’m a complete newbie to programming so would need a rather descriptive way of how to run such things.

@Nathan_Wilcox,
Hi,
For the last few days we have a problem with our gateway. It all started with the upgrade from 1.2.0 to 1.2.1 and now every try to register the gateway leads to error - “Auth code was not recognized. Please ensure that the device is connected to the network.” I was wandering if you have such problem or something went wrong with our gateway.

@m-memova

Hi,
My gateway hasn’t updated yet, it is still running on version 1.2.0 and has remained registered and fully working both with their independent app and with the openhab Binding you have been working on.

Hope this helps
Nathan

@svilenvul @m-memova

Hi Both,

Are there any advances on the Binding? I’ve not seen any activity on the GitHub changes for a while and just wanted to check how things were getting on.

I’ve had my energy monitor connected now for roughly 2 weeks and it seems to work perfectly with the system, great response times and work very well inside HABpanel.

Also, how have you found the motion sensors to be? Are they relatively accurate and how do you find the pairing process before I purchase any?

Hi,

Great to hear that the energy monitor is working good !

And about your questions:

Are there any advances on the Binding?

We are waiting for the PR to be reviewed and merged in the openhab2-addons repository. If you like, you could leave some comments in the GitHub Pull Request as well :).

Also, how have you found the motion sensors to be? Are they relatively accurate and how do you find the pairing process before I purchase any?

We haven’t experienced any issues with them (the sensitivity can be configured by pressing a button) and the paring process doesn’t differ from the process for the other devices.

@svilenvul @m-memova

Hi Both,

Just wondering if you could quickly teach me how I can go about parsing a select piece of information from the response below. The piece I’m after is the section "power_state":0, I want to use this as a way of checking the state of the light Switch to see if it has been turned on.

Hopefully this will help with your future endeavours when including it into the binding.

[16:51:42] openhabian@openHABianPi:~$ curl -u "USERNAME:PASSWORD" -X POST -H "
Content-Type: application/json" -d "{\"id\":42349}" https://mihome4u.co.uk/api/v1/subdevices/show
{"status":"success","time":0.03,"flags":{},"data":{"device_type":"light","id":42349,"label":"Ceiling
 Light","device_id":5164,"power_state":0,"startup_mode":0,"aggregated_hourly_at":"2017-01-14T12:05:5
9.000Z","aggregated_daily_at":"2017-01-14T12:05:59.000Z","remote_id":1,"timer1_enabled":null,"timer1
_on_time":null,"timer1_off_time":null,"timer1_monday":null,"timer1_tuesday":null,"timer1_wednesday":
null,"timer1_thursday":null,"timer1_friday":null,"timer1_saturday":null,"timer1_sunday":null,"timer2
_enabled":null,"timer2_on_time":null,"timer2_off_time":null,"timer2_monday":null,"timer2_tuesday":nu
ll,"timer2_wednesday":null,"timer2_thursday":null,"timer2_friday":null,"timer2_saturday":null,"timer
2_sunday":null,"timer3_enabled":null,"timer3_on_time":null,"timer3_off_time":null,"timer3_monday":nu
ll,"timer3_tuesday":null,"timer3_wednesday":null,"timer3_thursday":null,"timer3_friday":null,"timer3
_saturday":null,"timer3_sunday":null,"extra_data":null,"target_temperature":null,"voltage":null,"vol
tage_reported_at":null,"frequency":null,"real_power":null,"reactive_power":null,"created_at":"2017-0
1-14T12:05:59.000Z","updated_at":"2017-01-14T12:15:07.000Z","nest_thermostat_id":null,"rate_limit_to
kens_used":10,"rate_limit_tokens_updated_at":"2017-04-14T18:59:23.000Z","device_groups":[{"id":38337
,"name":"Nathan \u0026 Jess Room","user_id":30732}],"today_wh":0,"today_wh_range":"low","last_data_i
nstant":0,"unknown_state?":true,"unknown_state":true}}

Thank
Nathan

@Nathan_Wilcox,
Hi,
Basically there are several steps which you need to follow in order to extract almost any information you want.

  1. send the request (the response you get is a JsonObject) :
    JsonObject showResponse = apiManager.showSubdevice(42349);

  2. get the data object from the response (again, it’s a JsonObject):
    JsonObject showResponseData = showResponse .get(JSONResponseConstants.DATA_KEY).getAsJsonObject();

  3. get the property you need as JsonElement - once you have the data object, you can use the get(String memberName) method to extract what you need.
    JsonElement stateElement = showResponseData.get("power_state");

  4. Parse the JsonElement to its corresponding type (String, int, double…)
    int powerState = stateElement.getAsInt();

Of course, you can combine the last two steps :
int powerState = showResponseData.get("power_state").getAsInt();

Keep in mind, that it is a little more complicated if you want to extract the errors from the data, for example. In that case there are some objects into arrays into objects and so on :slight_smile: You can see it in one of the last commits to PR.

I hope I helped.

Regards,
Mihaela

@Nathan_Wilcox,
Hi,
we’ve made some changes to the binding. Here’s the PR for the latest version:


You can try it if you want.
If you find anything disturbing feel free to share with us.

Regards,
Mihaela

How do i intalls this, and where is it available to download from?

How do you install the socket adaptors?

Mihaela,

Forgive my newbie-ness. How do I get to install your module for the Energienie MiHome. Just got one of these with the door sensor and want to hook it into my OpenHab2 setup.

Cheers,

Martin