Think of this as a small library file that will add direct LAN control between your Photon project and TP-Link devices. Possible uses include:
- Garage opener - add to light a lamp in the house when door is opened
- Doorbell - add to turn on the porch light when pressed
- Use to control smart plugs instead of high voltage wiring
It will not interfer with Alexa or Kasa app control of the same device.How it works
TP-Link devices are WiFi based Smart Bulbs and Smart Plugs that do not need a central automation hub to work; they use your WiFi router instead. As such, it is easy for any local LAN device to control them directly provided that you use their packet protocol. The research done in this SoftCheck article, explains that protocol. The files TPLink.cpp and TPLink.h have the simple routines needed to use that protocol and issue direct commands. Add these two files to your project's src folder then place into your project.
Now add the desired subroutine calls:
//for bulbs, call TPLink_Bulb(uint8_t * lampIP, int state, int percent); //for plugs, call TPLink_Plug(uint8_t * plugIP, int state); //where state = 0 for OFF, state = 1 for ON //where percent = 1 for lowest brightness, percent = 100 for maximum brightness //for LB130 bulbs, call either routine depending on your parameters //TPLink_LB130Bulb(uint8_t * lampIP, int state, int hue, int saturation, int percent); //TPLink_RGB_Bulb(uint8_t * lampIP, int state, int Red, int Green, int Blue); //where hue = 0 to 360. saturation = 0 to 100, percent = 0 to 100 //where Red,Blue,Green are 0 to 255
Demo projects are shown as examples of how to call the routines. They have been tested with LB100 bulbs, LB130 bulbs, and HS105 plugs.IP Addresses
In order for this to work properly, you will need to know the IP Address of each device you wish to control. You can discover this from your WiFi router's connected device page and comparing the MAC addresses with those lised for each device in the TP-Link Kasa App. Use your router's reserve IP function to make those addresses permanent.Example Projects
This example project shows the basic bulb and plug subroutine usage needed to issue control commands.
This example project shows how to generate a candle flicker effect on a TP-Link bulb. Use this as part of your next Halloween lighting project for pumpkin or front porch light. Or haunt your whole house with the Vixen bridge project below.
This example project uses the Photon to create a Vixen Lights sACN stream to TPLink bulb control bridge. It's a bit more advanced than the other projects and you need to understand Vixen and controller patching. NOTE: ACN uses multicast packets and some WiFi routers group these into a packed burst instead of a true time domain spread; this may affect your presentation.
This example project uses the Photon to create a Vixen Lights BlinkyLinky protocol to TPLink bulb control bridge. It has lower network overhead than ACN and might work better with some WiFi systems.
This example project shows how to control your local TP-Link device via a Photon that acts as a hub and is connected to the Particle.io cloud . You can add the code to an existing Photon or use a dedicated Photon for the project.
Detailed Ring Doorbell to Photon via IFTTT implementation example
This is an IFTTT example of how to light the front porch when your Ring doorbell is pressed. Load your Photon with the TPLinkHub project and adjust the bulb IP address accordingly. With the Photon running the project, use your Particle App to test trigger the FrontPorch routine. Finally, go to your IFTTT account's applet section and create a new applet. Here are the steps to complete:Step 1
Choose a service.
Then select the trigger for the doorbell press.
Create the trigger.
Select Particle for the THAT.
Select the Call a function.
Specify the function.
Click Create and you are done. In actual testing I observed that this can take over 60 seconds to transfer the press detection to Ring to IFTTT to Particle to your Photon to the bulb; but it demonstrates the process.