Table of Contents
TP-Link / Kasa
Currently at version 1.1 2/19/2020 and included in XTension 9.4.28
The TP-Link/Kasa plugin is included in the standard XTension distribution and supports the currently shipping appliance modules, dimming modules, non-color bulbs, color bulbs and color temperature bulbs as well as their multi-controllable outlet power strips. If the device supports the energy monitor functions then some combination of current usage in watts as well as historical KWH usage may also be available.
This plugin uses the local subnet protocol for discovering devices and controlling them. Only devices on the same local subnet with the XTension machine will be found, devices elsewhere in the cloud will not be discovered. An active internet connection then is not needed to control devices on the same subnet.
Note: There are many and varied WiFi controllable devices out there. This one is compatible only with devices branded as TP-Link or Kasa. This is not compatible with Sonoff or any other devices that I am aware of. There may be other off brand ones that use the same local network protocol, but I wouldn’t count on it just because they are made to look like the TP-Link devices.
Add the device to your local network in the normal way using the iOS or Android app. Once the device is available on your local wifi it will be discoverable by the XTension plugin.
Only a single instance of the plugin is necessary to control all the devices on the local subnet.
Device Discovery: If the “Automatically Create Units In XTension” checkbox is checked then any new device discovered on the network will automatically have a corresponding unit created in XTension. The “Discover New Devices Now” button should be clicked after you add new devices to the network so that they can be added to XTension’s database. There is also a scripting command to trigger a discovery process:
tell xInterface “this interface name” to discover()
That will return immediately as the discovery is an async process. If the “Create New Units” checkbox above is selected then any new units discovered will be created in XTension.
Default Polling Interval: TP-Link/Kasa devices do not send a message when their state is controlled locally or via the iOS or other app. The only way to know if you have controlled a device through another channel is to poll them regularly. Set to 0 to make the default to not poll a device or any number of seconds larger than 10. This is a very small amount of network traffic and doing it even as much as every 30 seconds should not cause any problematic usage on your network unless you have hundreds of devices. If you never control your devices from any other place than XTension you can turn this off entirely. The other purpose that regularly polling devices serves is to check for them to actually be online. When a device is controlled or polled and it is not responding, either because it has been manually turned off in the case of a bulb or unplugged in the case of an outlet it will figure that out and set a unit error at the poll. If you are not polling the devices then you will not have an indication that the device is not available until you try to control it and it is not there.
Each Unit has a configuration option to override the default polling interval for that specific device.
XTension Unit Types:
In XTension a Unit will be created for each Device discovered. You can manually create other units for the energy monitor functions if available. The Units when created will be given the same name that you have configured in the Kasa app when you set them up. After that you can change the name of the XTension unit to anything you wish. These changes are not sent back to the Devices. The names are only read when creating the units. Once the unit is created you can change the name of either the XTension Unit or the Device without affecting the other.
The address of the XTension Units will be the MAC address of the device with the exception of the powerstrip outlet Units which will be the MAC address followed by a period and then the index of the outlet starting at 0. So something like 12:34:56:78:90:A1:FF.0 for the first outlet and .1 for the second etc.
All units support the Query command. If you have polling turned off or just want to check the state or value of a unit at a specific time you can issue a query to ask the device for it’s current info.
query “name of unit you wish to query”
Remember that the query is done async. The query command returns immediately and if there is any change to the unit status then the unit will update when that is received back from the device.
All single end point devices like Smart Outlets and Smart Bulbs will create a single XTension Unit of type “Kasa Device”. Depending on the capabilities discovered when the unit is created it will be properly setup as dimmable or non-dimmable, as well as having it’s color and color temperature capabilities turned on or off automatically.
Device Polling: If you wish you can override the Default Polling Interval you set in the Plugin Settings window above. If you have polling turned off globally you can still enable it for individual Devices by setting a value here. Enter 0 to disable polling for this Device, leave blank to use the global default setting or set to any value greater than 5 seconds. The faster you poll a device the faster the XTension database will conform to the current settings of the device. When controlling a Device from XTension the database will always be correct, if you control the Device from another control point like the mobile app those changes must be polled to be found. If you never control the Device from anywhere but XTension you can turn polling off.
Send Power Recovery Preset Level: Some especially older Bulbs have a problem with turning on remotely to a different level or color than they were at when they were turned off. They will immediately start ramping to the last in use level before then changing to the new level you are sending them. This can be a problem if you are using the bulb somewhere you don’t want a flash of bright light when you turn on the light. Checking this box will have XTension send the brightness level you set immediately before turning it off. A low value like the default of 1% will avoid the Nova effect but it also makes it impossible to turn the lamp on by physically turning the bulb off and back on again, as it will only return to the 1% level. So for bulbs that do not nova you can turn this off.
You can also leave this on and then whenever XTension turns the bulb off it will send whatever value is there, This makes it possible to set the power on level whenever you turn off the bulb. This value is ONLY sent if XTension turns off the light, and the light is powered on and available at the time. It cannot change the level if the bulb is offline.
This is sent to the bulb anytime an Off is sent. The bulb does not have to be On to get this command, though you may see a momentary flicker of light from it as it starts to ramp up to the preset level before receiving it’s off command again.
You can change this value programmatically by using the setPowerRecoveryPreset command. See the section below on scripting commands for more info on using that.
Manage Meta Data Units: In addition to the Unit that controls the state of the device, you can optionally create units to track the energy usage and the devices wifi signal strength. Not all devices support these functions. If you create one for a device that does not track that information the new unit will be created but will quickly set an error condition noting that it cannot get that information.
The “Smart Strip” or other multi-outlet devices will be configured as a Powerstrip Unit. A top level unit will be created with it’s device type popup set to “Kasa Power Strip” Controlling this Unit will turn on or off all the outlets of the powerstrip.
If you create energy usage units for this unit they will be the sum of all the watts or KWH usage of all the outlets. To measure the usage of a single outlet create the appropriate unit from the Powerstrip Outlet unit below.
Only the top level powerstrip device can read it’s wifi signal strength. Creating an RSSI unit for an individual outlet will result in a unit with an error set.
After the main powerstrip Unit is created, a separate “Powerstrip Outlet” Unit will be created for each controllable outlet in the device. For many devices they can have their own watts and KWH monitoring units created but if you create an RSSI unit for an outlet it will just log an error condition as the individual outlets do not send a separate RSSI from the main device.
Other multi-outlet devices such as the outdoor dual outlet module and the wired outlet devices with each outlet controllable separately will show up as powerstrips with only 2 outlets or however many outlets that they support.
Set Power Recovery Preset Scripting Command:
In the section on Kasa Device setup above the setPowerRecoveryPreset command is mentioned. This is the scripting command you can use to change the value for the Unit at any time programatically. Note that this does not actually send anything to the Unit by itself, it just sets the value in the Unit preferences so that the next time an Off is sent to the Unit it can include this value. If the lamp is already off you can then send it an Off command which will not change the visible state of the Bulb but will reset it’s preset level. If the lamp is on you cannot send it the preset except by turning it off or just dimming it to the new level. If the bulb is physically powered off then no changes of any kind can be sent to the lamp.
This might be useful if you wanted to set a different power on level for lamps before going to bed vs in the morning and during the day or something similar to that.
tell xUnit “Name Of Your Kasa Bulb Unit in XTension” to setPowerRecoveryPreset( 75)
This plugin uses an undocumented protocol to talk to the devices on the local network and therefore does not require internet access or for the devices to be connected to the cloud in order to work. This is the same protocol that the Kasa iOS and Android app use to control the devices when on the same subnet. While I hope it is unlikely, it is possible that they could change this at any moment making the plugin unusable. I would recommend that before updating any devices firmware in the future that you verify either on this site or by experimenting with one device that things continue to work properly.
- The TP-Link/Kasa plugin was added as a beta version in XTension build 9.4.26 on 11/15/2019
- The automatic discovery interval was removed in version 1.1 of the plugin which was included in XTension build 9.4.28. The discovery would cause units to be lost if it intersected with an actual control or poll of a device. If you need to discover a new device click the Discover New Devices Now button at any time or use the scripting command documented above.
- Added the ability to control the power recovery preset level for Bulbs in XTension 9.5.2 and plugin version 2.0.4 in March of 2023.