TP-Link Plugin - How To (v0.1.2)

Posted on
Wed Jan 16, 2019 7:40 pm
ckeyes888 offline
Posts: 2117
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: TP-Link Plugin - How To (v0.1.2)

Maybe this helps?
https://github.com/codetheweb/tuyapi

Thanks,

Carl

Posted on
Thu Jan 17, 2019 10:20 am
jay (support) offline
Site Admin
User avatar
Posts: 15797
Joined: Mar 19, 2008
Location: Austin, Texas

Re: TP-Link Plugin - How To (v0.1.2)

There is a python port of that API - but it's definitely not the same API as the TP-Link API, so it won't work with this plugin.

Maybe you could bribe one of the 3rd party developers to take a shot at a plugin with some hardware, though it appears to be a reverse-engineered protocol so can be easily broken by the vendor at any time.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Jan 17, 2019 10:50 am
FlyingDiver offline
Posts: 3544
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: TP-Link Plugin - How To (v0.1.2)

I think I have some TP-Link hardware somewhere. Let me dig it out.


Sent from my iPhone using Tapatalk

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Jan 17, 2019 12:07 pm
jay (support) offline
Site Admin
User avatar
Posts: 15797
Joined: Mar 19, 2008
Location: Austin, Texas

Re: TP-Link Plugin - How To (v0.1.2)

FlyingDiver wrote:
I think I have some TP-Link hardware somewhere. Let me dig it out.


TP-Link hardware works fine with this plugin (I have a TP-Link wall wart). It's just this other hardware that is the question.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Jan 17, 2019 12:45 pm
FlyingDiver offline
Posts: 3544
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: TP-Link Plugin - How To (v0.1.2)

jay (support) wrote:
FlyingDiver wrote:
I think I have some TP-Link hardware somewhere. Let me dig it out.


TP-Link hardware works fine with this plugin (I have a TP-Link wall wart). It's just this other hardware that is the question.


Oh. Hmm. Maybe you could split the posts about the other hardware to a different thread?

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Jan 17, 2019 1:47 pm
jay (support) offline
Site Admin
User avatar
Posts: 15797
Joined: Mar 19, 2008
Location: Austin, Texas

Re: TP-Link Plugin - How To (v0.1.2)

It is somewhat confusing - @ckeyes888 was confused about what hardware worked with this plugin, so it took a couple of back-and-forths to get to the bottom of that.

He should create a new topic in the Hardware Support Inquiries and Requests forum asking if anyone would be interested in building a plugin for his hardware (as I recommended a couple of posts up).

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Jan 17, 2019 2:21 pm
ckeyes888 offline
Posts: 2117
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: TP-Link Plugin - How To (v0.1.2)

Thanks Jay. The Tuya API is definitely not compatible with TP-Link.
I’ll put in a feature request for a plugin as the Techin, Gosund and others are far cheaper than the TP-Link
and as per my testing work equally well.
The down side of course is their reliance on the cloud.

Carl

Posted on
Thu Jan 17, 2019 4:54 pm
jtburgess offline
User avatar
Posts: 43
Joined: Jan 17, 2018
Location: NJ

Re: TP-Link Plugin - How To (v0.1.2)

I agree, it's very confusing. Multiple vendors with very similar wall-wart WiFi controlled devices, each with their own (iOS / android) App, and thus evidently their own protocol. There is no standard!

I found a TP-Link python package on GitHub, which I used as the basis for this plugin.
Someone will have to do something similar for each of the others.
I'd suggest using TP-Link as a prototype, but if the other API is different (or not in python!) all bets are off.

And obviously, you must have a device from each vendor to test each plugin.

Good luck.

Posted on
Sat Jan 19, 2019 7:00 pm
Ramias offline
Posts: 146
Joined: Nov 24, 2015

Re: TP-Link Plugin - How To (v0.1.2)

TP Link has a Kasa powerstrip that says you can Independantly control each of six outlets.

Will this plugin support this?

I just bought one and will test Monday.
https://www.amazon.com/Smart-Power-Stri ... B07G95FFN3

Posted on
Sat Jan 19, 2019 7:04 pm
jtburgess offline
User avatar
Posts: 43
Joined: Jan 17, 2018
Location: NJ

Re: TP-Link Plugin - How To (v0.1.2)

If it uses the Kasa app, then it should work.
The plugin is really simple, though and doesn’t “know” about multi-port devices.

I’ll work with you as best I can...

Posted on
Mon Jan 21, 2019 11:57 am
Ramias offline
Posts: 146
Joined: Nov 24, 2015

Re: TP-Link Plugin - How To (v0.1.2)

I ended up getting the HS300 Strip and the HS107 "Dual" model since these fit my use case for counter ceiling and counter top lighting control perfectly.

The Plugin does turn both on and off "globally" but of course not each independent outlet on the strip or the dual plug.

I found this on GitHub:
https://github.com/newAM/pyHS100

