TP-Link Tapo Plug P115

From WickyWiki
Revision as of 22:05, 12 July 2023 by Wilbert (talk | contribs) (Created page with "Category:Home Automation Category:Domotica Category:202307 = Matter = The future of integration of home automation devices seems to be the [https://en.wikipedia.org/wiki/Matter_(standard) Matter] standard. This is fairly new (2022) and currently only few devices support it. We may also assume that manufacturers will still work hard to inject their data-collection routines. However, the coolest thing is, it describes that local control should be possible and...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Matter

The future of integration of home automation devices seems to be the Matter standard. This is fairly new (2022) and currently only few devices support it. We may also assume that manufacturers will still work hard to inject their data-collection routines. However, the coolest thing is, it describes that local control should be possible and it will enable us to access these devices with our own code.

Tapo Plug Control

TP-Link has two similar product-lines that are not compatible. It seems that Tapo is a bit newer but both products are said to be supported and updated. This guide is made for the Tapo P115 plug:

Counter part (US outlets):

Basically:

  • P100 is big an clunky
  • P105 supports energy monitoring
  • P110 is the same as P100 but a smaller-sized version
  • P115 is both small and supports energy monitoring

The Tapo devices can officially only be controlled with the TP-Link Tapo app, you need to register for an account and link your devices. Ultimately, credentials will be stored on the device, a live internet connection is not necessary after that.

Setup

With the TP-Link Tapo app:

  1. Connect to your Tapo account
  2. To restart setup of Wifi: hold the reset button for 5 seconds
  3. To factory reset the Tapo device: hold the reset button for 10 seconds
  4. The Tapo device will start with a Wifi open network
  5. Connect to this network with you mobile device
  6. Detect and register the device with the app
  7. Using the app, connect the device to your Wifi Guest network

The device is now in your Wifi network, for the next part it is best to make sure it always receives the same IP address. You can configure this in the DHCP settings in your router.

Reverse Engineering

Below "tapo-plug" project didn't work out for me but it has some reverse engineering information (without further documentation)

Some method examples may help figuring out how other methods should be called:

  • get_device_running_info
    • { "method": "get_device_running_info", "requestTimeMils":0, "terminalUUID": uuid }
  • get_diagnose_status
    • { "method": "get_diagnose_status", "requestTimeMils":0, "terminalUUID": uuid }
  • Get plug time usage
    • { "method": "get_device_usage", "requestTimeMils":0, "terminalUUID": uuid }
  • Unknown:
    • { "method": "qs_component_nego", "params": { "device_id":get_device_info['result']['device_id'], }, "requestTimeMils":0, "terminalUUID": uuid }
  • set_led_info
    • { "method": "set_led_info", "params": { "led_status":False, "led_rule":"never", "night_mode":{ "night_mode_type":"unknown", "sunrise_offset":0, "sunset_offset":0, "start_time":0, "end_time":0 } }, "requestTimeMils":0, "terminalUUID": uuid, }
  • get_wireless_scan_info
    • { "method": "get_wireless_scan_info", "params": { "start_index":0 }, "requestTimeMils":0, "terminalUUID": uuid }
  • wifi settings
    • { "method": "set_qs_info", "params": { 'account': { 'password': b64encode(deviceInfo['tapoEmail'].encode()).decode("utf-8"), 'username': b64encode(deviceInfo['tapoPassword'].encode()).decode("utf-8") }, 'time': { 'latitude': 90, 'longitude': -135, 'region': deviceInfo['region'], 'time_diff': 60, 'timestamp': 1619885501 }, 'wireless': { 'key_type': deviceInfo['key_type'], 'password': b64encode(deviceInfo['password'].encode()).decode("utf-8"), 'ssid': b64encode(deviceInfo['ssid'].encode()).decode("utf-8") } }, "requestTimeMils":0, "terminalUUID": uuid }
  • get_schedule_rules
    • { "method": "get_schedule_rules", "params": { "start_index":0 } }

Firmware updates

  • Currently (2023 july) having firmware 1.2.3 Build 230425 Rel. 142542 and it works
  • Once you have everything working it is probably best to disable automatic firmware update from the app

Python control

There are some people who managed to work out how to control this device without the app in the local network. It this particular case using a Python module.

I used the code from this project:

pip3 install PyP100

Packages are installed in the 'local' directory of the user: /$HOME/.local/lib/python3.7/site-packages/

Login python3:

import PyP110

p110 = PyP100.P110(ipAddress, user, password)

#Creates the cookies required for further methods
p110.handshake() 

#Sends credentials to the plug and creates AES Key and IV for further methods
p110.login()

Control python3:

#Turns the connected plug on
p110.turnOn() 

#Turns the connected plug off
p110.turnOff() 

#Toggles the state of the connected plug
p110.toggleState()

#Turns the connected plug on after 10 seconds
p110.turnOnWithDelay(10)

#Turns the connected plug off after 10 seconds
p110.turnOffWithDelay(10)

#Returns dict with all the device info of the connected plug
print( p110.getDeviceInfo() )

#The P110 has all the same basic functions as the plugs and additionally allow for energy monitoring.
print( p110.getEnergyUsage() )

TODO

  • It has the local timezone date and time and seems to update this every 30 mins from ntp.org. It will probably work well with daylight saving time.