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.