Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

TP-LINK Smart Plug VD


Unified_io

Question

Hi!

 

Let me start off by saying I've zero experience and knowledge with working with API's so I'm not sure if this is even going to be possible.

 

I'm trying to make a Virtual Device to turn on/off some TP-Link Smart Plugs I have.

 

The Controller I'm using is a HCL

 

 

 

I've scoured the Internet and found a way of controlling these plugs via a HTTP POST request. To turn on the plug you can use the following (and to turn off you can simply substitute the state value with a 0 to turn off)

curl --request POST "https://your_region_specific_url/?token=your_token_here HTTP/1.1" \
 --data '{"method":"passthrough", "params": {"deviceId": "your_device_id_here", "requestData": "{\"system\":{\"set_relay_state\":{\"state\":0}}}" }}' \
--header "Content-Type: application/json"

 

 

 

And to get the device state, you can use the following:

 

curl -s --request POST "https://your_region_specific_url/?token=your_token_here HTTP/1.1"\
 --data '{"method":"passthrough", "params": {"deviceId": "your_device_id_here", "requestData": "{\"system\":{\"get_sysinfo\":null},\"emeter\":{\"get_realtime\":null}}" }}'\
 --header "Content-Type: application/json" | grep -q '..relay_state..:1' && echo "ON" || echo "OFF"

 

 

 

How would I format this to make it compatible for buttons on a HCL compatible VD? I've spent a couple of hours trial and error but getting nowhere (mainly because I can't seem to find any error logs - does the HCL even have any?)

 

I'd be incredibly appreciative of some help!

 

 

UPDATE

 

I'm guessing this would be the correct format for the buttons however I still don't seem to be able to get this to work?

 

POST /?token=your_token_here HTTP/1.1
Host: your_regional_specific_url_here
Content-Type: application/json

{"method":"passthrough", "params": {"deviceId": "your_device_id_here", "requestData": "{\"system\":{\"set_relay_state\":{\"state\":0}}}" }}

 

Edited by Unified_io
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

@Unified_io  (also @iceagescrat )

 

as Your post pointed me to the right direction I will try to help You. It looks like You have HC2. I am using HC3 so it is a bit different, but You should handle this on your own.

The source of my knowlede is

Please login or register to see this link.

page.

 

1. PREPARATION

Create a unique identifier for Your script (VD) - it should be valid UUID v4 - You can use

Please login or register to see this link.

 

2. AUTHORIZATION:

Please login or register to see this link.

So the first thing to do is to get the valid token (I don't know how long it is valid, but I assume we should re-generate it every time we call the set of actions).

 

Make a POST request to

Please login or register to see this link.

with the following body:

 

Please login or register to see this code.

where cloudUserName / cloudPassword are your KASA credentials, and terminalUUID is the one You generated in #1

 

3. LIST YOUR DEVICES:

Please login or register to see this link.

 

Make a POST request to

Please login or register to see this link.

/?token=YOUR_TOKEN

with the following request body:

 

Please login or register to see this code.

 

The DeviceId from the response is static for Your device, so You can check it once and hardcode in Your script.

 

4. CONTROL YOUR DEVICE

Please login or register to see this link.

 

Make a POST request to

Please login or register to see this link.

/?token=YOUR_TOKEN

with the following request body:

 

Please login or register to see this code.

 

 

In the attachment I add my lua script (HC3) that I use for turning ON / OFF my HS100 TpLink smart plug.

 

Please login or register to see this attachment.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...