After doing some research, and especially reading the Javascript code at https://github.com/plasticrake/tplink-smarthome-api, I’ve figured out how this API works.
Currently Home Assistant is just sending the set_relay_state
command:
{"system":{"set_relay_state":{"state":0}}}
In order to support multiple outlets, a context must be added:
{"system":{"set_relay_state":{"state":0}},"context":{"child_ids":["000000000000000000000000"]}}
The child_id can be found by looking at the results of the get_sysinfo
command. Multiple child_ids can be sent, so for the HS300 with 6 outlets you could turn on up to all 6 at once.
Now, getting from understanding the API to integrating it into HA, that’s another story for another night (and perhaps a better Python dev than I am).
Here’s an example of how to use tplink-smarthome-api to send this command. This could be used inside a script, for example, which is what I’ll probably do for now.
$ tplink-smarthome-api setPowerState --childId '[child_id]' '[host_ip]' 1