TP-Link WiFi Switches

Forum rules

Questions about hardware that can be controlled by Indigo (but not through the interfaces and plugins listed). If Indigo doesn't support some bit of hardware you're interested in, and you don't find a 3rd Party Plugin for it, add it to this forum. Be sure to include links to as much information as you can find about it.

Note: adding it here does not mean we're going to add it - in fact it's possible one of our 3rd party developers may decide to write a plugin for it. We add hardware/features based on a lot of different factors beyond just having a request for it.

Posted on
Mon Nov 07, 2016 10:08 pm
ChopOMatic offline
Posts: 110
Joined: Sep 12, 2014

TP-Link WiFi Switches

I've just put a couple TP-Link HS110 WiFi-controlled switches into use. They're Echo-accessible so I figure it wouldn't be too tough to create native Indigo support?

Posted on
Fri Dec 29, 2017 12:38 am
spiv offline
Posts: 190
Joined: Jul 15, 2014

Re: TP-Link WiFi Switches

Just found this:

https://blog.georgovassilis.com/2016/05 ... mart-plug/

And a more detailed analysis with a command line python script:

https://github.com/softScheck/tplink-smartplug


Does anyone know if either of these still work?

If so, should be straightforward for the plug-in experts here to create a simple python script plugin to turn the plug on or off.

Oh, the reason this is interesting now is recently. Amazon had a deal where if you bought an Amazon Dot, you could buy a tp-link on/off switch for only $5 more. (I assume they were dumping the older model since TP-Link has a newer version out now.)

Posted on
Fri Dec 29, 2017 9:43 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: TP-Link WiFi Switches

No need for a plugin really - just execute a run shell script action that points to that script.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Dec 29, 2017 1:21 pm
spiv offline
Posts: 190
Joined: Jul 15, 2014

Re: TP-Link WiFi Switches

Thanks!

I found there is also a module for HomeBridge, but I prefer the simpler approach of avoiding HomeBridge unless truly desired.

Posted on
Thu Jan 11, 2018 8:44 pm
kg23 offline
User avatar
Posts: 21
Joined: Dec 17, 2012

Re: TP-Link WiFi Switches

Dumb Question. How do you determine the ip address of the TP-Link switch for use in the command-line script?

Code: Select all
Usage
./tplink-smartplug.py -t <ip> [-c <cmd> || -j <json>]

Posted on
Fri Jan 12, 2018 11:47 am
spiv offline
Posts: 190
Joined: Jul 15, 2014

Re: TP-Link WiFi Switches

Use a node scanner like LAN Scan Pro for the Mac.

Posted on
Fri Jan 12, 2018 11:38 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: TP-Link WiFi Switches

kg23 wrote:
Dumb Question. How do you determine the ip address of the TP-Link switch for use in the command-line script?

Code: Select all
Usage
./tplink-smartplug.py -t <ip> [-c <cmd> || -j <json>]

Check your dhcp server’s lease list or log file.

Posted on
Fri Aug 09, 2019 2:31 am
ChopOMatic offline
Posts: 110
Joined: Sep 12, 2014

Re: TP-Link WiFi Switches

I'm not a coder and I do it so seldom that every time I need to do something like this I'm starting from scratch.

All that said...

I now have scripts that turn on, turn off, and pull info from the TP-Link switches perfectly. My problem is that there doesn't seem to be a way to query the switches for only the on/off state, which is all I need. The 'info' command returns everything about the switch:

Code: Select all
{
   "system": {
      "get_sysinfo": {
         "err_code": 0,
         "sw_ver": "1.2.5 Build 171206 Rel.085954",
         "hw_ver": "1.0",
         "type": "IOT.SMARTPLUGSWITCH",
         "model": "HS110(US)",
         "mac": "50:C7:BF:00:40:51",
         "deviceId": "8006E9DC881A5D7A3227882E4D3B0B7616C73011",
         "hwId": "60FF6B258734EA6880E186F8C96DDC61",
         "fwId": "00000000000000000000000000000000",
         "oemId": "FFF22CFF774A0B89F7624BFC6F50D5DE",
         "alias": "GK",
         "dev_name": "Wi-Fi Smart Plug With Energy Monitoring",
         "icon_hash": "",
         "relay_state": 0,
         "on_time": 0,
         "active_mode": "none",
         "feature": "TIM:ENE",
         "updating": 0,
         "rssi": -65,
         "led_off": 0,
         "latitude": 30.157556,
         "longitude": -95.501769
      }
   }
}


How do I extract the value for just the relay_state?

Thanks...

Chop

Posted on
Fri Aug 09, 2019 2:54 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: TP-Link WiFi Switches

ChopOMatic wrote:
How do I extract the value for just the relay_state?


Code: Select all
results['system']['get_sysinfo']['relay_state']


Post the entire script if want the exact syntax.

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

Posted on
Fri Aug 09, 2019 2:58 am
ChopOMatic offline
Posts: 110
Joined: Sep 12, 2014

Re: TP-Link WiFi Switches

This is the script I'm using that returns the JSON data above.

Code: Select all
#!/bin/sh

python tplink_smartplug.py -t 10.0.0.26 -c info

Posted on
Fri Aug 09, 2019 3:04 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: TP-Link WiFi Switches

And what do you want to do with that result once you have it?

You're going to need to do this as a Python script, not a shell script.

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

Posted on
Fri Aug 09, 2019 3:13 am
ChopOMatic offline
Posts: 110
Joined: Sep 12, 2014

Re: TP-Link WiFi Switches

All I want to do is populate an ON or OFF status in Indigo.

Posted on
Fri Aug 09, 2019 3:14 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: TP-Link WiFi Switches

ChopOMatic wrote:
All I want to do is populate an ON or OFF status in Indigo.


I assume you mean an Indigo variable? Possibly used as the status for a Virtual device?

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

Posted on
Fri Aug 09, 2019 3:15 am
ChopOMatic offline
Posts: 110
Joined: Sep 12, 2014

Re: TP-Link WiFi Switches

Correct. Populate a variable.

Posted on
Fri Aug 09, 2019 3:18 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: TP-Link WiFi Switches

Code: Select all
#import json

# do the http request
reply = requests.get('python tplink_smartplug.py -t 10.0.0.26 -c info')

# convert the text result to Python dictionary
data = json.loads(result_json)

# extract the state
state = data['system']['get_sysinfo']['relay_state']

# update the variable (put in the correct variable ID)
indigo.variable.updateValue(1234567, value=state)

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

Who is online

Users browsing this forum: No registered users and 3 guests