tplink-smarthome-api icon indicating copy to clipboard operation
tplink-smarthome-api copied to clipboard

Kasa Cam (KC) Support?

Open kvinagro opened this issue 4 years ago • 6 comments

Will the Kasa Cam (KC) series of devices ever be supported? It would be great to be able to grab the video feed instead of having to use their app. I understand this is very different than plugs and bulbs, but just wanted to put it out there. Thanks!

kvinagro avatar Jun 10 '20 15:06 kvinagro

If someone can point me to any documentation or example programs that have this working I may be able to implement it. Alas I don't have any Kasa Cams myself to test with.

plasticrake avatar Oct 13 '20 20:10 plasticrake

Happy to run any tests necessary. At the moment, I get this:

tplink-smarthome-api search -D
<other devices>
client.startDiscovery(): socket:message From: 192.168.180.23 9999 Message: {"system":{"get_sysinfo":{"err_code":0,"system":{"sw_ver":"2.3.3 Build 20200923 rel.52147","hw_ver":"2.0","model":"KC100(UN)","hwId":"xxxREDACTEDxxx","oemId":"xxxREDACTEDxxx","deviceId":"xxxREDACTEDxxx","dev_name":"Kasa Spot","c_opt":[0,1],"a_type":2,"type":"IOT.IPCAMERA","alias":"Kasa Spot Cam","mic_mac":"3C846A61xxxx","mac":"3C:84:6A:61:xx:xx","longitude":-0.00000,"latitude":0.00000,"rssi":-77,"system_time":1607860962,"led_status":"on","updating":false,"status":"configured","resolution":"1080P","camera_switch":"on","bind_status":true,"last_activity_timestamp":1607464542}}}}
/usr/local/lib/node_modules/tplink-smarthome-api/lib/client.js:221
        throw new Error('Could not determine device from sysinfo');
        ^

Error: Could not determine device from sysinfo
    at Client.getDeviceFromSysInfo (/usr/local/lib/node_modules/tplink-smarthome-api/lib/client.js:221:15)
    at process (/usr/local/lib/node_modules/tplink-smarthome-api/lib/client.js:445:31)
    at Client.createOrUpdateDeviceFromSysInfo (/usr/local/lib/node_modules/tplink-smarthome-api/lib/client.js:465:13)
    at Socket.<anonymous> (/usr/local/lib/node_modules/tplink-smarthome-api/lib/client.js:380:22)
    at Socket.emit (node:events:376:20)
    at UDP.onMessage [as onmessage] (node:dgram:919:8)

cjdshaw avatar Dec 13 '20 12:12 cjdshaw

This would be PERFECT for one of my projects, Are You guys still looking into this?

Michael-Loia avatar Feb 07 '21 06:02 Michael-Loia

Absolutely agree, this would be awesome! I might get back to this ticket with a pr once I'm able to test myself

simlu avatar Apr 01 '21 04:04 simlu

Here is some information that should help. I also have a Kasa cam and its presence alone was causing node-red to crash, since I have the TPlink node-red integration, which uses tplink-smarthome-api. I stopped the crashing by changing or commenting out a couple of lines.

I did not have any flows that try to do anything with the Kasa cam, but it was crashing whenever the Kasa cam is turned on and connected to the network. With these lines commented out, tplink-smarthome-api now fails silently when it tries to identify the Kasa cam in the background, instead of crashing everything.

Even if tplink-smarthome-api doesn't know how to control the Kasa Cam, it would be nice to not crash. It also crashed when running from the command line: tplink-smarthome-api search

In client.js I told it to consider non-plug/non-bulb devices to be plugs:

    getDeviceFromSysInfo(sysInfo, deviceOptions) {  
        if ((0, device_1.isPlugSysinfo)(sysInfo)) {  
            return this.getPlug({ ...deviceOptions, sysInfo });  
        }  
        if ((0, device_1.isBulbSysinfo)(sysInfo)) {
            return this.getBulb({ ...deviceOptions, sysInfo });
        }
        return this.getPlug({ ...deviceOptions, sysInfo });
        //return this.getDevice({ ...deviceOptions, sysInfo });
        //throw new Error('Could not determine device from sysinfo');
    }

I also commented out the error throwing here:

    static setSysInfoForDevice(device, sysInfo) {
        if (device instanceof plug_1.default) {
            if (!(0, device_1.isPlugSysinfo)(sysInfo)) {
                //throw new TypeError(util_1.default.format('Expected PlugSysinfo but received: %O', sysInfo));
            }
            device.setSysInfo(sysInfo);
        }

Before I commented out the second thrown error I got this detailed error:

3 Jul 15:41:53 - [error] TypeError: Expected PlugSysinfo but received: {
  err_code: 0,
  system: {
    sw_ver: '2.3.6 Build 20210202 rel.59338',
    hw_ver: '2.0',
    model: 'KC115(US)',
    hwId: '519C7853498739BC[redacted]',
    oemId: '8689134D37FC8B5C[redacted]',
    deviceId: '801A8572C10E670677C[redacted]',
    dev_name: 'Kasa Spot Pan Tilt, 24/7 Recording',
    c_opt: [ 0, 1 ],
    f_list: [ 1, 2 ],
    a_type: 2,
    type: 'IOT.IPCAMERA',
    alias: 'Basement cam',
    mic_mac: 'B095[redacted]',
    mac: 'B0:95:[redacted]',
    longitude: -1XX.[redacted],
    latitude: 4X.[redacted],
    rssi: -40,
    system_time: 1656884511,
    led_status: 'on',
    updating: false,
    status: 'configured',
    resolution: '720P',
    camera_switch: 'off',
    bind_status: true,
    last_activity_timestamp: 1656475139
  }
}
    at Function.setSysInfoForDevice (/home/[redacted]/.node-red/node_modules/tplink-smarthome-api/lib/client.js:366:23)
    at process (/home/[redacted]/.node-red/node_modules/tplink-smarthome-api/lib/client.js:385:24)
    at Client.createOrUpdateDeviceFromSysInfo (/home/[redacted]/.node-red/node_modules/tplink-smarthome-api/lib/client.js:411:13)
    at Socket.<anonymous> (/home/[redacted]/.node-red/node_modules/tplink-smarthome-api/lib/client.js:326:22)
    at Socket.emit (events.js:400:28)
    at UDP.onMessage [as onmessage] (dgram.js:931:8)
nodered.service: Main process exited, code=exited, status=1/FAILURE
nodered.service: Failed with result 'exit-code'.

pfahlstrom avatar Jul 08 '22 20:07 pfahlstrom

I started some groovy effort based on the repository https://github.com/401Unauthorized/locam. This was a great kick-off point and I carried a little further.

Below is a XL list of commands I have tested (largely successful). Holdup is usability if I can not detect events (can not find out how).

Below is an xl file with a number of commands I have tested on my device. Stopped work because there was no way to detect events.

The file has columns related to the code below (groovy). I used in Hubitat to generate the commands. You wold replace the values for those from the corresponding columns in the XL file. I got about 80% to work.

def test(testCmd = "") {
	def system = "smartlife.cam.ipcamera."
	def capability = "switch"
	def method = "set_is_enable"
	def params = ["value": testCmd]
	def method2 = "get_is_enable"
	def params2 = []
	def command = ["${system}${capability}": ["${method}": params, "${method2}":params2]]
	sendCmd(JsonOutput.toJson(command).toString())
}

sendCmd then encrypts the output (LAN only) and directs it to the proper UPD, TCP, WS, or Cloud communications method.

CAMERA CMDS.xlsx

DaveGut avatar Aug 18 '22 17:08 DaveGut