hassio-addons icon indicating copy to clipboard operation
hassio-addons copied to clipboard

add support for privacy mode

Open joaoopereira opened this issue 3 years ago • 18 comments

Hi,

It's possible to add support to turn on and off the privacy mode?

Thanks

joaoopereira avatar Dec 02 '21 16:12 joaoopereira

Hi @joaoopereira - I'd have to look at how the Kasa smartphone apps trigger the privacy mode to know if it's possible.

This add-on currently allows you to specify a toggleentity (details are under the Readme) in Home Assistant. This add-on then monitors that toggle and starts/stops streaming based on it's value. Setting the toggle to false will stop the stream produced by this add-on, however the Camera will still be viewable from the Kasa apps.

Depending on your use case the "toggleentity" route may effectively do the same thing.

joshgetter avatar Jan 12 '22 20:01 joshgetter

Hi @joshgetter,

First, many thanks for your answer 😄

Unfortunately the toggleentity doesn't cover my use case. I want to enable privacy mode when nobody is at home and disable privacy mode when somebody is at home, this will allow me to use the Kasa app notifications on movement as an alarm.

As workaround I have a power plug connected to home assistant that covers my use case: turn on when nobody is at home and turn off when somebody is at home.

Thanks!

joaoopereira avatar Jan 15 '22 20:01 joaoopereira

Just to clarify, this is what it says in the app: image

That and pan/tilt (for supported cameras) are the only things that aren't initial setup that we can't do currently with HA.

sellison2 avatar Feb 01 '22 19:02 sellison2

Turning privacy mode on and off is achieved via these messages:

{"smartlife.cam.ipcamera.switch":{"set_is_enable":{"value":"off"}}}

and

{"smartlife.cam.ipcamera.switch":{"set_is_enable":{"value":"on"}}}

These need to be sent (after tp-link "encryption") to https://camera_ip:10443/data/LINKIE.json as a "content" POST parameter. This request needs to be authenticated using the tplink email/password, via http basic auth.

As simple command-line switch can be used for home-assistant integration, e.g.

switch:
  - platform: command_line
    switches:
      tplink_camera:
        command_on: curl XXX
        command_off: curl YYY

ikoz avatar Feb 14 '22 15:02 ikoz

@ikoz many thanks I will try this :)

joaoopereira avatar Feb 14 '22 16:02 joaoopereira

Hey @ikoz quick question, what do you mean by tp-link "encryption". Tried the requests a milion times over, and although they report success through postman, the camera doesnt seem to care

ElCapitanDre avatar Feb 19 '22 16:02 ElCapitanDre

Hey @ikoz quick question, what do you mean by tp-link "encryption". Tried the requests a milion times over, and although they report success through postman, the camera doesnt seem to care

tp-link products do a 'encryption' and 'decryption' operation using XOR with key=171. See here for example. https://github.com/softScheck/tplink-smartplug/blob/master/tplink_smartplug.py#L70

Also, on my KC110, the authorization header needed to be in this format: base64(email_address:md5(password))

Using the above i am able to turn on and off the camera perfectly well - it even responds that the command is accepted.

ikoz avatar Feb 19 '22 16:02 ikoz

Hey @ikoz quick question, what do you mean by tp-link "encryption". Tried the requests a milion times over, and although they report success through postman, the camera doesnt seem to care

tp-link products do a 'encryption' and 'decryption' operation using XOR with key=171. See here for example. https://github.com/softScheck/tplink-smartplug/blob/master/tplink_smartplug.py#L70

Also, on my KC110, the authorization header needed to be in this format: base64(email_address:md5(password))

Using the above i am able to turn on and off the camera perfectly well - it even responds that the command is accepted.

Okay! Thanks a lot for the knowledge, not home right now, but will try it once there! 😉

ElCapitanDre avatar Feb 19 '22 16:02 ElCapitanDre

Hey it worked great! Thanks a lot for the help. Wondering now if there is any endpoint that relays the state? (If its either on or off)

ElCapitanDre avatar Feb 20 '22 10:02 ElCapitanDre

Hey it worked great! Thanks a lot for the help. Wondering now if there is any endpoint that relays the state? (If its either on or off)

{"smartlife.cam.ipcamera.switch":{"get_is_enable":null}} this will respond with on or off - you'll need to decrypt the result (or, easier, just regex match on the base64 response)

ikoz avatar Mar 01 '22 16:03 ikoz

Hi all,

I'm not being able to make this work, maybe I missed something. Screenshot 2022-03-11 at 00 43 11

the POST request always returns "0K0="

joaoopereira avatar Mar 11 '22 00:03 joaoopereira

Hi all,

I'm not being able to make this work, maybe I missed something. Screenshot 2022-03-11 at 00 43 11

the POST request always returns "0K0="

Same as the other commands above to turn the camera on and off, the json needs to be sent as the value of a content post parameter, after first being xored with 171

ikoz avatar Mar 11 '22 07:03 ikoz

@ikoz thanks for your quick answer, but I'm not able to get a result yet :( image

I have used the encrypt method from https://github.com/softScheck/tplink-smartplug/blob/master/tplink_smartplug.py#L70 Maybe I'm doing some wrong, but I don't know what.

joaoopereira avatar Mar 11 '22 11:03 joaoopereira

@ikoz thanks for your quick answer, but I'm not able to get a result yet :( image

I have used the encrypt method from https://github.com/softScheck/tplink-smartplug/blob/master/tplink_smartplug.py#L70 Maybe I'm doing some wrong, but I don't know what.

You need to send, as a POST parameter, the following: content=base64enc(xor171(json))) Basicelly the value of content should be base64 encoded. The correct string starts like this content=0PKB7... obviously, this and all other headers and parameters should also be url-encoded at the end. curl does this via paratemers, or you can do it separately.

ikoz avatar Mar 11 '22 13:03 ikoz

Hi @ikoz,

Thanks for all your help! I'm now able to do the request, but I'm always receiving this response (I tried the get and both set): {"smartlife.cam.ipcamera.switch":{"get_is_enable":{"err_code":-10007,"err_msg":"Unauthorized Error"}}}

Maybe is my KC100 that doesn't support this.

joaoopereira avatar Mar 14 '22 01:03 joaoopereira

Hi @ikoz,

Thanks for all your help! I'm now able to do the request, but I'm always receiving this response (I tried the get and both set): {"smartlife.cam.ipcamera.switch":{"get_is_enable":{"err_code":-10007,"err_msg":"Unauthorized Error"}}}

Maybe is my KC100 that doesn't support this.

Are you using the correct format for the authorization header? It needs to be: base64(email_address:md5(password))

ikoz avatar Mar 14 '22 09:03 ikoz

Has anyone have a final example of the curl command that works and get data?

DaveGut avatar Dec 04 '22 18:12 DaveGut

Bump please

NTGDeveloper avatar Jan 30 '23 21:01 NTGDeveloper