Please find below my working code for controlling and pulling data from the Energenie MiHome range of smart plugs / switches.
(For those unfamiliar with github you can use this link to download the latest folder: Download Link)
The templated switches are dynamically updated from the Energenie API, so they reflect the status of the switches even if you turn them off manually at the wall or via other means such as remote control or their website.
The measured wattage is retrieved and used as part of the energy monitoring capabilities of home assistant.
I’ve commented my code to try make it as self-explanatory as possible, but if you have any issues let me know.
Note: I personally use my own 433 MHz gateway for the Energenie wall light switches. However, their smart plugs use a two-way communication protocol, although still on 433 MHz it uses a different chipset and protocol, which I may look into doing a DIY solution in the future.
This would remove the reliance using the Energenie hardware gateway, a Internet connection and Energenie’s support for these products, both future proofing and enabling local control without Internet.
This is only been tested on:
- Mi|Home Smart Plug+ Control and Monitor [MIHO005]
- Mi|Home Smart Plug Monitor [MIHO004]
- Mi|Home Gateway [MIHO001]
However, their API is pretty open and I do not see any reason why my code could not be expanded to cover their entire range of products including the thermostatic radiator valves (TRV’s) and other smart appliances.
energenie_mihome folder and all of its contents into your Home Assistant’s packages folder This is often located inside of your /config folder. If you are running Hass.io , use SAMBA to copy the folder over. If you are running Home Assistant Supervised, the packages folder might be located at /usr/share/hassio/homeassistant. It is possible that your packages folder does not exist. If that is the case, create the folder in the proper location, and then copy the
energenie_mihome folder and all of its contents inside the newly created packages folder.
Add the link to the Package to your
configuration.yaml file, to the “homeassistant:” section. For me, I use:
packages: !include_dir_named packages/
Within my provided packages folder, I have one file per smart switch and a number file for the gateway.
Simply modify as follows:
Identify the device ID you wish to control. The simplest way to do this is to login to the https://mihome4u.co.uk/devices and click “manage” on the device you wish to get the ID of. The web page that opens contains the ID at the last set of numbers in the URL.
Optionally, get the ID of your gateway which is the first set of numbers in the URL.
Within the folder, if you wish rename the file names to match the ID of the device wish to control, however this has no effect on anything.
Either delete or edit the file energenie_mihome_gateway.yaml and add in your username password and the ID of your gateway.
Open one of the switch files:
a. Change !secret MiHome_ID and !secret MiHome_Password to your MiHome login details.
b. Do a find and replace on the existing ID number, edit it to match your device number you wish to monitor and control.
c. Rename the device friendly name to something you prefer, don’t forget spaces and case. E.G. “MiHome Ice Maker Switch” becomes “mihome_ice_maker_switch”.
Finally add the Integration (Riemann sum integral) cumulative energy sensors to the energy dashboard.
That should be everything.
I’ve set the availability topic to monitor the state of the switch and if no voltage is detected after 240 seconds it’s marked as unavailable.
Therefore if you are using switches that are not bidirectional (I.E. only receive commands and do not respond) you need to comment out the “availability_template” line otherwise shall switches will always show as unavailable, or you could replace them with the status of the gateway although this won’t be specific for each switch just your entire environment as a whole.
I don’t trust Energenie to keep their servers online forever, so am designing my own self-hosted server to talk to the Energenie Products
See: GitHub - genestealer/node-red-energenie-ener314rt-home-assistant-mqtt: Node-Red Config for Energenie ener314rt with Home Assistant MQTT Auto Discovery