Sunday, 31 July 2016

Automating with the Energenie MiHome controller: The API

It's all well and good doing cool things with MiHome and IFTTT, but what if you really want to get geeky... well it's time to try out the API.

While I must praise Energenie for having a documented API, I initially found the lack of real world examples confusing. Through trial and error, I eventually worked out that you need the following details to start using the API.

List the device groups:

curl -u "a<email address>:<password>" https://mihome4u.co.uk/api/v1/device_groups/list

Up will come a long stream, somewhere in there will be the device group ID number you want.. but rather than struggle to work out where it is, I suggest you log on to the website, find the group you want to action and hover over the Edit link. In the URL you will see the device group id number.



From there it's a simple case of using the credentials you use to log on to https://mihome4u.co.uk, and you can use CURL to action your request.

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

Simple!