and the SmartStrip file here:
https://github.com/newAM/pyHS100/blob/d ... rtstrip.py

Looks like they've figured out the code for the HS300 strip. I suspect the dual will work the same way. Probably need to go in as different device types in Indigo (instead of SmartPlug). Also, suspect for example the Strip with 6 outlets will need to be created as 6 separate Indigo Devices manually and specify the name of the strip and the port number. Unless others have thoughts on auto-detecting or automatically creating the "child" devices?

I've tweaked some plugins before and will give this a shot in a few days once I knock out some stuff for work, unless somebody else wants to jump in.

Posted on
Mon Jan 21, 2019 3:18 pm
jtburgess offline
User avatar
Posts: 43
Joined: Jan 17, 2018
Location: NJ

Re: TP-Link Plugin - How To (v0.1.2)

It’s possible for one plugin to have different device types. That’s the way to go.
Keep me posted on your progress, and feel free to ask questions.

Posted on
Mon Jan 21, 2019 10:39 pm
Ramias offline
Posts: 146
Joined: Nov 24, 2015

Re: TP-Link Plugin - How To (v0.1.2)

I have this working now with the 6 port power strip and the dual power adapter so the HS300 and HS107. But my code is a total hack and has zero error checking. But at least it works.

I found this online: https://github.com/p-doyle/Python-KasaSmartPowerStrip

For the multi-port models the command string that needs to be sent is:
Code: Select all
{"context":{"child_ids":["CHILD_ID"]},"system":{"set_relay_state":{"state":1}}}


The CHILD_ID is a long string of the device id with a two digit identifier appended to it -- 00, 01, up to 05 for the 6 port power strip.

to get the device ID string I ran the Python-KasaSmartPowerStrip.py file stand-alone with this syntax:
Code: Select all
from KasaSmartPowerStrip import SmartPowerStrip

power_strip = SmartPowerStrip('192.168.0.117')

# get general system info
print(power_strip.get_system_info())


and one of the values returned was the needed device_id.

I also had to modify the code to pass the child_ID value and build the right version of the string. So for now, I basically have a second, stand-alone, separate-name version of this plugin for just power strips, with no error detection and an ugly-ish install process, etc.

Looks like it would be possible to auto-discover and auto-create these and name them with the same name from the Kasa app, since that's all stored in the deviceInfo dump. But that's a bit beyond my skill at the moment.

Happy to share what I have if anybody needs it. Not a GitHub power user and the version of the plugin I have now won't work with normal devices since the command strings are different.

Also, if one of the switches is turned on outside of Indigo, Indigo doesn't know about it. I'll just remove the Kasa Alexa skill and expose these to Alexa via Indigo but adding status polling every 30 seconds (or configurable) may be useful. I may try to get to it but that's going to be further down the road.

Posted on
Thu Jan 24, 2019 8:45 pm
Ramias offline
Posts: 146
Joined: Nov 24, 2015

Re: TP-Link Plugin - How To (v0.1.2)

(Not a Python Expert here, but I can hack a bit)

Is it possible to put a variable in a Python dictionary string?

For example, for the single plug, the commands dictionary is:

Code: Select all
commands = {'info'     : '{"system":{"get_sysinfo":{}}}',
         'on'       : '{"system":{"set_relay_state":{"state":1}}}',
         'off'      : '{"system":{"set_relay_state":{"state":0}}}',
         'cloudinfo': '{"cnCloud":{"get_info":{}}}',
         'wlanscan' : '{"netif":{"get_scaninfo":{"refresh":0}}}',
         'time'     : '{"time":{"get_time":{}}}',
         'schedule' : '{"schedule":{"get_rules":{}}}',
         'countdown': '{"count_down":{"get_rules":{}}}',
         'antitheft': '{"anti_theft":{"get_rules":{}}}',
         'reboot'   : '{"system":{"reboot":{"delay":1}}}',
         'reset'    : '{"system":{"reset":{"delay":1}}}',
         'energy'   : '{"emeter":{"get_realtime":{}}}'


Would it be possible to insert a variable in this string? So the "on" line would look like this in the dictionary (using % as the variable placeholder):
'on' : '{%"system":{"set_relay_state":{"state":1}}}',

And for the single plug, you could just send "" for %, but for the multi-port, send: "context":{"child_ids":["CHILD_ID"]},

Which would generate the correct command for either plug type.

Or would it be better to just have separate dictionaries for each one?

I'm going to try this again, because apparently I made my changes to the 0.12 version of the plugin and it doesn't status update :(.

Posted on
Fri Apr 19, 2019 2:14 pm
madscientist offline
Posts: 79
Joined: Jan 05, 2007
Location: Ontario, Canada

Re: TP-Link Plugin - How To (v0.1.2)

For those of you asking about local Tuya control via Indigo, see here for a (somewhat complicated) workaround solution: https://forums.indigodomo.com/viewtopic.php?f=132&t=19981&p=176255#p176255

Who is online

Users browsing this forum: No registered users and 0 guests