Page 1 of 8

TP-Link WiFi Switches

PostPosted: Mon Nov 07, 2016 10:08 pm
by ChopOMatic
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?

Re: TP-Link WiFi Switches

PostPosted: Fri Dec 29, 2017 12:38 am
by spiv
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.)

Re: TP-Link WiFi Switches

PostPosted: Fri Dec 29, 2017 9:43 am
by jay (support)
No need for a plugin really - just execute a run shell script action that points to that script.

Re: TP-Link WiFi Switches

PostPosted: Fri Dec 29, 2017 1:21 pm
by spiv
Thanks!

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

Re: TP-Link WiFi Switches

PostPosted: Thu Jan 11, 2018 8:44 pm
by kg23
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>]

Re: TP-Link WiFi Switches

PostPosted: Fri Jan 12, 2018 11:47 am
by spiv
Use a node scanner like LAN Scan Pro for the Mac.

Re: TP-Link WiFi Switches

PostPosted: Fri Jan 12, 2018 11:38 pm
by berkinet
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.

Re: TP-Link WiFi Switches

PostPosted: Fri Aug 09, 2019 2:31 am
by ChopOMatic
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

Re: TP-Link WiFi Switches

PostPosted: Fri Aug 09, 2019 2:54 am
by FlyingDiver
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.

Re: TP-Link WiFi Switches

PostPosted: Fri Aug 09, 2019 2:58 am
by ChopOMatic
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

Re: TP-Link WiFi Switches

PostPosted: Fri Aug 09, 2019 3:04 am
by FlyingDiver
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.

Re: TP-Link WiFi Switches

PostPosted: Fri Aug 09, 2019 3:13 am
by ChopOMatic
All I want to do is populate an ON or OFF status in Indigo.

Re: TP-Link WiFi Switches

PostPosted: Fri Aug 09, 2019 3:14 am
by FlyingDiver
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?

Re: TP-Link WiFi Switches

PostPosted: Fri Aug 09, 2019 3:15 am
by ChopOMatic
Correct. Populate a variable.

Re: TP-Link WiFi Switches

PostPosted: Fri Aug 09, 2019 3:18 am
by FlyingDiver
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)