I have created a way to use TP-Link Kasa lights for motion detection lighting through Blue Iris

JDfromDB

Getting the hang of it
Dec 20, 2019
41
34
CA
I wanted to trigger some of my Kasa lights from Blue Iris when my cameras detect motion. There is no public API available but there are a few web pages that list enough of the protocol for what I need. I used this info to create an exe that that will turn on a light for n seconds and then turn it off, if the light is already on, then it will do nothing.

To use this from Blue Iris you need to go to the camera settings and in the Alert tab add an action to call the exe when triggered.

The exe is named KasaMotionLight and it targets the .Net framework 4.8 so that is the only requirement.

The command line is as follows: KasaMotionLight id:<your login id> pw:<your password> s:<number of seconds to leave the light on> dev:<light name in the Kasa app>
Example: KasaMotionLight id:userid pw:secret s:60 dev:driveway_light

I only have a few of the various Kasa devices so it is possible that it will not work for some of them. It is also possible that Kasa will change the API at some point to break this but for now it works.

If anyone finds this useful, let me know how it works for you.
 

Attachments

I wanted to trigger some of my Kasa lights from Blue Iris when my cameras detect motion. There is no public API available but there are a few web pages that list enough of the protocol for what I need. I used this info to create an exe that that will turn on a light for n seconds and then turn it off, if the light is already on, then it will do nothing.

To use this from Blue Iris you need to go to the camera settings and in the Alert tab add an action to call the exe when triggered.

The exe is named KasaMotionLight and it targets the .Net framework 4.8 so that is the only requirement.

The command line is as follows: KasaMotionLight id:<your login id> pw:<your password> s:<number of seconds to leave the light on> dev:<light name in the Kasa app>
Example: KasaMotionLight id:userid pw:secret s:60 dev:driveway_light

I only have a few of the various Kasa devices so it is possible that it will not work for some of them. It is also possible that Kasa will change the API at some point to break this but for now it works.

If anyone finds this useful, let me know how it works for you.

Hi JD,
Thanks for the original post. Interested in controlling a TP link device via my Blue Iris system / camera motion. I'm not as technical as some. To use this I see how to set the .exe in the action for an alert in the BI camera settings. Would the command line be entered into the Parameters box? Also, my BI machine is running MS .net runtime 5.0.17 (x64). Does that cover the requirement mentioned?
Thanks a lot.
Dan
 
Hi JD,
Thanks for the original post. Interested in controlling a TP link device via my Blue Iris system / camera motion. I'm not as technical as some. To use this I see how to set the .exe in the action for an alert in the BI camera settings. Would the command line be entered into the Parameters box? Also, my BI machine is running MS .net runtime 5.0.17 (x64). Does that cover the requirement mentioned?
Thanks a lot.
Dan

As long as you keep your PC updated, then you should have the .net requirements.
For the parameters, I use a batch file and put the name of the exe and the parameters in there and then call the batch file from the alert.
 
If anyone finds this useful, let me know how it works for you.
works great... I use it to trigger a light in the house at night to let me know it's time to run the deer off before they eat every darn plant in the garden! Thanks!
 
Also, my BI machine is running MS .net runtime 5.0.17 (x64). Does that cover the requirement mentioned?
Thanks a lot.
Dan
Microsoft says new .net verisons are supposed to support older versions unlike before. So if you have a later version, which you do, you shouldn't need to install a previous one.

Would I be able to trigger this to only work between specified times? Like 3am - 6am?
 
  • Like
Reactions: looney2ns
Microsoft says new .net verisons are supposed to support older versions unlike before. So if you have a later version, which you do, you shouldn't need to install a previous one.

Would I be able to trigger this to only work between specified times? Like 3am - 6am?
Yes, set up a profile in BI that only includes this function during that time.
 
FWIW, the Shelly Wi-Fi smart switches, AC outlets and LED bulbs have a published API, including MQTT, that Blue Iris via HTTP can turn on/off via curl or that can receive input from them. For input to BI I have used them to trigger a cam, change profile and move to a preset; and for output from BI I have turned on lights and sounded an alarm.

More here ==>> Simple Blue Iris I/O using Shelly1 Wi-Fi Devices *
And here from @jaydeel ==>> Mailbox monitor using Shelly Wifi Motion sensor & Blue Iris
and lastly here ==>> Wireless siren to Hikvision NVR ?

* NOTE: See attached PDF.
 

Attachments

Last edited:
This has been working great up to now, but stopped. Any ideas? Yours still ok?
By any chance did you create an account with TP-LINK/Kasa/Tapo, get on your local Wi-Fi, install their app on your smartphone and have the app "add device"?
 
  • Like
