smford / tplink-hs1x-cli

Simple command line tool to control TP-Link HS100 and HS110 Devices
0 stars 0 forks source link

How to configure the config.yaml file #23

Closed Gevaarlijk closed 8 months ago

Gevaarlijk commented 8 months ago

Hi,

I really want to be able to turn on or off a smart plug from windows and script it using a batch file. It seems your software can do this but before I go out and find a TP-link HS100 or 110 device and buy it can you explain how to make the config.yaml file?

Where would i find the IP address and what does small/large mean?

smford commented 8 months ago

@Gevaarlijk this software will certainly work, but the hs100 and hs110 are older devices that are harder to find brand new now.

You might want to check out the tplink p100 and p110 models instead, I am currently writing a command line app, similar to this one, to support them.

To answer your question:

---
devices:
  small: 192.168.10.44
  large: 192.168.10.127

You can find the ip address by looking at the configuration section of the device within your phones tapo app. I use static ips at home. If you have dns setup you can replace the ips with whatever hostname appropriate.

The config file is in standard yaml format.

The small/large - they are just human readable names for the device. I have a small light, and i have a large light! You can change it to be whatever you like, you can add extra devices even.

The name used to tell the app which device to run the action on, for example:

tplink-hs1x-cli --do off --device small
Gevaarlijk commented 8 months ago

Thank you for replying!

I actually got it to work with some trial and error and I specifically bought a Hs100 secondhand for this.

The ip address was not in the Kasa app (I never heard of Tapo app) but I found it by querying my router and guessing.

My plug received a dynamic IP address though so I'm afraid the software will fail if the IP address changes. Can you give me a pointer in how to prevent this? I'm not very experienced here.

The small/large thing is what really threw me off. To a layman it looks like I'd have to give a range with IP addresses from smallest to largest. Would have been easier to understand if you'd call it smalllamp and largelamp. ;-)

Anyway, thank you for your software. I have a setup where I use an infrared heating panel on the ceiling above my workspace. When I leave my workspace I have a script running that verifies if I haven't touched keyboard or mouse for 10 minutes at which point another script is launched which turns off the smartplug that connects the infrared panel. I used to do this by sending a webhook through IFTTT but last week they removed all free webhooks and make people pay a monthly fee. So I found your solution as an alternative and it works pretty well so far.

So thank you!

smford commented 8 months ago

@Gevaarlijk

Anyway, thank you for your software. I have a setup where I use an infrared heating panel on the ceiling above my workspace. When I leave my workspace I have a script running that verifies if I haven't touched keyboard or mouse for 10 minutes at which point another script is launched which turns off the smartplug that connects the infrared panel. I used to do this by sending a webhook through IFTTT but last week they removed all free webhooks and make people pay a monthly fee. So I found your solution as an alternative and it works pretty well so far.

So thank you!

Nice setup! No thank you for using it, totally my pleasure! It made me genuinely happy knowing someone actually uses it! :D

The small/large thing is what really threw me off. To a layman it looks like I'd have to give a range with IP addresses from smallest to largest. Would have been easier to understand if you'd call it smalllamp and largelamp. ;-)

Good fair point! When I next do an update, over the next couple weeks, I will do this, thanks for the feedback!

The ip address was not in the Kasa app (I never heard of Tapo app) but I found it by querying my router and guessing.

Oops sorry, I said the wrong app - TPLink use two apps strangely, ones Tapo the others Kasa. I just checked and you are correct, kasa strangely doesnt show the IP.

My plug received a dynamic IP address though so I'm afraid the software will fail if the IP address changes. Can you give me a pointer in how to prevent this? I'm not very experienced here.

Firstly, there isn't any easy way for the software to discover your device and keep itself updated. Technically its possible, but not something I want to invest loads of time doing because I'm very time poor and I know it would take a good number of hours.

But there is a solid alternative way which I and most other people use, which will solve the problem for you:

OK, I can't answer you precisely because it is very much dependant on your setup which will be very different from my own, but I can give you a generic pointer. So, you are correct, most sensible people will be using dhcp - called dynamic ip allocation - to assign an ip address to the device, which you are correct, could mean it changes over time.

With many routers or wireless access points you can go in to the configuration of it and tell it to "whenever it sees a specific device, always give that device the same ip, and don't give that ip to any other device ever". This means your device will effectively get given a static ip address even when using dhcp (dynamic ip allocation). This feature is pretty standard across most routers these days, but will often go by different names and use different words to describe the feature.

How it works for me: I connect my brand new HS100/hs110 to my network, I then login to the configuration webpage for my router/wireless access point, I then click DHCP, then click "Leases", then I find my device in the list and click a button called "map to static IP". And during that process I note down the IP and put in to the config.yaml.

The easiest way to determine from the list of devices which is your hs100/hs110 plug is to check MAC addresses, this is a unique identifier for the device. When your router sees this MAC address, it will assign the static ip to it.

To find out the MAC address of your hs100/hs110, go in to the kasa app, click on the device, then go in to settings. Below is a picture of the MAC address. You then use this to identify your device in your routers dhcp configuration page which lists devices.

hs100-example

Lastly, tplink have discontinued the hs100/hs110's. They appear to have replaced them with the models p100 (plug) and p110 (plug with energy monitoring). Last week I picked up some p110s and have been playing with them a little and writing software to control them just like this app. I will release that over the next couple weeks as I've got the basics of it working. If you needed to buy more plugs look at those models as they'll be easier to purchase.

Gevaarlijk commented 8 months ago

Thank you so much for your detailed explanation. This actually turned out to be pretty easy as a result.

https://i.vgy.me/aJAhZk.png

Think I did it.