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
Sun Aug 11, 2019 5:17 pm
ChopOMatic offline
Posts: 110
Joined: Sep 12, 2014

Re: TP-Link WiFi Switches

When I try to run the script from where it is now (a location from which I can run the script fine in Terminal), I get the following error:

Action Collection Error Script file doesn't exist: /usr/local/bin/gkmain_info.sh

Posted on
Sun Aug 11, 2019 5:18 pm
ChopOMatic offline
Posts: 110
Joined: Sep 12, 2014

Re: TP-Link WiFi Switches

And BTW, when I copy gkmain_info.sh to /users/chopomatic/ and try to run it from there, the script generates an error that it can't call tplink_smartplug.py. (Which is in /usr/local/bin/

Posted on
Sun Aug 11, 2019 7:19 pm
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: TP-Link WiFi Switches

ChopOMatic wrote:
And BTW, when I copy gkmain_info.sh to /users/chopomatic/ and try to run it from there, the script generates an error that it can't call tplink_smartplug.py. (Which is in /usr/local/bin/

In the shell script, change the path to the python script to
Code: Select all
/usr/local/bin/tplink_smartplug.py ...

Posted on
Sun Aug 11, 2019 9:20 pm
ChopOMatic offline
Posts: 110
Joined: Sep 12, 2014

Re: TP-Link WiFi Switches

Focusing first on getting 'grep' and 'cut' working right...

The code as suggested
Code: Select all
 | grep relay_state | cut -c25
is returning the 25th character of the entire results string, ie. "e"

Posted on
Mon Aug 12, 2019 12:19 am
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: TP-Link WiFi Switches

ChopOMatic wrote:
Focusing first on getting 'grep' and 'cut' working right...

The code as suggested
Code: Select all
 | grep relay_state | cut -c25
is returning the 25th character of the entire results string, ie. "e"

Hmm. Worked ok here using your output posted below. In any case, just remove the “[ cut -c25” and you should have the full line with relay_state. Then count the columns (characters, including spaces) to the 0 or 1. Then add back the cut command and adjust the column (-c) until it is right.

Posted on
Mon Aug 12, 2019 3:50 am
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: TP-Link WiFi Switches

Perhaps the actual output from tplink_smartplug.py is not exactly as you posted. I am guessing there are actually an additional 4 spaces at the start of each line. I put together the following file (called tmpfil) . I cut the relevant (relay_state) line from your example and pasted it in twice, once as posted and a second time with 4 leading spaces. I also added column numbers at the top of the file.
Code: Select all
         111111111122222222223
123456789012345678901234567890
         "relay_state": 0,
             "relay_state": 0,
Then. I ran
Code: Select all
berkinet$ !cut -c25 <tmpfil
2
5
0
e
and voila, it looks like you really want column 29.

By the way, you can probably simplify things a tiny bit by changing the first line of tplink_smartplug.py from
    #!/usr/bin/env python2
    to
    #!/usr/bin/env python
and making sure the program is executable: chmod 755 /usr/local/bin/ tplink_smartplug.py
Then the shell script can directly call tplink_smartplug.py
Code: Select all
/usr/local./bin/tplink_smartplug.py -t 10.0.0.26 -c info | grep relay_state | cut -c29

Posted on
Mon Aug 12, 2019 8:41 pm
ChopOMatic offline
Posts: 110
Joined: Sep 12, 2014

Re: TP-Link WiFi Switches

You're exactly right. When I first posted the output here, it ran way off the right side of the browser page. I cleaned it up in a JSON formatter and reposted it.

Posted on
Mon Aug 12, 2019 8:58 pm
ChopOMatic offline
Posts: 110
Joined: Sep 12, 2014

Re: TP-Link WiFi Switches

Here's the output exactly as it appears:

Received: {"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":-69,"led_off":0,"latitude":30.157556,"longitude":-95.501769}}}

Posted on
Mon Aug 12, 2019 8:59 pm
ChopOMatic offline
Posts: 110
Joined: Sep 12, 2014

Re: TP-Link WiFi Switches

When I run the shell script with your latest code it returns a "y".

Posted on
Tue Aug 13, 2019 12:43 am
ChopOMatic offline
Posts: 110
Joined: Sep 12, 2014

Re: TP-Link WiFi Switches

Latest: I edited the tplink_smartplug.py script to get rid of the SENT/RECEIVED stuff. Now it returns exactly this:

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":-69,"led_off":0,"latitude":30.157556,"longitude":-95.501769}}}


BTW, sure would be nice if the switch supported a simple query for "relay_state." SIGH.

Posted on
Tue Aug 13, 2019 1:18 am
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: TP-Link WiFi Switches

ChopOMatic wrote:
Latest: I edited the tplink_smartplug.py script to get rid of the SENT/RECEIVED stuff. Now it returns exactly this:
Code: Select all
{"system":{"get_sysinfo":{"err_code":0,"sw_ver":"1.2.5 Build 171206 ...
Ok. we are getting somewhere. I have added a json pretty printer to the commands (pipeline) to make the output easier to parse (I.e. make it like the output you originally posted). I also added a bit (tr) at the end to remove the line-ending character so Indigo will correctly interpret the 0 or 1 as a boolean. Note the spacing around the pipe characters "|" is just for readability and is not required.

This should work with your modified script:
Code: Select all
/usr/local./bin/tplink_smartplug.py -t 10.0.0.26 -c info | json_pp | grep relay_state | cut -c26 | tr -d "\n"
and this will work with the original, unmodified script:
Code: Select all
/usr/local./bin/tplink_smartplug.py -t 10.0.0.26 -c info | sed -e "s/Received..//" | json_pp | grep relay_state | cut -c26 | tr -d "\n"

Posted on
Tue Aug 13, 2019 1:47 am
ChopOMatic offline
Posts: 110
Joined: Sep 12, 2014

Re: TP-Link WiFi Switches

First, huge thanks for all the help, you and Joe and everyone else. It's much appreciated.

I think we're almost there. The script now properly returns the state. Yay! It looks a little funky in Terminal but that's okay.

My last remaining problem can be seen in this screenshot. Not sure why Indigo is claiming the shell script doesn't exist.
Attachments
hs100.png
hs100.png (250.73 KiB) Viewed 7210 times

Posted on
Tue Aug 13, 2019 1:54 am
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: TP-Link WiFi Switches

ChopOMatic wrote:
...My last remaining problem can be seen in this screenshot. Not sure why Indigo is claiming the shell script doesn't exist.
Well, it is odd the Run Shell Script dialog box does not error on save if it can't find there file? Are you on the same machine as the Indigo server. In other words, are you using screen-sharing to access the Indigo machine?
Can you do ls -l /usr/local/bin/gkmain_info.sh and post that here.
and
post the contents of gkmain_info.sh

Posted on
Tue Aug 13, 2019 1:58 am
ChopOMatic offline
Posts: 110
Joined: Sep 12, 2014

Re: TP-Link WiFi Switches

Same machine.
Attachments
hs100-2.png
hs100-2.png (77.21 KiB) Viewed 7210 times

Posted on
Tue Aug 13, 2019 2:01 am
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: TP-Link WiFi Switches

Ahh. Probably permissions:
try chmod 755 /usr/local/bin/gkmain_info.sh

Page 3 of 8 1, 2, 3, 4, 5, 6 ... 8

Who is online

Users browsing this forum: No registered users and 1 guest