Reactions: looney2ns
By any chance did you create an account with TP-LINK/Kasa/Tapo, get on your local Wi-Fi, install their app on your smartphone and have the app "add device"?
I was wrong, it is still working fine. (I had disabled the profile for that alert in BI during the daytime and forgot.... so it appeared to be not working. It is fine, user error!)
 
  • Like
Reactions: looney2ns and TonyR
I was wrong, it is still working fine. (I had disabled the profile for that alert in BI during the daytime and forgot.... so it appeared to be not working. It is fine, user error!)
Good to hear but I'm still curious about the answer to my post #9......
 
  • Like
Reactions: looney2ns
sorry, yes. I have the Kasa switch attached to lamps. works with Alexa well. Account on the Kasa app on phone, device added, on local wifi... and I created a .bat file with the KasaMotionLight as in the OP post which Blue Iris points to in the alerts tab. Works great (as long as I remember not to disable the profile first!)
 
sorry, yes. I have the Kasa switch attached to lamps. works with Alexa well. Account on the Kasa app on phone, device added, on local wifi... and I created a .bat file with the KasaMotionLight as in the OP post which Blue Iris points to in the alerts tab. Works great (as long as I remember not to disable the profile first!)
So what happens to the Kasa's switch function if your Internet (not your LAN) is down?
 
So what happens to the Kasa's switch function if your Internet (not your LAN) is down?
I guess Alexa wouldn't work, but BI functions should work as long as wifi / router/ LAN functioned? But that rarely happens and its not a crucial need, more convenience (I can always turn light on/off manually) and alerts for deer so I can chase them away! It's not a part of my home security system.
 
I guess Alexa wouldn't work, but BI functions should work as long as wifi / router/ LAN functioned? But that rarely happens and its not a crucial need, more convenience (I can always turn light on/off manually) and alerts for deer so I can chase them away! It's not a part of my home security system.
No, I understand that it's not a crucial need but I ask in order to determine if the switch's function is cloud-based and could explain why you asked previously in another post (which has since been deleted) "This has been working great up to now, but stopped. Any ideas? Yours still ok? "

In other words, if it IS cloud-based and either their server hiccupped OR your Internet was down, the switch would not work. Would you like to know the answer to that question?

If so, momentarily disconnect your Internet from the LAN, not your BI server, and see if the switch still works.
 
No, I understand that it's not a crucial need but I ask in order to determine if the switch's function is cloud-based and could explain why you asked previously in another post (which has since been deleted) "This has been working great up to now, but stopped. Any ideas? Yours still ok? "

In other words, if it IS cloud-based and either their server hiccupped OR your Internet was down, the switch would not work. Would you like to know the answer to that question?

If so, momentarily disconnect your Internet from the LAN, not your BI server, and see if the switch still works.
I had deleted the post because it wasn't correct.. I had asked why the KasaMotionLight.exe app that allowed the alert in BI to get to the Kasa switch app on my phone no longer worked, but it did... it was user error in that I had set a daytime profile to OFF for that alert and forgot.
Back to your question, though, I tested it and the Kasa switch app on the phone works just fine with the internet disabled but LAN and Wifi still on. It doesn't need cloud access. What didn't work was the above alert connection (the KasaMotionLight.exe and BAT file alert through BI. That seems to need internet, though I can't seem to figure out why. Maybe the microsoft .net framework needs the net... that would make some sense!
 
  • Like
Reactions: TonyR
That seems to need internet, though I can't seem to figure out why.
if you created an account with TP-LINK/Kasa/Tapo, got on your local Wi-Fi, installed their app on your smartphone and had the app "add device", then you're most likely using their cloud; so, if no Internet, no switch.
 
if you created an account with TP-LINK/Kasa/Tapo, got on your local Wi-Fi, installed their app on your smartphone and had the app "add device", then you're most likely using their cloud; so, if no Internet, no switch.
Not really. If I turn off internet and leave wifi and router working, and tell the app on my phone to turn light off or on, it does. The phone is still on wifi (with a no internet warning), the Kasa device has no internet now, and the app still controls the light over the available wifi (with no net).
 
In my experience it will eventually wonk out without internet. From the research I did:

Your Kasa smart plug will still be able to use existing timer and schedule settings when the internet goes down. However, if the smart plug loses power it will forget those timers and schedule settings until the internet is back up. Zigbee and Z-Wave smart plugs are a little bit more resilient to internet outages than Wi-Fi smart plugs.



Q12: Will the Timer and Schedule function still take effect if internet is down?

A: Yes, those functions will take effect even if the Smart Home device loses its internet connection.

But during the time of losing the internet, please don't power off the Smart Home device, or the schedule will not take effect.

.