[Custom Component] TP-Link Router Integration

@awg Sory, fixed the code. Could you run this?

from tplinkrouterc6u import TplinkRouter
from logging import Logger

client = TplinkRouter('192.168.0.1', 'yourPassword', logger=Logger('test'))
client.authorize()
print(client.request('admin/smart_network?form=game_accelerator', 'operation=loadDevice'))
print('---')
print(client.request('admin/wireless?form=statistics', 'operation=load'))

And could you post the result with your Iot devices and wifi devices connected. I need to check the difference between an IoT device and other wifi devices or lan devices

This should be the info, sanitized and simplified:

[
    {'enableLimit': 'off', 'index': 25, 'trafficUsage': 63990689, 'deviceType': '***', 'remainTime': 0, 'deviceName': '***', 'key': '***', 'uploadSpeed': 0, 'onlineTime': 8774.8499999996, 'mac': '***', 'downloadSpeed': 0, 'deviceTag': 'iot_2.4G', 'isGuest': False, 'downloadLimit': 1024, 'uploadLimit': 200, 'enablePriority': False, 'txrate': 65000, 'ip': '***', 'rxrate': 72000, 'timePeriod': -1, 'speedLimitOnline': True, 'signal': -33
    },
    {'enableLimit': 'off', 'index': 7, 'trafficUsage': 9482492, 'deviceType': '***', 'remainTime': 0, 'deviceName': '***', 'key': '***', 'uploadSpeed': 0, 'onlineTime': 47508.85, 'mac': '***', 'downloadSpeed': 0, 'deviceTag': 'iot_2.4G', 'isGuest': False, 'downloadLimit': 1024, 'uploadLimit': 200, 'enablePriority': False, 'txrate': 72000, 'ip': '***', 'rxrate': 52000, 'timePeriod': -1, 'speedLimitOnline': True, 'signal': -59
    },
    {'enableLimit': 'off', 'index': 21, 'trafficUsage': 1129520, 'deviceType': '***', 'remainTime': 0, 'deviceName': '***', 'key': '***', 'uploadSpeed': 0, 'onlineTime': 1421902.85, 'mac': '***', 'downloadSpeed': 0, 'deviceTag': 'iot_2.4G', 'isGuest': False, 'downloadLimit': 1024, 'uploadLimit': 200, 'enablePriority': False, 'txrate': 43000, 'ip': '***', 'rxrate': 48000, 'timePeriod': -1, 'speedLimitOnline': True, 'signal': -65
    },
    {'enableLimit': 'off', 'index': 13, 'trafficUsage': 1752272, 'deviceType': '***', 'remainTime': 0, 'deviceName': '***', 'key': '***', 'uploadSpeed': 0, 'onlineTime': 1441104.85, 'mac': '***', 'downloadSpeed': 0, 'deviceTag': 'iot_2.4G', 'isGuest': False, 'downloadLimit': 1024, 'uploadLimit': 200, 'enablePriority': False, 'txrate': 2000, 'ip': '***', 'rxrate': 72000, 'timePeriod': -1, 'speedLimitOnline': True, 'signal': -58
    },
    {'enableLimit': 'off', 'index': 22, 'trafficUsage': 233647, 'deviceType': '***', 'remainTime': 0, 'deviceName': '***', 'key': '***', 'uploadSpeed': 0, 'onlineTime': 48032.85, 'mac': '***', 'downloadSpeed': 0, 'deviceTag': 'iot_2.4G', 'isGuest': False, 'downloadLimit': 1024, 'uploadLimit': 200, 'enablePriority': False, 'txrate': 72000, 'ip': '***', 'rxrate': 72000, 'timePeriod': -1, 'speedLimitOnline': True, 'signal': -53
    },
    {'enableLimit': 'off', 'index': 11, 'trafficUsage': 52003508, 'deviceType': '***', 'remainTime': 0, 'deviceName': '***', 'key': '***', 'uploadSpeed': 0, 'onlineTime': 11554.85, 'mac': '***', 'downloadSpeed': 0, 'deviceTag': '5G', 'isGuest': False, 'downloadLimit': 1024, 'uploadLimit': 200, 'enablePriority': False, 'txrate': 780000, 'ip': '***', 'rxrate': 6000, 'timePeriod': -1, 'speedLimitOnline': True, 'signal': -61
    },
    {'enableLimit': 'off', 'index': 6, 'trafficUsage': 428585317, 'deviceType': '***', 'remainTime': 0, 'deviceName': '***', 'key': '***', 'uploadSpeed': 0, 'onlineTime': 11514.85, 'mac': '***', 'downloadSpeed': 0, 'deviceTag': '5G', 'isGuest': False, 'downloadLimit': 1024, 'uploadLimit': 200, 'enablePriority': False, 'txrate': 864000, 'ip': '***', 'rxrate': 720000, 'timePeriod': -1, 'speedLimitOnline': True, 'signal': -58
    },
    {'enableLimit': 'off', 'index': 12, 'trafficUsage': 1397004, 'deviceType': '***', 'remainTime': 0, 'deviceName': '***', 'key': '***', 'uploadSpeed': 0, 'onlineTime': 1443410.85, 'mac': '***', 'downloadSpeed': 0, 'deviceTag': 'iot_5G', 'isGuest': False, 'downloadLimit': 1024, 'uploadLimit': 200, 'enablePriority': False, 'txrate': 150000, 'ip': '***', 'rxrate': 150000, 'timePeriod': -1, 'speedLimitOnline': True, 'signal': -52
    },
    {'enableLimit': 'off', 'index': 14, 'trafficUsage': 13715456, 'deviceType': '***', 'remainTime': 0, 'deviceName': '***', 'key': '***', 'uploadSpeed': 0, 'onlineTime': 415640.85, 'mac': '***', 'downloadSpeed': 0, 'deviceTag': 'iot_5G', 'isGuest': False, 'downloadLimit': 1024, 'uploadLimit': 200, 'enablePriority': False, 'txrate': 150000, 'ip': '***', 'rxrate': 150000, 'timePeriod': -1, 'speedLimitOnline': True, 'signal': -37
    },
    {'enableLimit': 'off', 'index': 8, 'trafficUsage': 1451564820, 'deviceType': '***', 'remainTime': 0, 'deviceName': '***', 'key': '***', 'uploadSpeed': 0, 'onlineTime': 11544.85, 'mac': '***', 'downloadSpeed': 0, 'deviceTag': '5G', 'isGuest': False, 'downloadLimit': 1024, 'uploadLimit': 200, 'enablePriority': False, 'txrate': 866000, 'ip': '***', 'rxrate': 780000, 'timePeriod': -1, 'speedLimitOnline': True, 'signal': -55
    },
    {'enableLimit': 'off', 'index': 15, 'trafficUsage': 1748651421, 'ip': '***', 'remainTime': 0, 'deviceName': '***', 'key': '***', 'uploadSpeed': 0, 'onlineTime': 22764.85, 'mac': '***', 'downloadSpeed': 0, 'isGuest': False, 'deviceType': '***', 'downloadLimit': 1024, 'uploadLimit': 200, 'enablePriority': False, 'timePeriod': -1, 'speedLimitOnline': True, 'deviceTag': 'wired'
    },
]
---
[
    {'mac': '**-**-**-**-**-**', 'type': '5GHz', 'encryption': 'wpa2', 'rxpkts': 0, 'txpkts': 0
    },
    {'mac': '**-**-**-**-**-**', 'type': '5GHz', 'encryption': 'wpa2', 'rxpkts': 0, 'txpkts': 0
    },
    {'mac': '**-**-**-**-**-**', 'encryption': 'wpa/wpa2-psk', 'rxpkts': 0, 'txpkts': 0
    },
    {'mac': '**-**-**-**-**-**', 'encryption': 'wpa/wpa2-psk', 'rxpkts': 0, 'txpkts': 0
    },
    {'mac': '**-**-**-**-**-**', 'encryption': 'wpa2', 'rxpkts': 0, 'txpkts': 0
    },
    {'mac': '**-**-**-**-**-**', 'encryption': 'wpa2', 'rxpkts': 0, 'txpkts': 0
    }
]

