Page 3 of 3

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

PostPosted: Wed Jan 16, 2019 7:40 pm
by ckeyes888
Maybe this helps?
https://github.com/codetheweb/tuyapi

Thanks,

Carl

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

PostPosted: Thu Jan 17, 2019 10:20 am
by jay (support)
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.

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

PostPosted: Thu Jan 17, 2019 10:50 am
by FlyingDiver
I think I have some TP-Link hardware somewhere. Let me dig it out.


Sent from my iPhone using Tapatalk

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

PostPosted: Thu Jan 17, 2019 12:07 pm
by jay (support)
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.

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

PostPosted: Thu Jan 17, 2019 12:45 pm
by FlyingDiver
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?

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

PostPosted: Thu Jan 17, 2019 1:47 pm
by jay (support)
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).

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

PostPosted: Thu Jan 17, 2019 2:21 pm
by ckeyes888
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

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

PostPosted: Thu Jan 17, 2019 4:54 pm
by jtburgess
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.

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

PostPosted: Sat Jan 19, 2019 7:00 pm
by Ramias
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

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

PostPosted: Sat Jan 19, 2019 7:04 pm
by jtburgess
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...

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

PostPosted: Mon Jan 21, 2019 11:57 am
by Ramias
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.

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

PostPosted: Mon Jan 21, 2019 3:18 pm
by jtburgess
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.

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

PostPosted: Mon Jan 21, 2019 10:39 pm
by Ramias
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.

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

PostPosted: Thu Jan 24, 2019 8:45 pm
by Ramias
(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 :(.

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

PostPosted: Fri Apr 19, 2019 2:14 pm
by madscientist
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