joshgetter / hassio-addons

A Home Assistant Addon repository.
MIT License
52 stars 28 forks source link

add support for privacy mode #7

Open joaoopereira opened 2 years ago

joaoopereira commented 2 years ago

Hi,

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

Thanks

joshgetter commented 2 years ago

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.

joaoopereira commented 2 years ago

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!

sellison2 commented 2 years ago

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.

ikoz commented 2 years ago

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
joaoopereira commented 2 years ago

@ikoz many thanks I will try this :)

ElCapitanDre commented 2 years ago

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

ikoz commented 2 years ago

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.

ElCapitanDre commented 2 years ago

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 commented 2 years ago

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)

ikoz commented 2 years ago

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)

joaoopereira commented 2 years ago

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="

ikoz commented 2 years ago

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

joaoopereira commented 2 years ago

@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.

ikoz commented 2 years ago

@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.

joaoopereira commented 2 years ago

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.

ikoz commented 2 years ago

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))

DaveGut commented 1 year ago

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

NTGDeveloper commented 1 year ago

Bump please