@awg Thank you!

@awg What is it in deviceType parameter?

Looks to be a pre-determined set of strings from the router that attempt to describe the device, some examples are: Laptop, Tablet, IP Camera, Doorbell, etc. I donā€™t know what the full possible list is.

v1.13.0 Released

Changelog

@awg Added IoT Wi-Fi network clients number for Archer AX3000. Please download the new version and let me know

1 Like

Some time ago, I tried a tp-link integrating with a AX3000, but every time I accessed the routerā€™s web interface to view the clientsā€™ IP addresses, the portal close after a couple of seconds, preventing me from seeing the IPs. Does anyone know why this was happening?

Looks great, thanks for adding it in!

v1.13.1 Released

Changelog

I have python 3 installed on my laptop, what the command i must run in cmd?
I just run client.py, but have only:

C:\adb\1>client.py

C:\adb\1>client.py

C:\adb\1>

You have to find out how the encryption works for this router in JS files first. Than try to write the code in python to get the data from router. Unfortunately, there is no concrete algorithm for that

@ArmC The TP-Link Web Interface only supports upto 1 user logged in at a time (for security reasons, apparently). So you will be logged out from router web interface when the integration updates data

I have made a research.
These routers also should be supported

Models:

  • Deco M5
  • Deco P7
  • Deco X20
  • Deco X60
  • Deco X90
1 Like

v1.13.2 Released

Changelog

Can you help me with the web encrypted password?

Iā€™m using the Archer C1200 model but I couldnā€™t find the password by following the step-by-step process on the integration page.

Forgive me if something is written wrong, Iā€™m using a translator.

@eujulianolopes Hi.
What is your router hardware version?

v1.13.3 Released

Changelog

  • Client update. Increased timeout

It turned out that some Deco routers require more time to update, which led to an error - TimeoutError: timed out.

v1.14.0 Released

Changelog

  • Added down_speed and up_speed for tracked device for Deco
  • Fixed Tp-link C1200 V2 error in request to /admin/smart_network

v1.15.0 Released

Added device events:

  • tplink_router_new_device: Fired when a new device appears in your network
  • tplink_router_device_offline: Fired when a device becomes offline
  • tplink_router_device_online: Fired when a device becomes online

Now you may create automation to receive notifications of appearing a new device in your network, or becoming device online\offline. Follow README instructions